Skip to content

Commit

Permalink
added sum as a stats method (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
nwlandry authored Sep 13, 2022
1 parent 7504098 commit d439345
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions tests/stats/test_edgestats.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,23 @@ def test_aggregates(edgelist1, edgelist2, edgelist8):
H = xgi.Hypergraph(edgelist1)
assert H.edges.order.max() == 2
assert H.edges.order.min() == 0
assert H.edges.order.sum() == 5
assert round(H.edges.order.mean(), 3) == 1.25
assert round(H.edges.order.std(), 3) == 0.829
assert round(H.edges.order.var(), 3) == 0.688

H = xgi.Hypergraph(edgelist2)
assert H.edges.order.max() == 2
assert H.edges.order.min() == 1
assert H.edges.order.sum() == 4
assert round(H.edges.order.mean(), 3) == 1.333
assert round(H.edges.order.std(), 3) == 0.471
assert round(H.edges.order.var(), 3) == 0.222

H = xgi.Hypergraph(edgelist8)
assert H.edges.order.max() == 4
assert H.edges.order.min() == 1
assert H.edges.order.sum() == 17
assert round(H.edges.order.mean(), 3) == 1.889
assert round(H.edges.order.std(), 3) == 0.875
assert round(H.edges.order.var(), 3) == 0.765
Expand Down
3 changes: 3 additions & 0 deletions tests/stats/test_nodestats.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,20 +160,23 @@ def test_aggregates(edgelist1, edgelist2, edgelist8):
H = xgi.Hypergraph(edgelist1)
assert H.nodes.degree.max() == 2
assert H.nodes.degree.min() == 1
assert H.nodes.degree.sum() == 9
assert round(H.nodes.degree.mean(), 3) == 1.125
assert round(H.nodes.degree.std(), 3) == 0.331
assert round(H.nodes.degree.var(), 3) == 0.109

H = xgi.Hypergraph(edgelist2)
assert H.nodes.degree.max() == 2
assert H.nodes.degree.min() == 1
assert H.nodes.degree.sum() == 7
assert round(H.nodes.degree.mean(), 3) == 1.167
assert round(H.nodes.degree.std(), 3) == 0.373
assert round(H.nodes.degree.var(), 3) == 0.139

H = xgi.Hypergraph(edgelist8)
assert H.nodes.degree.max() == 6
assert H.nodes.degree.min() == 2
assert H.nodes.degree.sum() == 26
assert round(H.nodes.degree.mean(), 3) == 3.714
assert round(H.nodes.degree.std(), 3) == 1.385
assert round(H.nodes.degree.var(), 3) == 1.918
Expand Down
2 changes: 1 addition & 1 deletion xgi/readwrite/xgi_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def load_xgi_data(dataset, nodetype=None, edgetype=None):
index = requests.get(index_url).json()
if dataset not in index:
print("Valid dataset names:")
print(*index, sep = "\n")
print(*index, sep="\n")
raise XGIError("Must choose a valid dataset name!")

r = requests.get(index[dataset]["url"])
Expand Down
4 changes: 4 additions & 0 deletions xgi/stats/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ def min(self):
"""The minimum value of this stat."""
return self.asnumpy().min(axis=0)

def sum(self):
"""The sum of this stat."""
return self.asnumpy().sum(axis=0)

def mean(self):
"""The arithmetic mean of this stat."""
return self.asnumpy().mean(axis=0)
Expand Down

0 comments on commit d439345

Please sign in to comment.