pnnl / HyperNetX

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

How to build a hypergraph with node weights and hyperedge weights? #115

Closed mr1ck7 closed 3 months ago

mr1ck7 commented 1 year ago

Should I use edge_weight_prop,and node_weight_prop to assign values to edge weights and node weights? I noticed that there is a cell_weigh property, I want to know what cell weight represents

bpraggastis commented 1 year ago

Cell weight reference edge dependent weights. In general properties can be assigned to nodes and edges of a hypergraph but there might be some data that depends on the incidence pair. For example, take all movies as hyperedges and all actors who play in those movies as nodes. Tom Hanks will belong to Forest Gump and Toy Story. But his role in each of those movies, and the amount of money he made for each of those movies, are distinct. That is what is meant by cell properties - where a cell references the (node,edge) indexed position in the incidence matrix.

MCDalvean commented 1 year ago

Greetings,

I would like to inquire about weights assigned in HyperNetx.

The following is an extract from my code:

dataframe = pd.read_csv(r'/home........../nodescsv.csv')

H = hnx.Hypergraph(dataframe,edge_col="col1",node_col="col2",cell_weight_col="w")

The problem is that the weights do not seem to have any effect on the hypergraph. When I change the weights in the source dataframe, there is no change in the hypergraph.

Furthermore, when I run hmod.precompute_attributes(H) and run H.edges, H.nodes and H.d_weights, all 69 nodes in the hypergraph get weight = 1, strength = 69 and H.d_weights = 69.

Any insight you could provide on this issue would be most appreciated.

brendapraggastis commented 1 year ago

The hypergraph constructor copies the contents of your dataframe; it does not create references back to your dataframe. Your issue brought to light an issue with the hypergraph's view into the underlying dataset. We are working on a fix at the moment. I suspect the fix will also fix the error in the hypergraph modularity module that you are getting. Stay tuned and please bring more issues to us as you find them.

MCDalvean commented 1 year ago

Thanks for your reply. One clarification I should make (I didn't explain the situation well in my previous post): The dataframe has a column for nodes, a column for edges, and a column for weights. The problem is that both a and b below produce the same graph-

a ) H = hnx.Hypergraph(dataframe,edge_col="col1",node_col="col2",cell_weight_col="w") b) H = hnx.Hypergraph(dataframe,edge_col="col1",node_col="col2")

I hope this clarifies the issue.

brendapraggastis commented 3 months ago

@MCDalvean The latest release of HNX should behave as expected. thanks for bringing this to our attention. We did quite a bit of internal surgery and it is much faster and more reliable.