pnnl / HyperNetX

Python package for hypergraph analysis and visualization.
https://hypernetx.readthedocs.io
Other
501 stars 86 forks source link

Find all hyperedges for a node #64

Closed michaeldorner closed 2 years ago

michaeldorner commented 3 years ago

Hi, Maybe I am just blind (and/or stupid), but how can I identify (easily) all hyperedges of a given node n in a (static) hypergraph H in HyperNetX?

The solution I came up is:

[edge for edge, nodes in H.incidence_dict.items() if n in nodes]

But probably you had another, more performant solution in mind? Thank you!

brendapraggastis commented 3 years ago

Thanks for bringing up the issue, @michaeldorner. Our first goal was to get a static version out to speed up construction, but the need for elements/memberships in constant time remains. That is on the workbench now and we have a couple of possible solutions and hope to push a more performant version within the next 6 weeks. For now I am afraid the original (dynamic) hypergraph is faster for look up of incident edges. If you have ideas or code snippets you would like to suggest, please send them. We will be watching.

brendapraggastis commented 2 years ago

@michaeldorner We have solved this in v1.1 by adding a .memberships attribute to the nodes of a static hypergraph. Note that for dynamic hypergraphs the information is stored with each entity. For static hypergraphs the information is stored by the StaticEntitySet: Use: H.nodes.memberships[node_uid]