Skip to content

Commit

Permalink
Test added and keep duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
pgberlureau committed Jul 4, 2024
1 parent 90c8782 commit b9f5435
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
6 changes: 6 additions & 0 deletions tests/convert/test_line_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ def test_to_line_graph(edgelist1, hypergraph1):

assert L.number_of_nodes() == 0
assert L.number_of_edges() == 0

H = xgi.Hypergraph({0: [(6.019592999999995, 47.2350647), (6.019592999999853, 47.2350647), (6.01959299999999, 47.2350647), (6.019592999999993, 47.2350647), (6.0195929999999755, 47.2350647)],
1: [(6.019592999999995, 47.2350647), (6.019592999999853, 47.2350647), (6.01959299999999, 47.2350647), (6.019592999999993, 47.2350647), (6.0195929999999755, 47.2350647)]})
L = xgi.to_line_graph(H)

assert L.number_of_nodes() == 2
assert L.number_of_edges() == 1

def test_abs_weighted_line_graph(edgelist1, hypergraph1, hypergraph2):
H = xgi.Hypergraph(edgelist1)
Expand Down
15 changes: 6 additions & 9 deletions xgi/convert/line_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,28 +53,25 @@ def to_line_graph(H, s=1, weights=None):
)
LG = nx.Graph()

edge_label_dict = {tuple(edge): index for index, edge in H._edge.items()}
LG.add_nodes_from([(k, {'original_hyperedge':v}) for k,v in H._edge.items()])

LG.add_nodes_from(edge_label_dict.values())

for edge1, edge2 in combinations(edge_label_dict.keys(), 2):
for e1, e2 in combinations(H._edge, 2):
# Check that the intersection size is larger than s
intersection_size = len(set(edge1).intersection(set(edge2)))
intersection_size = len(H._edge[e1].intersection(H._edge[e2]))
if intersection_size >= s:
if not weights:
# Add unweighted edge
LG.add_edge(
edge_label_dict[edge1], edge_label_dict[edge2]
e1, e2
)
else:
# Compute the (normalized) weight
weight = intersection_size
if weights == "normalized":
weight /= min([len(edge1), len(edge2)])
weight /= min([len(H._edge[e1]), len(H._edge[e2])])
# Add edge with weight
LG.add_edge(
edge_label_dict[edge1],
edge_label_dict[edge2],
e1, e2,
weight=weight,
)

Expand Down

0 comments on commit b9f5435

Please sign in to comment.