194
Appendix F. Example MATLAB functions
temprw(j,:) = A(j,:)/rs;
end
end
if epsilon > 0
temprw = (1-epsilon) * temprw + epsilon/(n-1) * (ones(n,n)-eye(n));
end
for j = 1:c
% minimize the disagreement between layers using beta
if i == j
aggregateRW((i-1) * n+1:i * n,(j-1) * n+1:j * n) = (1-beta) * temprw;
else
aggregateRW((i-1) * n+1:i * n,(j-1) * n+1:j * n) = beta/(c-1) * eye(n,n);
end
end
%%%% compute Fan Chung’s Directed Laplacian
[Cvector, e] = DirLaplacianChung(aggregateRW, 0, k);
Vector = zeros(n, k, c);
for i = 1:c
Vector(:,:,i) = Cvector((i-1) * n+1:i * n,:);
end
varargout{1} = Vector;
varargout{2} = e;
varargout{3} = aggregateRW;
function [varargout] = SignedDirLaplacian(posW,negW,type,k)
% Spectral embedding of a signed directed network
%
% W an n * n * c weighted adjacency matrix
% with n nodes, and c different edge types
% k is the number of eigenvectors desired, corresponding to the k
% smallest eigenvalues (default is all);
%
% varargout = cell array of output
%
1: PosOut=Eigenvectors of positive Out role
%
2: Negout=Eigenvectors of negative Out role
%
3: PosIn=Eigenvectors of positive in role
%
4: NegIn=Eigenvectors of negative in role
%
5: E=Eigenvalues
%
6: Xpos= the positive adjacency matrix created
%
by modelling the signed directed graph
%
6: Xneg= the negative adjacency matrix created
%
by modelling the signed directed graph
[n,m] = size(posW);
%%%% Bind together the four different versions of each node
Dinpos = sum(posW,1);
Doutpos = sum(posW,2);
Dinneg = sum(negW,1);
Doutneg = sum(negW,2);
crossweights = Dinpos + Doutpos’ + Dinneg + Doutneg’;
Appendix F. Example MATLAB functions
temprw(j,:) = A(j,:)/rs;
end
end
if epsilon > 0
temprw = (1-epsilon) * temprw + epsilon/(n-1) * (ones(n,n)-eye(n));
end
for j = 1:c
% minimize the disagreement between layers using beta
if i == j
aggregateRW((i-1) * n+1:i * n,(j-1) * n+1:j * n) = (1-beta) * temprw;
else
aggregateRW((i-1) * n+1:i * n,(j-1) * n+1:j * n) = beta/(c-1) * eye(n,n);
end
end
%%%% compute Fan Chung’s Directed Laplacian
[Cvector, e] = DirLaplacianChung(aggregateRW, 0, k);
Vector = zeros(n, k, c);
for i = 1:c
Vector(:,:,i) = Cvector((i-1) * n+1:i * n,:);
end
varargout{1} = Vector;
varargout{2} = e;
varargout{3} = aggregateRW;
function [varargout] = SignedDirLaplacian(posW,negW,type,k)
% Spectral embedding of a signed directed network
%
% W an n * n * c weighted adjacency matrix
% with n nodes, and c different edge types
% k is the number of eigenvectors desired, corresponding to the k
% smallest eigenvalues (default is all);
%
% varargout = cell array of output
%
1: PosOut=Eigenvectors of positive Out role
%
2: Negout=Eigenvectors of negative Out role
%
3: PosIn=Eigenvectors of positive in role
%
4: NegIn=Eigenvectors of negative in role
%
5: E=Eigenvalues
%
6: Xpos= the positive adjacency matrix created
%
by modelling the signed directed graph
%
6: Xneg= the negative adjacency matrix created
%
by modelling the signed directed graph
[n,m] = size(posW);
%%%% Bind together the four different versions of each node
Dinpos = sum(posW,1);
Doutpos = sum(posW,2);
Dinneg = sum(negW,1);
Doutneg = sum(negW,2);
crossweights = Dinpos + Doutpos’ + Dinneg + Doutneg’;
