Skip to content

Commit

Permalink
update sbm test
Browse files Browse the repository at this point in the history
  • Loading branch information
martinroyer committed Oct 18, 2017
1 parent 58120d2 commit dc9efa0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 9 additions & 0 deletions pecok/pecok_clustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,12 @@ def cluster(X, K):
X : array-like or sparse matrix, shape=(n_samples, n_features)
Training instances to cluster."""
return pecok_admm(X.dot(X.T)-Gamma_hat4(X), K)

def cluster_sbm(A, K):
"""Implementation of PECOK estimator of B*
Parameters
----------
A : adjacency matrix for network, shape=(n_samples, n_samples)
Training instances to cluster."""
return pecok_admm(A.dot(A), K)
4 changes: 2 additions & 2 deletions tests/test_sbm.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
expA[:n_samples//2,:n_samples//2] += p-q
expA[n_samples//2:,n_samples//2:] += p-q
A = np.vectorize(lambda p : np.random.binomial(1, p))(expA)
A.flat[::n_samples+1] = 10
A.flat[::n_samples+1] = 0
i_lower = np.tril_indices(n_samples, -1)
A[i_lower] = A.T[i_lower]
print(A)

Bhat = pecok_clustering.cluster(A, 2)
Bhat = pecok_clustering.cluster_sbm(A, 2)
kMeans = cluster.KMeans(n_clusters=2, init='k-means++', n_init=100, copy_x=True)
print("truth:".ljust(10), truth)
print("pecok:".ljust(10), kMeans.fit(Bhat).labels_)
Expand Down

0 comments on commit dc9efa0

Please sign in to comment.