Skip to content

Instantly share code, notes, and snippets.

Last active Jun 16, 2016
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 for background.
L = diag(sum(A)) - A;
Lp = pinv(L);
[U, E] = eigs(Lp, k);
X = E.^(1/2) * U';
Copy link

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