xgi-org / xgi

CompleX Group Interactions (XGI) is a Python package for higher-order networks.
https://xgi.readthedocs.io
Other
178 stars 27 forks source link

EdgeView comparison only checks edge ID, not contents #194

Open leotrs opened 1 year ago

leotrs commented 1 year ago

This is Bad.

In [11]: H1 = xgi.Hypergraph([{0, 1, 2}, {0}, {1, 2}])

In [12]: H2 = xgi.Hypergraph([{1, 2, 3}, {0}, {1, 3}])

In [13]: H1 == H2
Out[13]: False

In [14]: H1.edges == H2.edges
Out[14]: True
leotrs commented 1 year ago

OK to be honest, what I wrote in the title is my current hunch as to why this is happening, but I might be wrong.

leotrs commented 1 year ago

An easy (temporary?) fix is to encourage the user to do this instead:

H1.edges.members(dtype=dict) == H2.edges.members(dtype=dict)
maximelucas commented 1 year ago

Is this a bug though? H.edges contains edges IDs, so your example is not so surprising. Although a user might write

In [14]: H1.edges == H2.edges

and expect

Out[14]: False

assuming it's gonna compare edges members rather than IDs.

We could implement = between H.edges as checking for the full dict {ID: members} as the fix you suggested. In both cases, we should clarify this in the doc.

leotrs commented 1 year ago

Yeah coming back to this the main problem I see is that the user may inadvertently compare two views from two different network instead of two views from the same network. And the question is whether we want EdgeViews to compare only based on the IDs rather than also take into account which network those IDs belong to.

leotrs commented 1 year ago

Okay I think my preference would be that comparing two views only works when they come from the same network. If the user wants to compare only the IDs contained, they can use view.ids. So we'd have:

H1.edges == H2.edges
# -> always False, regardless of edge IDs

H1.edges.ids == H2.edges.ids
# -> may be True, if H1 and H2 have the same edge IDs
leotrs commented 1 year ago

Will work on this after #406 is merged.

maximelucas commented 1 year ago

What do we want if the two have the same hyperedges (based on members) but different IDs?

leotrs commented 1 year ago

That sounds dangerously close to determining whether two hypergraphs are isomorphic :grin: