From 529aeac0c1149505c0a235646dcd76c8b064c0d0 Mon Sep 17 00:00:00 2001 From: Nicholas Landry Date: Fri, 22 Mar 2024 16:52:36 -0400 Subject: [PATCH] added measures --- lcs/measures.py | 18 ++++++++++++++++++ lcs/utilities.py | 14 -------------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/lcs/measures.py b/lcs/measures.py index 0bfe12b..5a0a80b 100644 --- a/lcs/measures.py +++ b/lcs/measures.py @@ -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) @@ -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 diff --git a/lcs/utilities.py b/lcs/utilities.py index 72124b4..20c81a8 100644 --- a/lcs/utilities.py +++ b/lcs/utilities.py @@ -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)