Skip to content
Snippets Groups Projects
Commit 7fb11a38 authored by Andrew Cohen's avatar Andrew Cohen
Browse files

gap breaks on first local maxima

parent e5d6b410
Branches
No related tags found
No related merge requests found
...@@ -52,6 +52,11 @@ ...@@ -52,6 +52,11 @@
function [kGap Gap S idx] = GapSpectral(DistanceMatrix,nMaxClusters,bAlgorithmicInformationDistance) function [kGap Gap S idx] = GapSpectral(DistanceMatrix,nMaxClusters,bAlgorithmicInformationDistance)
kGap=-1;
Gap=[];
S=[];
idx=[];
if nargin<3 if nargin<3
bAlgorithmicInformationDistance=1; bAlgorithmicInformationDistance=1;
end end
...@@ -99,17 +104,25 @@ for k=1:nMaxClusters ...@@ -99,17 +104,25 @@ for k=1:nMaxClusters
S(k)=sdk * sqrt(1+1/B); S(k)=sdk * sqrt(1+1/B);
% Gap % Gap
% S % S
if k>1
if Gap(k-1)>=Gap(k)-S(k)
% found it!
kGap=k-1;
break;
end
end
end end
figure if kGap<0
errorbar( [1:nMaxClusters],Gap,S) % rut roh!
set(gca,'XTick',[1:nMaxClusters]) fprintf(2,'error - gap did not converge?\n')
k=1;
while ((k<nMaxClusters) && (Gap(k) < Gap(k+1)-S(k+1)))
k=k+1;
end end
kGap=k;
%
% figure
% errorbar( [1:length(Gap)],Gap,S)
% set(gca,'XTick',[1:length(Gap)])
if (kGap>1) if (kGap>1)
idx = SpectralCluster(D,kGap); idx = SpectralCluster(D,kGap);
else else
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment