Skip to content

Commit

Permalink
Use N or N-1 instead of empirical kmax in degree histogram
Browse files Browse the repository at this point in the history
Tweaks `DegreeDivergence` to use N (if there are self-loops) or N-1 (if there
are not) instead of the largest observed degree when constructing the degree
histogram. This works because a `Counter` behaves like a `defaultdict(int)`, so
the list comprehension

```
hist = np.array([counter[v] for v in range(max_deg)])
```

pads out the zeros automatically. It should rarely affect results, but has the
advantages of (i) being slightly more accurate for the pedants among us and (ii)
being faster for some reason. And while it doesn't affect the JSD, if we ever do
implement #174, maybe it ends up mattering somewhere else.
  • Loading branch information
sdmccabe committed Aug 1, 2019
1 parent 749adbc commit 96c562d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion netrd/distance/degree_divergence.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ def degree_vector_histogram(graph):
"""
vec = np.array(list(dict(graph.degree()).values()))
max_deg = max(vec)
if next(graph.selfloop_edges(), False):
max_deg = len(graph)
else:
max_deg = len(graph) - 1
counter = Counter(vec)
hist = np.array([counter[v] for v in range(max_deg)])
return vec, hist
Expand Down

0 comments on commit 96c562d

Please sign in to comment.