Commit 7fb11a38 authored by Andrew Cohen's avatar Andrew Cohen
Browse files

gap breaks on first local maxima

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