Skip to content

Commit

Permalink
fix to make hyperconvo output json-serializable
Browse files Browse the repository at this point in the history
  • Loading branch information
calebchiam committed May 30, 2020
1 parent efcbe91 commit eb34cfb
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions convokit/hyperconvo/hyperconvo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
from .hypergraph import Hypergraph

def degree_stat_funcs(nan_val):
# int wrapping is to convert from np.int64 to int, since np.int64 is not JSON-serializable
return {
"max": np.max,
"argmax": np.argmax,
"max": lambda l: int(np.max(l)),
"argmax": lambda l: int(np.argmax(l)),
"norm.max": lambda l: np.max(l) / np.sum(l) if np.sum(l) > 0 else 0,
"2nd-largest": lambda l: np.partition(l, -2)[-2] if len(l) > 1 else nan_val,
"2nd-argmax": lambda l: (-l).argsort()[1] if len(l) > 1 else nan_val,
"2nd-largest": lambda l: int(np.partition(l, -2)[-2]) if len(l) > 1 else nan_val,
"2nd-argmax": lambda l: int((-l).argsort()[1]) if len(l) > 1 else nan_val,
"norm.2nd-largest": lambda l: np.partition(l, -2)[-2] / np.sum(l) if (len(l) > 1 and np.sum(l) > 0) else nan_val,
"mean": np.mean,
"mean-nonzero": lambda l: np.mean(l[l != 0]) if len(l[l != 0]) > 0 else 0,
Expand Down

0 comments on commit eb34cfb

Please sign in to comment.