xgi icon indicating copy to clipboard operation
xgi copied to clipboard

wrong degree count with singleton

Open maximelucas opened this issue 2 years ago • 5 comments

Running

HH = xgi.Hypergraph([{1, 2, 3}, {4}, {5, 6}, {6, 7, 8}])
xgi.degree_counts(HH)

outputs [0, 7, 1].

It is even our test: https://github.com/ComplexGroupInteractions/xgi/blob/c262f406cf13e3d51e7b40e5534fbfcca223caff/tests/classes/test_function.py#L58).

But node 4 does not have any neighbour, so degree 0 should have count 1: the output should be [1, 6, 1].

maximelucas avatar Oct 05 '22 14:10 maximelucas

I think the rationale is that 4 belongs to one (singleton) edge. So in a way, it is correct. The fix would be to add a parameter "ignore_singletons" as is done elsewhere in the codebase.

On Wed, Oct 5, 2022, 4:55 PM Maxime Lucas @.***> wrote:

Running

HH = xgi.Hypergraph([{1, 2, 3}, {4}, {5, 6}, {6, 7, 8}])xgi.degree_counts(HH)

outputs [0, 7, 1].

It is even our test: https://github.com/ComplexGroupInteractions/xgi/blob/c262f406cf13e3d51e7b40e5534fbfcca223caff/tests/classes/test_function.py#L58 ).

But node 4 does not have any neighbour, so degree 0 should have count 1: the output should be [1, 6, 1].

— Reply to this email directly, view it on GitHub https://github.com/ComplexGroupInteractions/xgi/issues/190, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAILYAARUKLWDY4CWW5UUK3WBWJGXANCNFSM6AAAAAAQ5U76IA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

leotrs avatar Oct 11 '22 07:10 leotrs

Sure I agree that 4 is a singleton edge here. But what would you say the degree of node 4 is here?

I would say 0 because node 4 has no neighbour (not connected by any node by an edge). Or would you say it's 1 because the singleton edge 4 is a self-loop for node 4 to node 4? It thought that would have been encoded as an edge (4,4) - but now that I think of it, that cannot exist we have edges as sets now. Still would feel weird to have a self-loop represented as singleton edge no?

maximelucas avatar Oct 24 '22 15:10 maximelucas

It comes down to a matter of semantics/perspective. Is the degree the number of neighboring nodes? If so, do you count repetitions (when a neighbor appears in many different edges)? Or is the degree defined as the number of edges a node belongs to?

Since we are using the bipartite representation, I'd say the degree of a node in the hypergraph should just be the degree of the node in the bipartite representation, and in this case it is 1 because it belongs to exactly one hyperedge, which just happens to be a singleton.

But that's just my opinion and I'm happy to be convinced otherwise :)

leotrs avatar Oct 24 '22 16:10 leotrs

Ok I see where this is coming from now, thanks. Might just touch on this in next meeting to make sure it makes sense for everyone, and maybe specify in docs? This particular case of the singleton still feels weird to me even though I understand the bipartite reason 😅

maximelucas avatar Oct 27 '22 08:10 maximelucas

Agreed, let's put it in the agenda.

leotrs avatar Oct 27 '22 12:10 leotrs

I can totally share Max's doubts, but I also completely agree with the "clean" definition by Leo of degree as given by the bipartite. I would say that the only thing really needed at this point is to stress this example as much as possible in the documentation ;)

iaciac avatar Nov 03 '22 16:11 iaciac

Agreed, at this point we should just pick one and stick with it.

(Though, if I may add one more data point: in graphs with self-loops, usually a node's degree is increased by 2 if it has a self-loop...)

leotrs avatar Nov 03 '22 18:11 leotrs

If I remember correctly, we decided to simply add an explanation in the docstring for this, right?

maximelucas avatar Mar 27 '23 14:03 maximelucas

Yes!

leotrs avatar Apr 05 '23 07:04 leotrs