Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial clique complex #200

Merged
merged 9 commits into from
Oct 24, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix: import
  • Loading branch information
maximelucas committed Jul 26, 2022
commit 6484f7ae83283a9a92e1be6a6a3f7522662e1419
13 changes: 9 additions & 4 deletions xgi/generators/classic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
from itertools import combinations

import networkx as nx
import numpy as np

from xgi import SimplicialComplex
from ..classes import SimplicialComplex
from ..utils import py_random_state

__all__ = [
Expand Down Expand Up @@ -202,20 +203,24 @@ def flag_complex(G, max_order=2, ps=None, seed=None):
# defined. Otherwise, a circular import error would happen.

nodes = G.nodes()
edges = G.edges()

# compute all triangles to fill
max_cliques = list(nx.find_cliques(G))

S = SimplicialComplex()
S.add_nodes_from(nodes)
S.add_simplices_from(edges)
if not ps: # promote all cliques
S.add_simplices_from(max_cliques, max_order=max_order)
else: # promote cliques with a given probability
for i, p in enumerate(ps[max_order - 1]):
for i, p in enumerate(ps[:max_order - 1]):
d = i + 2 # simplex order
cliques_d = [x for x in max_cliques if len(x) == d + 1]
maximelucas marked this conversation as resolved.
Show resolved Hide resolved
probas = seed.random.random(size=len(cliques_d))
cliques_d_to_add = cliques_d[probas <= p]
cliques_d_to_add = []
for el in cliques_d:
if seed.random() <= p:
cliques_d_to_add.append(el)
maximelucas marked this conversation as resolved.
Show resolved Hide resolved
S.add_simplices_from(cliques_d_to_add, max_order=max_order)

return S