├── ClusteringMeasure.m ├── veccomp.m ├── README.md ├── eig1.m ├── ACSK.m ├── myKernel.m ├── ACMK.m └── EuDist2.m /ClusteringMeasure.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sckangz/ICDE/HEAD/ClusteringMeasure.m -------------------------------------------------------------------------------- /veccomp.m: -------------------------------------------------------------------------------- 1 | function [all,dis]=veccomp(ij,n,F,X); 2 | for ji=1:n 3 | all(ji)=(norm(F(ij,:)-F(ji,:)))^2; 4 | dis(ji)=(norm(X(ij,:)-X(ji,:)))^2; 5 | end 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This is the code to implement algorithm in Paper "Structured Graph Learning for Clustering and 2 | Semi-supervised Classification". 3 | An example data can be downloaded from https://www.dropbox.com/sh/z6knmvidpfhz5le/AABfizEur-U3OiwmtKHNAB8Ra?dl=0 4 | -------------------------------------------------------------------------------- /eig1.m: -------------------------------------------------------------------------------- 1 | function [eigvec, eigval, eigval_full] = eig1(A, c, isMax, isSym) 2 | 3 | if nargin < 2 4 | c = size(A,1); 5 | isMax = 1; 6 | isSym = 1; 7 | elseif c > size(A,1) 8 | c = size(A,1); 9 | end; 10 | 11 | if nargin < 3 12 | isMax = 1; 13 | isSym = 1; 14 | end; 15 | 16 | if nargin < 4 17 | isSym = 1; 18 | end; 19 | 20 | if isSym == 1 21 | A = max(A,A'); 22 | end; 23 | [v d] = eig(A); 24 | d = diag(d); 25 | %d = real(d); 26 | if isMax == 0 27 | [d1, idx] = sort(d); 28 | else 29 | [d1, idx] = sort(d,'descend'); 30 | end; 31 | 32 | idx1 = idx(1:c); 33 | eigval = d(idx1); 34 | eigvec = v(:,idx1); 35 | 36 | eigval_full = d(idx); -------------------------------------------------------------------------------- /ACSK.m: -------------------------------------------------------------------------------- 1 | function [result]=ACSK(X,K,s,alpha,gamma) 2 | [m,n]=size(K); 3 | Z=eye(n); 4 | c=length(unique(s)); 5 | 6 | for i=1:100 7 | Zold=Z; 8 | Z= (Z+Z')/2; 9 | D = diag(sum(Z)); 10 | L = D-Z; 11 | 12 | [F, temp, ev]=eig1(L, c, 0); 13 | 14 | 15 | parfor ij=1:n 16 | 17 | [all,dis]=veccomp(ij,n,F,X); 18 | 19 | H=2*alpha*eye(n)+2*K; 20 | H=(H+H')/2; 21 | ff=dis'+gamma/2*all'-2*K(:,ij); 22 | [Z(:,ij),err,lm] = qpas(H,ff,[],[],ones(1,n),1,zeros(n,1),ones(n,1)); 23 | 24 | end 25 | if i>10 &((norm(Z-Zold)/norm(Zold))<1e-3) 26 | break 27 | end 28 | 29 | end 30 | 31 | actual_ids= kmeans(F, c, 'emptyaction', 'singleton', 'replicates', 100, 'display', 'off'); 32 | 33 | [result] = ClusteringMeasure( actual_ids,s); 34 | -------------------------------------------------------------------------------- /myKernel.m: -------------------------------------------------------------------------------- 1 | function [ out ] = myKernel(x,lambda) 2 | if lambda == 2015 3 | out = x * x'; 4 | else if lambda == 2016 5 | out = x * x'; 6 | out = out .^ 2; 7 | else if lambda == 2017 8 | 9 | out = x*x'; 10 | out = out .^4; 11 | else if lambda == 2018 12 | 13 | out = 1+x*x'; 14 | out = out .^2; 15 | else if lambda == 2019 16 | 17 | out = 1+x*x'; 18 | out = out .^4; 19 | 20 | 21 | 22 | else if lambda==2020 23 | m=size(x,1); 24 | out=zeros(m); 25 | for i=1:m 26 | for j=i+1:m 27 | out(i,j)=x(i,:)*x(j,:)'/(norm(x(i,:))*norm(x(j,:))+eps); 28 | out(j,i)=out(i,j); 29 | end 30 | end 31 | else 32 | tmp=EuDist2(x,[],0); 33 | delta=lambda*max(tmp(:)); 34 | out = exp(-tmp./delta); 35 | end 36 | end 37 | end 38 | end 39 | end 40 | end 41 | maximum=max(out(:)); 42 | out = out ./maximum; 43 | 44 | end 45 | -------------------------------------------------------------------------------- /ACMK.m: -------------------------------------------------------------------------------- 1 | function [result]=ACMK(X,A,s,alpha,beta,gamma) 2 | [m,n,nm]=size(A); 3 | Z=eye(n); 4 | c=length(unique(s)); 5 | e=1/12*ones(12,1); 6 | 7 | for i=1:500 8 | K=zeros(n); 9 | for j=1:12 10 | K=K+e(j)*A(:,:,j); 11 | end 12 | 13 | 14 | Zold=Z; 15 | 16 | Z= (Z+Z')/2; 17 | 18 | D = diag(sum(Z)); 19 | L = D-Z; 20 | 21 | [F, temp, ev]=eig1(L, c, 0); 22 | 23 | parfor ij=1:n 24 | [all,dis]=veccomp(ij,n,F,X); 25 | H=2*alpha*eye(n)+2*K; 26 | H=(H+H')/2; 27 | ff=beta*dis'+gamma/2*all'-2*K(:,ij); 28 | [Z(:,ij),err,lm] = qpas(H,ff,[],[],ones(1,n),1,zeros(n,1),ones(n,1)); 29 | end 30 | 31 | 32 | h=zeros(12,1); 33 | for j=1:12 34 | h(j)=trace(A(:,:,j)-2*A(:,:,j)*Z+Z'*A(:,:,j)*Z); 35 | end 36 | for j=1:12 37 | e(j)=(h(j)*sum(1./h))^(-2); 38 | end 39 | 40 | if i>10 &((norm(Z-Zold)/norm(Zold))<1e-3) 41 | 42 | break 43 | end 44 | 45 | end 46 | actual_ids= kmeans(F, c, 'emptyaction', 'singleton', 'replicates', 100, 'display', 'off'); 47 | [result] = ClusteringMeasure( actual_ids,s); -------------------------------------------------------------------------------- /EuDist2.m: -------------------------------------------------------------------------------- 1 | function D = EuDist2(fea_a,fea_b,bSqrt) 2 | %EUDIST2 Efficiently Compute the Euclidean Distance Matrix by Exploring the 3 | %Matlab matrix operations. 4 | % 5 | % D = EuDist(fea_a,fea_b) 6 | % fea_a: nSample_a * nFeature 7 | % fea_b: nSample_b * nFeature 8 | % D: nSample_a * nSample_a 9 | % or nSample_a * nSample_b 10 | % 11 | % Examples: 12 | % 13 | % a = rand(500,10); 14 | % b = rand(1000,10); 15 | % 16 | % A = EuDist2(a); % A: 500*500 17 | % D = EuDist2(a,b); % D: 500*1000 18 | % 19 | % version 2.1 --November/2011 20 | % version 2.0 --May/2009 21 | % version 1.0 --November/2005 22 | % 23 | % Written by Deng Cai (dengcai AT gmail.com) 24 | 25 | 26 | if ~exist('bSqrt','var') 27 | bSqrt = 1; 28 | end 29 | 30 | if (~exist('fea_b','var')) || isempty(fea_b) 31 | aa = sum(fea_a.*fea_a,2); 32 | ab = fea_a*fea_a'; 33 | 34 | if issparse(aa) 35 | aa = full(aa); 36 | end 37 | 38 | D = bsxfun(@plus,aa,aa') - 2*ab; 39 | D(D<0) = 0; 40 | if bSqrt 41 | D = sqrt(D); 42 | end 43 | D = max(D,D'); 44 | else 45 | aa = sum(fea_a.*fea_a,2); 46 | bb = sum(fea_b.*fea_b,2); 47 | ab = fea_a*fea_b'; 48 | 49 | if issparse(aa) 50 | aa = full(aa); 51 | bb = full(bb); 52 | end 53 | 54 | D = bsxfun(@plus,aa,bb') - 2*ab; 55 | D(D<0) = 0; 56 | if bSqrt 57 | D = sqrt(D); 58 | end 59 | end 60 | 61 | --------------------------------------------------------------------------------