[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
what are the meanings of every ROW
From: |
pro_octave |
Subject: |
what are the meanings of every ROW |
Date: |
Fri, 12 Jul 2013 19:09:34 -0700 (PDT) |
I am a newcomer for Machine Learning, below is the algorithm of k-Medoids
clustering in Octave, but I am confused by the meanings of every VARs and
ROWs, here is the CODE, is there anyone can explain for me, I will be very
appreciate, please note that with more DETAILS
function [Medoids, clusvector, DIST]=clusterKMedoids(M, N)
[points, dim]=size(M);
% disp('calculating distances');
DIST=zeros(points, points);
for i=1:points-1
for j=i+1:points
DIST(i, j)=norm(M(i, :)-M(j, :), 2);
DIST(j, i)=DIST(i, j);
end
end
%compute medoids
Medoids=[];%
sumdist=sum(DIST);%
[Min Medoids(1)] = min(sumdist);%
for k=2:N %
notselected=setdiff([1:points], Medoids);%
Cj=zeros(points,1);%
for i=notselected%
for j=notselected(find(notselected~=i))
%for j=not yet select
Dj=min(DIST(j, Medoids));
dij=DIST(j, i);
Cj(i)=Cj(i)+max([Dj-dij 0]);
end
end
[Max Medoids(k)]=max(Cj);%selected ones have score zero
end
% do swap
notselected=setdiff([1:points], Medoids);
ns=points-N; %
minT=-1;
T=zeros(N, ns);%
iter=0;
sumD=[];%
while (minT<0 && iter<=20)
for i=Medoids
for h=notselected
Cjih=0;
for j=union(notselected, i)
Dj=min(DIST(j, Medoids));
dij=DIST(j,i);
dhj=DIST(j,h);
if Dj==dij
Ej=min(DIST(j,
Medoids(find(Medoids~=i))));
if dhj<Ej
Cjih=Cjih+dhj-dij;
else
Cjih=Cjih+Ej-Dj;
end
elseif Dj>dhj
Cjih=Cjih+dhj-Dj;
end
end
T(find(Medoids==i),find(notselected==h))=Cjih;
end
end
[minT, Ind]=min(T(:));
if minT<0
colh=ceil(Ind/N);
rowi=Ind-(colh-1)*N;
i=Medoids(rowi);
Medoids(rowi)=notselected(colh);
notselected(colh)=i;
end
iter=iter+1;
sumiter=0;
for j=notselected
sumiter=sumiter+min(DIST(j, Medoids));
end
sumD=[sumD sumiter];
end%END for WHILE
clusvector=zeros(points,1);
for i=Medoids
clusvector(i, 1)=find(Medoids==i);
end
for j=notselected
[Dj Ind]=min(DIST(j, Medoids));
clusvector(j, 1)=Ind;
end
end
--
View this message in context:
http://octave.1599824.n4.nabble.com/what-are-the-meanings-of-every-ROW-tp4655577.html
Sent from the Octave - General mailing list archive at Nabble.com.
- what are the meanings of every ROW,
pro_octave <=