
txtf; % txtf formira rijeci x dokumenti matricu
k=6;
[m,n]=size(a);

% multiparticioniranje
disp('Multiparticijski algoritam');
tic
d1=1./sqrt(sum(a'));
d2=1./sqrt(sum(a));
an=a.*(d1'*d2);
[un,sn,vn]=svds(an,k);
%sn
z=[repmat(d1',[1,k]).*un(:,1:k);repmat(d2',[1,k]).*vn(:,1:k)];
clear d1 d2 un vn sn an
vk=kmeans(z,k,'EmptyAction','singleton','Distance','cosine');
nr=svdnormrez(vk,k,a)
[rsort,rindex]=sort(vk(1:m));
[dsort,dindex]=sort(vk(m+1:m+n));
asort=a(rindex,dindex);
toc
%vk(m+1:m+n)'
% Grafièki prikaz sortirane matrice
subplot(2,2,1),spy(a);axis square;
title('r x d matrica','FontSize',10);
subplot(2,2,2),spy(asort);axis square;
title('Sortirana r x d matrica (mp)','FontSize',10);
clear asort


% rekurzivno particioniranje (of - normalizirani rez)
disp('Rekurzivni biparticijski algoritam');
tic
vk=svdrebipart(a,k);
nr=svdnormrez(vk,k,a)
[rsort,rindex]=sort(vk(1:m));
[dsort,dindex]=sort(vk(m+1:m+n));
asort=a(rindex,dindex);
toc
%vk(m+1:m+n)
% Grafièki prikaz sortirane matrice
subplot(2,2,3),spy(asort);axis square;
title('Sortirana r x d matrica (rbp)','FontSize',10);
clear asort


% K-means particioniranje
disp('K-means');
tic
vkr=kmeans(a,k,'EmptyAction','singleton','Distance','cosine');
vkd=kmeans(a',k,'EmptyAction','singleton','Distance','cosine');
vk=[vkr;vkd];
nr=svdnormrez(vk,k,a)
[rsort,rindex]=sort(vkr);
[dsort,dindex]=sort(vkd);
asort=a(rindex,dindex);
toc
% Grafièki prikaz sortirane matrice
subplot(2,2,4),spy(asort);axis square;
title('Sortirana r x d matrica (km)','FontSize',10);
pause;close;


