Skip to content

Commit

Permalink
fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nwlandry committed Nov 29, 2023
1 parent 5811945 commit 1624388
Show file tree
Hide file tree
Showing 2 changed files with 226 additions and 173 deletions.
38 changes: 23 additions & 15 deletions lcs/generative.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@ def sbm(n, k, epsilon, seed=None):
return nx.adjacency_matrix(G).todense()



def delta_dist(x_prime):
return rv_discrete(name = 'custom',values = ([x_prime],[1.]))
return rv_discrete(name="custom", values=([x_prime], [1.0]))


def generate_hypergraph_bipartite_edge_list(N_groups, N_inds, p_dist, g_dist,seed = None):
def generate_hypergraph_bipartite_edge_list(
N_groups, N_inds, p_dist, g_dist, seed=None
):
"""
generate_hypergraph_bipartite_edge_list(): generates a hypergraph in the style of Newman's model in "Community Structure in social and biological networks"
inputs:
Expand All @@ -60,13 +61,12 @@ def generate_hypergraph_bipartite_edge_list(N_groups, N_inds, p_dist, g_dist,see
edge_list: the edge list for a bi-partite graph. The first n-indices represent the clique edges and the rest represent individuals
"""

#generate rng with seed
# generate rng with seed
if seed is not None:
rng = np.random.default_rng(seed)
else:
rng = np.random.default_rng()


chairs = []
butts = []

Expand All @@ -78,10 +78,14 @@ def generate_hypergraph_bipartite_edge_list(N_groups, N_inds, p_dist, g_dist,see

for i in range(1, N_groups + 1):
p_n = p_dist.rvs() # select the number of chairs in clique i
p_n = int(p_n if len(chairs) + p_n <= len(butts) else len(butts) - len(chairs)) # pull a random length or select a length to make the two lists equal if we are bout to go over
p_n = int(
p_n if len(chairs) + p_n <= len(butts) else len(butts) - len(chairs)
) # pull a random length or select a length to make the two lists equal if we are bout to go over
print(p_n)
chairs.extend([i for _ in range(int(p_n))]) # add p_n chairs belonging to clique i
chairs.extend([chairs[-1] for i in range(len(butts) - len(chairs))])
chairs.extend(
[i for _ in range(int(p_n))]
) # add p_n chairs belonging to clique i
chairs.extend([chairs[-1] for i in range(len(butts) - len(chairs))])
breakpoint()
chairs = [chair + N_inds for chair in chairs]

Expand All @@ -102,16 +106,20 @@ def generate_hypergraph_bipartite_edge_list(N_groups, N_inds, p_dist, g_dist,see
def bipartite_graph(edge_list):
B = nx.Graph()
a = np.vstack(edge_list)
node_list1,node_list2 = np.unique(a[:,1]),np.unique(a[:,0])
B.add_nodes_from(node_list1,bipartite=0)
B.add_nodes_from(node_list2,bipartite=1)
node_list1, node_list2 = np.unique(a[:, 1]), np.unique(a[:, 0])
B.add_nodes_from(node_list1, bipartite=0)
B.add_nodes_from(node_list2, bipartite=1)
B.add_edges_from(edge_list)
return B


def clustered_unipartite(n_groups,n_ind,my_p_dist,my_g_dist,**kwargs):
edge_list,vertex_attributes = generate_hypergraph_bipartite_edge_list(n_groups,n_ind,my_p_dist,my_g_dist)
projected_nodes = [k for k,v in vertex_attributes.items() if v == 1]#identify ndes to project graph onto
def clustered_unipartite(n_groups, n_ind, my_p_dist, my_g_dist, **kwargs):
edge_list, vertex_attributes = generate_hypergraph_bipartite_edge_list(
n_groups, n_ind, my_p_dist, my_g_dist
)
projected_nodes = [
k for k, v in vertex_attributes.items() if v == 1
] # identify ndes to project graph onto
B = bipartite_graph(edge_list)
U = nx.projected_graph(B,projected_nodes)#create unipartite projection
U = nx.projected_graph(B, projected_nodes) # create unipartite projection
return nx.adjacency_matrix(U).todense()
Loading

0 comments on commit 1624388

Please sign in to comment.