192
Appendix F. Example MATLAB functions
% k: is the number of vectors desired, corresponding to the k smallest
%
eigenvalues (default is all)
% LazyRate: a value between 0 and 1, the transition probability to
%
another layer (default is 0.5)
%
% Vector = the eigenvector matrix
% E = the diagonal matrix of Laplacian eigenvalues
% R = the large constructed random walk matrix created
%
% varargout = cell array
%
1: Vector=Eigenvectors
%
2: E= Eigenvalues
%
3: R= random walk matrix of the big connected graph
[n,m,c] = size(W);
%%%% convert each layer to a random walk matrix
RW = zeros(n,n,c);
for i = 1:c
for j = 1:n
rs = sum(W(j,:,i));
if rs == 0;
RW(j,j,i) = 1;
else
RW(j,:,i) = W(j,:,i)/rs;
end
end
end
%%%%% add epsilon
if epsilon > 0
%
RW = (1-epsilon) * RW+epsilon/n;
for i = 1:c
RW(:,:,i) = (1-epsilon) * RW(:,:,i)
+epsilon/(n-1) * (ones(n,n)-eye(n));
end
end
%%%% convert entire graph to a random walk matrix R
R = zeros(c * n,c * n);
for i = 1:c
for j = 1:c
if i == j
R((i-1) * n+1:i * n,(j-1) * n+1:j * n) = (1-LazyRate) * RW(:,:,i);
else
R((i-1) * n+1:i * n,(j-1) * n+1:j * n) = LazyRate/(c-1) * eye(n,n);
end
end
end
%%%% compute Fan Chung’s Directed Laplacian
Précédent

- 213/231

Suivant