Last active
August 29, 2015 14:08
-
-
Save yamaguchiyuto/a010cc2f113e5fd383fc to your computer and use it in GitHub Desktop.
Plot EE-plot from edgelist [Aditya+, ICDM09]
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
import sys | |
import networkx as nx | |
from scipy.sparse import linalg | |
import matplotlib | |
matplotlib.use('Agg') | |
import matplotlib.pyplot as plt | |
def plot(v,name,k,n=10000): | |
for i in range(0,k-1): | |
plt.plot(v[:n,i],v[:n,i+1],'r+') | |
plt.xlabel(name+str(i)) | |
plt.ylabel(name+str(i+1)) | |
plt.savefig(edge_list_file+'.'+name+'.'+str(i)+'_'+str(i+1)+'.eps') | |
plt.clf() | |
edge_list_file = sys.argv[1] | |
k = int(sys.argv[2]) | |
""" Read edge list """ | |
print >> sys.stderr, "LOADING GRAPH ..." | |
f = open(edge_list_file) | |
G = nx.read_edgelist(f,nodetype=int) | |
f.close() | |
print >> sys.stderr, "DONE" | |
""" Complement missing nodes """ | |
print >> sys.stderr, "COMPLEMENTING MISSING NODES ..." | |
G.add_nodes_from(range(0,max(G.nodes()))) | |
print >> sys.stderr, "DONE" | |
""" Convert to sparse matrix """ | |
""" linalg.svds will not accept int """ | |
print >> sys.stderr, "CONVERTING TO SPARSE MATRIX ..." | |
S = nx.to_scipy_sparse_matrix(G,dtype=float) | |
print >> sys.stderr, "DONE" | |
""" SVD """ | |
print >> sys.stderr, "RUNNING SVD ..." | |
U,s,V = linalg.svds(S,k=k) | |
print >> sys.stderr, "DONE" | |
""" Plot """ | |
print >> sys.stderr, "PLOTTING ..." | |
plot(U,'U',k) | |
plot(V.T,'V',k) | |
print >> sys.stderr, "DONE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment