-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathuniRan.m
executable file
·127 lines (85 loc) · 2.72 KB
/
uniRan.m
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
function bestCS = uniRan(transimage,vector)
prob = 0.05;
bestCS = [];
bestSTD = 1000;
bestSize =0;
probCS =1 ;
%parada = ;
ganhos = 0;
totais = 0;
while probCS > prob
%% Hypotesis Step ( Just Select A randon point from the set)
% Just sampled 5 positions from the valid vectors. And aftar that
% Took the mean and the variance
[y,idx] = datasample(vector,5);
vector(idx,:) = [];
avgVector = zeros(5,1);
for i=1:5
avgVector(i) = transimage(y(i));
end
mediaTrans = mean(avgVector);
stdDev = std(avgVector);
%% Now You verify the distance between the selected point and a threshold
CS = zeros(size(vector));
CSimage = zeros(length(vector),1);
% optimize
tamanho =1;
%size(vector)
% Look how many are close to the mean and the STD deviation
for i=1:length(vector)
%vector(:,i)
if (transimage(vector(i,1),vector(i,2)) - mediaTrans) <= stdDev
CS(tamanho,:) = vector(i,:);
CSimage(tamanho) = transimage(vector(i,1),vector(i,2));
tamanho = tamanho + 1;
end
end
%% remove the new inliers
% 'CS'
%size(CS)
meanCS = mean(CSimage);
tamanho;
apagar = zeros(tamanho,1); % vetor com elementos a serem apagados
for i=1:tamanho-1
if (CSimage(i) - meanCS) > stdDev
apagar(i) = 1;
end
end
% vai apagar
% Media
sizeCS=0;
soma=0;
for i=1:tamanho-1
if apagar(i) ~= 1
soma = soma + CSimage(i);
sizeCS = sizeCS + 1;
end
end
meanCS = soma/sizeCS;
% STD
soma =0;
sizeCS =1;
fprintf('apagou %d \n',tamanho-sizeCS);
for i=1:tamanho-1
if apagar(i) ~= 1
CS(sizeCS,:) = CS(i,:);
soma = soma + (CSimage(i) - meanCS)^2;
sizeCS = sizeCS +1;
end
end
%'cc2'
stdCS = sqrt(soma/sizeCS);
%sizeCS;
if stdCS < bestSTD
bestCS = CS;
bestSTD = stdCS
bestSize = sizeCS
%length(bestCS);
ganhos = ganhos +1;
end
totais = totais +1;
probCS = ganhos /totais
end
bestCS(bestSize:end,:) = [];
bestSTD
end