Skip to content

Commit

Permalink
Powerlawsv2 (#23)
Browse files Browse the repository at this point in the history
* fixed unit tests for clusterd graphs

* fixed bug

* format with black

---------

Co-authored-by: Nicholas Landry <nicholas.landry.91@gmail.com>
  • Loading branch information
WillHWThompson and nwlandry authored Jan 29, 2024
1 parent 2d5e938 commit ab9133e
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/test_generative.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,40 @@ def test_erdos_renyi():

A = erdos_renyi(10, 0.3, seed=0)
assert A.sum() == 16


def test_unipartite_clustering():
n = 21
clique_numbers = np.arange(1, 20)
clique_number = 5
clique_size = n // clique_number # the number of nodes per clique
clique_membership = 1 # the number of cliques per node
my_p_dist = delta_dist(clique_size)
my_g_dist = delta_dist(clique_membership)

k1 = [clique_membership] * n
k2 = [clique_size] * clique_number

# A = clustered_unipartite(clique_number, n, my_p_dist, my_g_dist)
A = clustered_network(k1, k2)

G = nx.from_numpy_array(A)
# Calculate the Laplacian matrix
L = nx.laplacian_matrix(G).toarray()
# Calculate the eigenvalues of the Laplacian matrix
eigenvalues = np.linalg.eigvals(L)
num_zeros = np.count_nonzero(
np.isclose(eigenvalues, 0)
) # this should be equal to the clique number
assert num_zeros == clique_number


def test_truncated_power_law_configuration_model():
n = 500
x_min = 1
x_max = n
r = 2
A = truncated_power_law_configuration(n, x_min, x_max, r)
G = nx.from_numpy_array(A)
max_degree = max(dict(G.degree()).values())
assert max_degree <= x_max

0 comments on commit ab9133e

Please sign in to comment.