Skip to content

Instantly share code, notes, and snippets.

View brandones's full-sized avatar

Brandon Istenes brandones

View GitHub Profile
@brandones
brandones / pylint
Created May 9, 2017 23:04
Run pylint using first virtualenv named 'env' in a parent directory
#!/usr/bin/python
#
# Placed at /usr/local/bin/python
# Expects pylint executable at /usr/bin/pylint
#
import os
import sys
def get_python_exec():
import networkx as nx
import numpy
import scipy.io
import scipy.linalg
import scipy.sparse.linalg
from scipy.sparse.linalg.eigen.arpack.arpack import ArpackNoConvergence
def reduce_from_matlab(mat_path, output_dim):
mat = scipy.io.loadmat(mat_path)
@brandones
brandones / graph_pca.m
Last active June 16, 2016 16:53
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';