...
 
Commits (2)
function [score,rgCorrect]=scoreClusteringMode(idxCluster,idxTrue)
rgCorrect=0*idxTrue;
for i=1:max(idxCluster)
% idxi are the elements in cluster i
idxi=find(idxCluster==i);
% imode is the ground truth label for cluster i
iMode=mode(idxTrue(idxi));
idxCorrect=idxi(find(idxTrue(idxi)==iMode));
rgCorrect(idxCorrect)=1;
end
score=nnz(rgCorrect)/length(rgCorrect);
4;
function nCorrect=scoreClusteringPerms(idxCluster,idxTrue)
classes=unique(idxTrue);
idxPerms=perms(classes);
rgCorrect=[];
rgWrong={};
for i=1:size(idxPerms,1)
idxMap = idxTrue;
for j=1:size(idxPerms,2)
idx = find(idxTrue==j);
idxMap(idx)=idxPerms(i,j);
end
rgCorrect(i)=length(find(idxMap'==idxCluster));
rgWrong{i}=find(idxMap'~=idxCluster);
end
[nCorrect iBest]=max(rgCorrect);
idxWrong = rgWrong(iBest);
......@@ -19,6 +19,7 @@ for k=1:k
delta{i}=odj;
end
end
bw=min(cellfun(@std,delta)./cellfun(@mean,delta));
% bw=min(cellfun(@std,delta)./cellfun(@mean,delta));
bw=min(cellfun(@min,delta));
% bw=min(cellfun(@min,delta));
\ No newline at end of file
target=[0,1];
target=[0:9];
kod=[];
kod2=[];
kGap=[];
for i=1:7,typex{i}='double';end
scoreCluster=table('Size',[1000,7],'VariableTypes',typex,...
'VariableNames',{'n','kgap','kod','kod2','accgap','accod','accod2'});
for n=1:1000
[Training]= getTrainingNIST(20,1);
[~,idxSort]=sort([Training.idxTrue]);
......@@ -15,7 +18,7 @@ for n=1:1000
for i=1:length(Training)
parfor j=1:length(Training)
if (i<=j)
continue
continue
end
d1=NCD.imNCDM([{Training(i).im},{Training(j).im}]);
d2=NCD.imNCDM([{Training(j).im},{Training(i).im}]);
......@@ -25,27 +28,37 @@ for n=1:1000
d=Cluster.Regularize(d);
k=length(target);
% [kGap(n) Gap S idx] = GapSpectral(d,k+2,true,k,idxGT);
[kGap(n) Gap S idx] = Cluster.GapSpectral(d,k+2,true);
% [kGap Gap S idx] = Cluster.GapSpectral(d,k+2,true,k,idxGT);
[kGap Gap S idx] = Cluster.GapSpectral(d,k+2,true);
scoreCluster.kgap(n)=kGap;
scoreCluster.accgap(n)=Cluster.scoreClusteringMode(idx,idxGT);
od={};
[od{1,1},bw]=NCD.optimalityDeficiency({Training.im});
score=[];
for ik=2:k+2
% if (ik==k)
% idx=idxGT;
% else
idx= Cluster.SpectralCluster(d,ik);
% end
score(ik)=Cluster.scoreClusteringMode(idx,idxGT);
[od{ik,:},bw(ik)]=NCD.optimalityDeficiency({Training.im},idx);
end
bw2=[];
for ik=1:k+2
bw2(ik)=max( (cellfun(@max,od{ik})-cellfun(@min,od{ik})));
end
[~,kod(n)]=min(bw);
[~,kod2(n)]=min(bw2);
fprintf(1,'%d: kGap=%d (%0.1f), kOptDef=%d (%0.1f) kOptDef2=%d (%0.1f)\n',...
n,kGap(n),length(find(kGap==k))/length(kGap),kod(n),...
length(find(kod==k))/length(kod),kod2(n),length(find(kod2==k))/length(kod2));
[~,scoreCluster.kod(n)]=min(bw);
[~,scoreCluster.kod2(n)]=min(bw2);
scoreCluster.n(n)=n;
scoreCluster.accod(n)=score(scoreCluster.kod(n));
scoreCluster.accod2(n)=score(scoreCluster.kod2(n));
scoreCluster(n,:)
% fprintf(1,'%d: kGap=%d (%0.1f), kOptDef=%d (%0.1f) kOptDef2=%d (%0.1f)\n',...
% n,kGap(n),length(find(kGap==k))/length(kGap),kod(n),...
% length(find(kod==k))/length(kod),kod2(n),length(find(kod2==k))/length(kod2));
end
\ No newline at end of file