Last active
June 16, 2016 16:53
-
-
Save brandones/995c53f527e924e788c2 to your computer and use it in GitHub Desktop.
Matlab implementation of PCA on a graph
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.