Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Katz centrality #370

Merged
merged 15 commits into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions tests/algorithms/test_centrality.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,24 +163,23 @@ def test_katz_centrality(edgelist1, edgelist3):
# test empty hypergraph
H = xgi.Hypergraph()
c, nodedict = xgi.katz_centrality(H, index=True)
assert c == np.array([])
assert nodedict == dict()

# test hypergraph with no edge
H.add_nodes_from([1, 2, 3])
c, nodedict = xgi.katz_centrality(H, index=True)
res = np.ones(3)/3
assert np.abs(float(np.sum(c - res))) < 1e-3
acombretrenouard marked this conversation as resolved.
Show resolved Hide resolved

# test numerical values
H = xgi.Hypergraph(edgelist1)
c, nodedict = xgi.katz_centrality(H, index=True)
for key in nodedict.keys():
if nodedict[key] == 4:
assert np.abs(c[key] - 0.0) <= 10**-3
elif nodedict[key] == 1:
assert np.abs(c[key] - 0.2519685) <= 10**-3
else:
pass
res = np.array([0.2519685 , 0.2519685 , 0.2519685 , 0. , 0.12647448, 0.37746639, 0.25246065, 0.25246065])
assert np.abs(float(np.sum(c - res))) < 1e-3

# test with no index
H = xgi.Hypergraph(edgelist3)
c = xgi.katz_centrality(H, index=False)

return
res = np.array([0.34686161, 0.34686161, 0.51894799, 0.51894799, 0.34686161, 0.34686161])
assert np.abs(float(np.sum(c - res))) < 1e-3
2 changes: 1 addition & 1 deletion xgi/algorithms/centrality.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ def katz_centrality(H, index=False, cutoff=100):
Parameters
----------
H : xgi.Hypergraph
Hypergraph on which to compute the alpha centralities.
Hypergraph on which to compute the Kayz-centralities.
index : bool
If set to True, will return a dictionary mapping each vector index to a node.
acombretrenouard marked this conversation as resolved.
Show resolved Hide resolved
cutoff : int
Expand Down