Skip to content

Commit 1658d21

Browse files
committed
Remove spectral 3
1 parent 6e557a5 commit 1658d21

File tree

2 files changed

+2
-43
lines changed

2 files changed

+2
-43
lines changed

src/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,5 @@ def run_all(files, algorithm, e_mode, n, n_jobs, out=True):
9696

9797
else:
9898
# run_all(test_files, ALGORITHM_3, 'eigsh', n=100, n_jobs=10)
99-
run_all(ptest_files, ALGORITHM_1, 'eigsh', n=1, n_jobs=10)
99+
run_all(comp_files, ALGORITHM_4, 'eigsh', n=1, n_jobs=10)
100100
# run_all(comp_files, ALGORITHM_1, 'eigsh', n=10, n_jobs=10)

src/spectral.py

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,15 @@
22

33
import numpy as np
44
from scipy.sparse.linalg import eigsh
5-
from sklearn.cluster import KMeans
65

76
from kmeans import k_means
8-
from laplacian import unnormalized_laplacian, normalized_laplacian
7+
from laplacian import unnormalized_laplacian
98
from read_graph import read_graph
109

1110
ALGORITHM_1 = 1
1211
ALGORITHM_2 = 2
1312
ALGORITHM_3 = 3
1413
ALGORITHM_4 = 4
15-
ALGORITHM_5 = 5
16-
ALGORITHM_6 = 6
17-
ALGORITHM_7 = 7
1814

1915

2016
def spectral_clustering1(graph_src, k_user=None):
@@ -101,40 +97,3 @@ def spectral_clustering2(graph_src, k_user=None):
10197
print("Cluster sizes: %s" % cluster_sizes)
10298
return clusters, seed, header
10399

104-
105-
def spectral_clustering3(graph_src, k_user=None):
106-
print("Reading graph: " + graph_src)
107-
start = time()
108-
A, D, k, header = read_graph(graph_src)
109-
if k_user or k is None:
110-
k = k_user
111-
header[4] = str(k_user)
112-
print("Finished after %.2f seconds" % (time() - start))
113-
114-
# Calculate laplacian matrix
115-
print("Calculating laplacian")
116-
start = time()
117-
laplacian_matrix = normalized_laplacian(D, A)
118-
print("Finished after %.2f seconds" % (time() - start))
119-
120-
D = None # Free memory
121-
A = None # Free memory
122-
123-
# Eigen-decomposition of Laplacian matrix
124-
print("Calculating Eigen-decomposition")
125-
start = time()
126-
e_values, e_vectors = eigsh(laplacian_matrix, k=k, which='SA')
127-
print("Finished after %.2f seconds" % (time() - start))
128-
laplacian_matrix = None # Free memory
129-
U = np.real(e_vectors)
130-
print("Normalizing U")
131-
start = time()
132-
T = U[:, :k] / np.sum(U[:, :k], axis=0) # Normalize
133-
print("Finished after %.2f seconds" % (time() - start))
134-
kmeans = KMeans(n_clusters=k, random_state=0).fit(T[:, :k])
135-
cluster_sizes = [0] * k
136-
for i in kmeans.labels_:
137-
cluster_sizes[i] += 1
138-
print("Cluster sizes: %s" % cluster_sizes)
139-
print(kmeans.cluster_centers_)
140-
return kmeans.labels_

0 commit comments

Comments
 (0)