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

Minor feats #192

Merged
merged 2 commits into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
Expand Down Expand Up @@ -148,4 +148,4 @@ tutorials/test.*

# airspeed velocity files
benchmarks/html/
benchmarks/results/
benchmarks/results/
12 changes: 12 additions & 0 deletions tests/classes/test_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
from xgi.exception import IDNotFound, XGIError


def test_num_edges_order(edgelist2):

H = xgi.Hypergraph(edgelist2)

assert xgi.num_edges_order(H, 0) == 0
assert xgi.num_edges_order(H, 1) == 2
assert xgi.num_edges_order(H, 2) == 1
assert xgi.num_edges_order(H) == 3


def test_max_edge_order(edgelist1, edgelist4, edgelist5):
H0 = xgi.empty_hypergraph()
H1 = xgi.empty_hypergraph()
Expand Down Expand Up @@ -59,6 +69,8 @@ def test_degree_counts(edgelist1, edgelist2, edgelist3):
assert xgi.degree_counts(H2) == [0, 5, 1]
assert xgi.degree_counts(H3) == [0, 4, 2]

assert xgi.degree_counts(H1, order=2) == [2,6]


def test_degree_histogram(edgelist1, edgelist2, edgelist3):
H1 = xgi.Hypergraph(edgelist1)
Expand Down
25 changes: 23 additions & 2 deletions xgi/classes/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from .hypergraph import Hypergraph

__all__ = [
"num_edges_order",
"max_edge_order",
"is_possible_order",
"is_uniform",
Expand All @@ -27,6 +28,23 @@
"convert_labels_to_integers",
]

def num_edges_order(H, d=None):
"""The number of edges of order d.

Parameters
----------
H : Hypergraph
The hypergraph of interest.

d : int | None, optional
The order of edges to count. If None (default), counts
for all orders.
"""

if d is not None:
return len(H.edges.filterby("order", d))
else:
return H.num_edges

def max_edge_order(H):
"""The maximum order of edges in the hypergraph.
Expand Down Expand Up @@ -149,13 +167,16 @@ def edge_neighborhood(H, n, include_self=False):
return [H.edges.members(e) - {n} for e in H.nodes.memberships(n)]


def degree_counts(H):
def degree_counts(H, order=None):
"""Returns a list of the frequency of each degree value.

Parameters
----------
H : Hypergraph object
The hypergraph of interest
order: int, optional
Order of edges to take into account. If None (default),
consider all edges.

Returns
-------
Expand All @@ -177,7 +198,7 @@ def degree_counts(H):
[0, 3, 1]

"""
counts = Counter(H.degree().values())
counts = Counter(H.degree(order=order).values())
return [counts.get(i, 0) for i in range(max(counts) + 1)]


Expand Down