xgi icon indicating copy to clipboard operation
xgi copied to clipboard

EdgeView comparison only checks edge ID, not contents

Open leotrs opened this issue 2 years ago • 8 comments

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 avatar Oct 07 '22 06:10 leotrs

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 avatar Oct 07 '22 06:10 leotrs

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

H1.edges.members(dtype=dict) == H2.edges.members(dtype=dict)

leotrs avatar Oct 07 '22 07:10 leotrs

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.

maximelucas avatar Mar 27 '23 14:03 maximelucas

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 avatar Mar 27 '23 14:03 leotrs

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 avatar Jun 19 '23 08:06 leotrs

Will work on this after #406 is merged.

leotrs avatar Jun 19 '23 09:06 leotrs

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

maximelucas avatar Jun 19 '23 09:06 maximelucas

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

leotrs avatar Jun 19 '23 10:06 leotrs