Skip to content

Commit

Permalink
added measures
Browse files Browse the repository at this point in the history
  • Loading branch information
nwlandry committed Mar 22, 2024
1 parent 3106df2 commit 529aeac
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
18 changes: 18 additions & 0 deletions lcs/measures.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ def fraction_of_correct_entries(samples, A, normalize=False, rho_guess=0.5):
return fce


def nodal_performance(Q, A):
return np.abs(Q - A).sum(axis=0) / A.shape[0]


def density(A):
n = A.shape[0]
return (A.sum() / 2) / binom(n, 2)
Expand All @@ -102,3 +106,17 @@ def auroc(samples, A):
if len(np.unique(y_true)) == 1:
return np.nan
return roc_auc_score(y_true, y_score)


def degrees(A):
if not isinstance(A, np.ndarray):
A = A.todense()
return A.sum(axis=0)


def clustering_coefficient(A):
T = np.diag(A @ A @ A)
k = degrees(A)
D = np.multiply(k, k - 1)
C = np.divide(T, D, out=np.zeros_like(T), where=D != 0)
return C
14 changes: 0 additions & 14 deletions lcs/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,6 @@ def nu_distribution(x, A):
return mat


def degrees(A):
if not isinstance(A, np.ndarray):
A = A.todense()
return A.sum(axis=0)


def clustering_coefficient(A):
T = np.diag(A @ A @ A)
k = degrees(A)
D = np.multiply(k, k - 1)
C = np.divide(T, D, out=np.zeros_like(T), where=D!=0)
return C


def power_law(n, minval, maxval, alpha, seed=None):
if seed is not None:
np.random.seed(seed)
Expand Down

0 comments on commit 529aeac

Please sign in to comment.