pnnl / HyperNetX

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

Modularity function returns error: AttributeError: 'Entity' object has no attribute 'strength' #98

Open thosvarley opened 1 year ago

thosvarley commented 1 year ago

When I call print('qH =',hmod.modularity(H, K, strict)) it returns AttributeError: 'Entity' object has no attribute 'strength'

The full code:

import igraph as ig
import hypernetx as hnx
import hypernetx.algorithms.hypergraph_modularity as hmod

H = hnx.Hypergraph(lookup)
H = hmod.precompute_attributes(H)
#%%
K = hmod.kumar(H)
#%%
strict = hmod.strict
## Compute qH
print('qH =',hmod.modularity(H, K, strict))

Lookup is a dictionary of the form: {key1 : (hedge1, hedge2...), key2 : (hedge1, hedge3...)}

madelynshapiro commented 1 year ago

Thank you for raising an issue, I will look into it. It looks like a line of code from your original post has been updated from hmod.precompute_attributes(H) -> H = hmod.precompute_attributes(H) - just to clarify, you are still receiving the same error message with the updated code?

thosvarley commented 1 year ago

EDIT: I realize that I was feeding the Hgraph in wrong. I was doing:

{node : (hedge1, hedge2...)} when I should have been doing {hedge1 : (node1, node2...)}. Fixing this solved the issue.

thosvarley commented 1 year ago

Reopening the issue since the change described above just changes the error from being about strength to being about weight.