-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexperimentsNoisyTransformations.m
More file actions
157 lines (137 loc) · 5.42 KB
/
experimentsNoisyTransformations.m
File metadata and controls
157 lines (137 loc) · 5.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
% Run experiments of denoising noisy pairwise transformations
%
% INPUT:
% k: number of transformations
%
% d: dimensionality
%
% sigma: standard deviation of Gaussian noise
%
% transformationType: 'linear', 'affine', 'similarity',
% 'similarityNoReflection', 'euclidean', 'rigid', 'translationOnly'
%
% varyingParameter: string containing the varying parameter
%
% parameterRange: vector containing all values for the varying parameter
% that are to be evaluated
%
% nDraws: number of how many times random transformations are generated
%
% saveImageFolder: output folder for saving .tikz files. Requires the
% matlab2tikz toolbox (if not available, set to [])
%
% varyingParameterLabel: string as label for the varying parameter (to use
% latex syntax)
%
% noiseType: type of noise, currently only additiveGaussian noise is
% supported
%
% nRepetitions: number of times noise is added to the transformations
%
%
% Author: Florian Bernard, f.bernardpi [at] gmail [dot] com
%
function experimentsNoisyTransformations(k, d, sigma, transformationType, ...
varyingParameter, parameterRange, nDraws, saveImageFolder, ...
varyingParameterLabel, noiseType, nRepetitions)
%% perform simulation runs for varying parameter
% arrays for storing results
transitiveErrorNoisy = nan(nDraws, numel(parameterRange));
errorNoisy = nan(nDraws, numel(parameterRange));
transitiveErrorDenoised = nan(nDraws, numel(parameterRange));
errorDenoised = nan(nDraws, numel(parameterRange));
for v=1:numel(parameterRange)
evalc([varyingParameter ' = ' num2str(parameterRange(v))]);
for sampleNo=1:nDraws % repeat experiments
refTransformationsHom = ...
generateRandomTransformations(d, k, transformationType);
% compute ground truth
groundTruthTransCell = cell(k,k);
for i=1:k
for j=1:k
Ti = refTransformationsHom{i};
Tj = refTransformationsHom{j};
Tij = Ti/Tj;
groundTruthTransCell{i,j} = Tij;
end
end
transitiveErrorDenoisedTmp = nan(nRepetitions, 1);
transitiveErrorNoisyTmp = nan(nRepetitions, 1);
errorNoisyTmp = nan(nRepetitions, 1);
errorDenoisedTmp = nan(nRepetitions, 1);
% for the generated set of random transformations, repeatedly add
% noise
for r=1:nRepetitions
switch noiseType
case 'additiveGaussian'
noisyTransCell = addGaussianNoiseToTransformations(...
groundTruthTransCell, sigma, transformationType);
case 'componentWise'
noisyTransCell = addNoiseToTransformationsHom(...
groundTruthTransCell, sigma, transformationType);
end
% determine error for noisy transformations
transitiveErrorNoisyTmp(r) = ...
transitiveErrorOfPairwiseTransformations(noisyTransCell);
errorNoisyTmp(r) = ...
errorTransformations(noisyTransCell, groundTruthTransCell);
% use transformation synchronisation
unnoisyTransCell = ...
synchroniseTransformationsZ(noisyTransCell, transformationType);
% and determine error for synchronised transformations
transitiveErrorDenoisedTmp(r) = ...
transitiveErrorOfPairwiseTransformations(unnoisyTransCell);
errorDenoisedTmp(r) = ...
errorTransformations(unnoisyTransCell, groundTruthTransCell);
end
transitiveErrorNoisy(sampleNo,v) = mean(transitiveErrorNoisyTmp);
errorNoisy(sampleNo,v) = mean(errorNoisyTmp);
transitiveErrorDenoised(sampleNo,v) = mean(transitiveErrorDenoisedTmp);
errorDenoised(sampleNo,v) = mean(errorDenoisedTmp);
end
end
%% plot errors
figure('Position', [120 620 300 180]);
switch noiseType
case 'additiveGaussian'
titleText = '$\mathcal{\tilde T}^{\mathcal{N}}$';
case 'componentWise'
titleText = '$\mathcal{\tilde T}^{C}$';
end
titleText = [titleText ', ' transformationType];
if ( ~strcmp(varyingParameter, 'sigma') )
titleText = [titleText ', $\sigma{=}' num2str(sigma) '$'];
end
if ( ~strcmp(varyingParameter, 'k') )
titleText = [titleText ', $k{=}' num2str(k) '$'];
end
if ( ~strcmp(varyingParameter, 'd') )
titleText = [titleText ', $d{=}' num2str(d) '$'];
end
title([titleText]);
hold on;
plot(parameterRange, mean(errorNoisy,1), 'g', 'LineWidth', 1);
plot(parameterRange, mean(errorDenoised,1), 'b', 'LineWidth', 1);
plot(parameterRange, mean(errorNoisy,1), 'gs', 'MarkerSize', 6, ...
'MarkerFaceColor', 'g');
plot(parameterRange, mean(errorDenoised,1), 'bs', 'MarkerSize', 6, ...
'MarkerFaceColor', 'b');
% legend({'noisy', 'synchronised'}, 'Location', 'NorthWest', ...
% 'Interpreter', 'tex');
xlabel(['$' varyingParameterLabel '$']);
ylabel('error');
maxVal = max([mean(errorNoisy,1) mean(errorDenoised,1)]);
if ( maxVal < 2.5 ) % do not show a finer vertical axis than [0;2.5]
ylim([0 2.5]);
end
if ( exist('saveImageFolder', 'var') && ~isempty(saveImageFolder) )
file = [saveImageFolder filesep 'errorPlot-' ...
transformationType '-k-' num2str(k) ...
'-d-' num2str(d) '-sigma-' num2str(sigma) ...
'-noiseType-' noiseType ...
'-var-' varyingParameter '-nDraws-' num2str(nDraws) '.tikz'];
matlab2tikz(file, ...
'height', '1cm', 'width', '2cm', ...
'parseStrings', false);
end
end