pnnl / HyperNetX

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

Please provide support for weighted hypergraphs #35

Closed jim-rafferty closed 4 years ago

jim-rafferty commented 4 years ago

Hi, this is a really good package :)

It would be loads more useful if you could provide support for weighted hypergraphs. It seems to be possible to create a weighted hypergraph at the moment like this:

import itertools
import hypernetx as hnx
import numpy as np

labels = "ABCD"
nodes = set(labels)
edges = list(
    itertools.chain(
        *[list(itertools.combinations(set(labels), ii)) for ii in range(2, len(labels))]
    )
)
hnx_edges = hnx.EntitySet(
    "Edges", 
    [hnx.Entity(
            "".join(ee), 
            ee,
            weight=np.random.rand() 
        ) for ee in edges]
)

h = hnx.Hypergraph(hnx_edges)
hnx.draw(h)
print(h.edges.elements)

but it's not possible to do any analysis with the weights as far as I can tell (see for example, the output of hnx.dist_stats(h) )

Are there any plans to add this type of functionality?

Thanks!

brendapraggastis commented 4 years ago

Thanks @jim-rafferty, You are correct, at present we only have the ability to add weight (or any other property) to an Entity. What we do with that information needs to be added to the library. We hope to include it in all of our statistics and algorithms but are slow to release anything before we know how best to integrate it into the existing code. If you have specific suggestions or would like to contribute code, that would be great. Stay tuned as we hope to have some new material pushed by the end of summer.

jim-rafferty commented 4 years ago

Thanks @brendapraggastis

I realise my initial request was horribly vague and open ended - apologies. I will have a look at the code and see if I can send you a PR.

Thanks again.

michaeldorner commented 3 years ago

Have I understood that correctly: Any property added to an edge (via Entity property) is not accessible in the graph?

edges_set = hnx.EntitySet(
    "edges", 
    elements = [hnx.Entity('e1', elements=['a', 'b'], weight=1)]
)
hnx.Hypergraph(edges_set).edges.elements

No change to get the weight?

Vivdaddy commented 2 years ago

Could we please get an answer to the above question? Also, since this thread is about an year old, have there been any updates with weighted hyperedges? https://github.com/pnnl/HyperNetX/issues/35#issuecomment-874583001

brendapraggastis commented 2 years ago

To answer @michaeldorner , when the hypergraph is generated it creates a copy of the EntitySet so any change to the original EntitySet will not be reflected in the hypergraph.

@Vivdaddy : We are actively working on the most intuitive and useful way to add metadata to a hypergraph. Currently attributes can be added directly to the nodes and edges. Tutorial 13 based on our hypergraph modularity module uses the attributes strength and weight on the nodes and edges. Have a look specifically at the precompute_attributes method starting on line 74 of the module.

Vivdaddy commented 2 years ago

Thank you, I will check it out.