188
Appendix F. Example MATLAB functions
[n,m] = size(posW);
tempvalue = max(max(posW-posW’));
if tempvalue ˜= 0
posW = (posW+posW’)/2;
end
tempvalue = max(max(negW-negW’));
if tempvalue ˜= 0
negW = (negW+negW’)/2;
end
Dpos = sparse(1:n,1:n,sum(posW,2));
Dneg = sparse(1:n,1:n,sum(negW,2));
D = Dpos + Dneg;
D2 = zeros(n,n);
for i=1:n
if D(i,i) ˜= 0
D2(i,i) = 1/D(i,i)ˆ0.5;
end
end
pDinv = sparse(n,n);
nDinv = sparse(n,n);
for i=1:n
if D(i,i) ˜= 0
D2(i,i) = 1/D(i,i)ˆ0.5;
end
if Dpos(i,i) > 0;
pDinv(i,i)=1/Dpos(i,i);
end
if Dneg(i,i)>0
nDinv(i,i) = 1/Dneg(i,i);
end
end
%unnormalized graph Laplacian
if (nargin < 3) || isempty(type) || strcmp(type,’un’)
|| strcmp(type,’Un’) ...
|| strcmp(type,’UN’)
display(’Unnormalized signed Laplacian decomposition’);
L = Dpos - posW - Dneg + negW;
tempvalue = max(Dpos(:));
if k == n
[Vector,eigenvalue] = eig(L);
E = diag(eigenvalue);
[E,IXY] = sort(E,1,’ascend’);
Vector = Vector(:,IXY);
else
[Vector,eigenvalue] = eigs(2 * tempvalue * eye(n)-L,k);
E = 2 * tempvalue - diag(eigenvalue);
end
varargout{1} = Vector;
varargout{2} = E;
%simple normalized signed graph Laplacian
elseif strcmp(type,’SNS’) || strcmp(type,’Sns’) || strcmp(type,’sns’)
Précédent

- 209/231

Suivant