Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added examples/karate/curvature.pkl
Binary file not shown.
6,129 changes: 6,129 additions & 0 deletions examples/paper_results/figure_1/.ipynb_checkpoints/figure_1-checkpoint.ipynb

Large diffs are not rendered by default.

7,787 changes: 7,675 additions & 112 deletions examples/paper_results/figure_1/figure_1.ipynb

Large diffs are not rendered by default.

95 changes: 26 additions & 69 deletions examples/paper_results/figure_3/eigenvalues_example.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import networkx as nx
import numpy as np
import matplotlib.pyplot as plt
from geocluster import curvature as cv
from geometric_clustering import curvature as cv
from tqdm import tqdm
from scipy.sparse.linalg import eigsh
import scipy as sp
Expand All @@ -10,9 +10,7 @@

if __name__ == "__main__":

tau = 0.5
l = 2
g = 4000
l = 3
seed = 1
k_in, k_out = 4, 1 #this is in the sparse regime

Expand Down Expand Up @@ -70,7 +68,6 @@
# for i in range(10):
# plt.plot(v[:,i])


#when summing over eigenvectors in clusters and taking differences, the fluctuations vanish
# g_range = np.arange(50,2000,500)
g_range = [1000]
Expand All @@ -79,44 +76,49 @@
for g_ in g_range:
graph = nx.planted_partition_graph(l, g_, k_in/g_, k_out/g_, seed=seed)
largest_cc = max(nx.connected_components(graph), key=len)
graph = graph.subgraph(largest_cc)
graph = graph.subgraph(largest_cc).copy()
mapping = dict(zip(graph, range(len(graph.nodes))))
graph = nx.relabel_nodes(graph, mapping)

laplacian = cv._construct_laplacian(graph,use_spectral_gap=False)

t = time.time()
w, v = sp.linalg.eig(laplacian.toarray())
# w,v = eigsh(laplacian.toarray(), k=500, which='SM')
# w, v = sp.linalg.eig(laplacian.toarray())
w,v = eigsh(laplacian.toarray(), k=200, which='SM')
print(time.time() - t)

C_1 = [i for i, k in enumerate(largest_cc) if k<g_]
C_2 = [j for j, k in enumerate(largest_cc) if k>=g_]
# C_1 = [i for i, k in enumerate(largest_cc) if k<g_]
# C_2 = [j for j, k in enumerate(largest_cc) if k>=g_]
diffs = []
pairs = np.vstack(list(graph.edges))
C_1 = list(pairs[:,0])
C_2 = list(pairs[:,1])
for s in tqdm(range(v.shape[1])):
diff = (v[C_1,s].sum() - v[C_2,s].sum())/np.sqrt(g_)
diffs.append(diff)#np.exp(-w[s]/lambda2)*
diffs.append(diff)

sum_v_g.append(diffs)


all_g = [g_ for i, g_ in enumerate(g_range) for j in range(len(sum_v_g[i]))]

plt.figure()
plt.scatter(all_g,abs(np.hstack(sum_v_g)))
plt.ylabel(r'$|\sum_{ij} (\phi_s(i) - \phi_s(j))\,\delta(C_i,C_j)|$')
plt.xlabel('number of nodes')
# plt.figure()
# plt.scatter(all_g,abs(np.hstack(sum_v_g)))
# plt.ylabel(r'$|\sum_{ij} (\phi_s(i) - \phi_s(j))\,\delta(C_i,C_j)|$')
# plt.xlabel('number of nodes')

ind = np.where(abs(np.hstack(sum_v_g))==max(abs(np.hstack(sum_v_g))))[0]
plt.figure()
plt.plot(v[:,ind])
plt.savefig('phi2.svg')
ind = np.argsort(np.abs(sum_v_g)).flatten()[::-1]
for i in range(l-1):
plt.figure()
plt.plot(v[:,ind[i]])
#plt.savefig('phi2.svg')

plt.figure()
ind = np.argsort(w)
# colors = cm.rainbow(np.linspace(0, 1, len(w)))
color = []
for i, y in enumerate(abs(np.array(sum_v_g).flatten())):
plt.scatter(w[i], y, color=cm.turbo(y))
color.append(cm.turbo(y))
# plt.scatter(w[ind],abs(np.array(sum_v_g)))
plt.savefig('diffusion_differece.svg')
#plt.axvline(lambda2,c='r')

Expand All @@ -127,52 +129,7 @@
for s in range(v.shape[1]):
corr.append(gt.dot(v[:,s]))

plt.figure()
for i, y in enumerate(corr):
plt.scatter(w[i],y,color=color[i])
plt.savefig('correlation.svg')


# diffs = []
# eigs = []
# for g_ in tqdm(range(5)):
# graph = nx.planted_partition_graph(l, g, k_in/g, k_out/g, seed=seed)
# largest_cc = max(nx.connected_components(graph), key=len)
# graph = graph.subgraph(largest_cc)

# laplacian = cv._construct_laplacian(graph,use_spectral_gap=False)
# w, v = np.linalg.eig(laplacian.toarray())

# C_1 = [i for i, k in enumerate(largest_cc) if k<g_]
# C_2 = [j for j, k in enumerate(largest_cc) if k>=g_]
# mean_v = []

# for s in range(len(v)):
# diffs.append((v[C_1,s].sum() - v[C_2,s].sum())/np.sqrt(len(largest_cc)))
# eigs.append(w[s])
# # mean_v.append(np.mean(diffs))

# # sum_v_g.append(np.array(mean_v))

# plt.figure()
# plt.scatter(w,abs(sum_v_g[-1]))
# plt.axvline(lambda2,c='r')

# g=1000
# graph = nx.planted_partition_graph(l, g, k_in/g, k_out/g, seed=seed)
# largest_cc = max(nx.connected_components(graph), key=len)
# graph = graph.subgraph(largest_cc)

# laplacian = cv._construct_laplacian(graph,use_spectral_gap=False)
# _, v = np.linalg.eig(laplacian.toarray())

# C_1 = [i for i, k in enumerate(largest_cc) if k<g]
# C_2 = [j for j, k in enumerate(largest_cc) if k>=g]

# evec_diff = []
# pairs = [(x,y) for x in C_1 for y in C_2]
# # for s in range(len(v)):
# for pair in pairs:
# evec_diff.append(v[pair[0],5]- v[pair[1],5])

# plt.hist(evec_diff,bins=50)
# for i, y in enumerate(corr):
# plt.scatter(w[i],y,color=color[i])
# plt.savefig('correlation.svg')
Loading