-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdicClusterFixedSizeAprox.m
32 lines (25 loc) · 1.03 KB
/
dicClusterFixedSizeAprox.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
function [indx centroid bound] = dicClusterFixedSizeAprox(Dic, numOfClusters, lastIndx)
bound = [];
centroid = [];
indx = zeros(size(Dic,2),1);
clusterSize = ceil(size(Dic,2)/numOfClusters);
[I C D] = kmeansMaxEnd(Dic,numOfClusters);
num = hist(I, numOfClusters);
bigClusters = find(num>=clusterSize);
for i = 1:length(bigClusters)
[I2 centroid2 bound2] = bestClusterAprox(Dic(:,I==bigClusters(i)),C(bigClusters(i),:), clusterSize);
centroid = [centroid centroid2];
bound = [bound; bound2];
lastIndx = lastIndx+1;
indx(I==bigClusters(i)) = I2*lastIndx;
end
if sum(indx==0) > clusterSize
[indx(indx==0) centroid2 bound2] = dicClusterFixedSizeAprox(Dic(:,indx==0), numOfClusters-length(bound), lastIndx);
centroid = [centroid centroid2];
bound = [bound; bound2];
elseif sum(indx==0)~=0
centroid(:,end+1) = mean(Dic(:,indx==0),2);
bound(end+1,1) = max(distan(Dic(:,indx==0),repmat(centroid(:,end),[1 sum(indx==0)])));
lastIndx = lastIndx+1;
indx(indx==0) = lastIndx;
end