-
Notifications
You must be signed in to change notification settings - Fork 1
/
testDetectorConvergence.m
executable file
·63 lines (60 loc) · 2.11 KB
/
testDetectorConvergence.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
% Author: Carl Doersch (cdoersch at cs dot cmu dot edu)
%
% Test whether any detectors have converged. This is a performance
% optimization that was not included in the paper; in general, any
% detector that converges will not change as the iterations continue (i.e.
% it just wastes cpu), and any detector that doesn't converge and gets
% thrown out could be thrown out by simply running it on a sufficeintly
% large dataset and seeing that it has low purity.
function [convergedClusts, tooOldClusts,resthresh]=testDetectorConvergence(prevPosFeats,...
prevAssignedClust,...
detectors,...
selectedClust,...
selClustIts,minfeats,maxage,mindecision)
if(nargin<7)
%old interface
maxage=3;
minfeats=5;
else
% if(numel(prevPosFeats)<numel(minits))
% convergedClusts=[];
% tooOldClusts=[];
% return;
% end
prevPosFeats=cell2mat(prevPosFeats);
prevAssignedClust=cell2mat(prevAssignedClust);
end
if(nargin<8)
mindecision=0;
end
convergedClusts=logical(zeros(size(selectedClust)));
weakestdecision=zeros(size(selectedClust));
for(i=1:numel(selectedClust))
mydet=selectDetectors(detectors,i)
features=prevPosFeats(find(prevAssignedClust==selectedClust(i)),:);
if(size(features,1)<minfeats)
weakestdecision(i)=-Inf;
continue;
end
labels = ones(size(features, 1), size(mydet.firstLevModels.w, 1));
[unused_labels, unused_acc, decision] = mySvmPredict(labels, ...
features, mydet.firstLevModels);
weakestdecision(i)=min(decision);
end
if(~isempty(mindecision))
% if(all(decision>mindecision))
% convergedClusts(i)=true;
% end
convergedClusts=weakestdecision>mindecision;
resthresh=mindecision;
else
if(any(~isinf(weakestdecision)))
decs=sort(weakestdecision(~isinf(weakestdecision)),'descend');
resthresh=decs(ceil(numel(decs)/4));
convergedClusts=weakestdecision>resthresh;
else
resthresh=[];
end
end
convergedClusts=selectedClust(convergedClusts);
tooOldClusts=selectedClust(selClustIts>=maxage);