Skip to content

Instantly share code, notes, and snippets.

@brandones
Last active Jun 16, 2016
Embed
What would you like to do?
Matlab implementation of PCA on a graph
function X = graph_pca(A, k)
% A: the adjacency matrix of a graph
% k: the number of dimensions to reduce to
%
% Calculates the ECTD-preserving PCA of the graph given by A.
% See http://outobox.cs.umn.edu/PCA_on_a_Graph.pdf for background.
L = diag(sum(A)) - A;
Lp = pinv(L);
[U, E] = eigs(Lp, k);
X = E.^(1/2) * U';
endfunction
@brandones
Copy link
Author

brandones commented Jun 16, 2016

So this is actually a very silly and inefficient way to do this, since inv(eigs(L)) == eigs(pinv(L)). Inverting L, which is mad expensive, is not actually necessary. See the python version for an improvement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment