From c65b747b4d030931a9ddba7e8f4361efd10f1762 Mon Sep 17 00:00:00 2001 From: AlexBennett Date: Fri, 15 Nov 2024 13:25:54 +0100 Subject: [PATCH 1/2] Jtk housekeeping fixed expansion sum and removed redundent for-loop --- glycowork/glycan_data/stats.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/glycowork/glycan_data/stats.py b/glycowork/glycan_data/stats.py index 4d509b2f..d93b34db 100644 --- a/glycowork/glycan_data/stats.py +++ b/glycowork/glycan_data/stats.py @@ -25,22 +25,22 @@ def fast_two_sum(a, b): """Assume abs(a) >= abs(b)""" - x = int(a) + int(b) - y = b - (x - int(a)) + x = a + b + y = b - (x - a) return [x] if y == 0 else [x, y] def two_sum(a, b): """For unknown order of a and b""" - x = int(a) + int(b) - y = (a - (x - int(b))) + (b - (x - int(a))) + x = a + b + y = (a - (x - b)) + (b - (x - a)) return [x] if y == 0 else [x, y] def expansion_sum(*args): """For the expansion sum of floating points""" g = sorted(args, reverse = True) - q, *h = fast_two_sum(np.array(g[0]), np.array(g[1])) + q, *h = fast_two_sum(g[0], g[1]) for val in g[2:]: z = two_sum(q, np.array(val)) q, *extra = z @@ -294,7 +294,7 @@ def jtkdist(timepoints, param_dic, reps = 1, normal = False): param_dic.update({"GRP_SIZE": tim, "NUM_GRPS": len(tim), "NUM_VALS": nn, "MAX": M, "DIMS": [int(nn * (nn - 1) / 2), 1]}) if normal: - param_dic["VAR"] = (nn ** 2 * (2 * nn + 3) - np.sum(np.square(tim) * (2 * t + 3) for t in tim)) / 72 # Variance of JTK + param_dic["VAR"] = (nn ** 2 * (2 * nn + 3) - np.sum(np.square(tim) * (2 * tim + 3) )) / 72 # Variance of JTK param_dic["SDV"] = math.sqrt(param_dic["VAR"]) # Standard deviation of JTK param_dic["EXV"] = M / 2 # Expected value of JTK param_dic["EXACT"] = False From 42627c79e826bb0d034698f136c2ebb3b5046a88 Mon Sep 17 00:00:00 2001 From: AlexBennett Date: Fri, 15 Nov 2024 13:41:43 +0100 Subject: [PATCH 2/2] Tidying and removing redundant for-loop --- glycowork/glycan_data/stats.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/glycowork/glycan_data/stats.py b/glycowork/glycan_data/stats.py index f6c2c2e2..6e599097 100644 --- a/glycowork/glycan_data/stats.py +++ b/glycowork/glycan_data/stats.py @@ -46,9 +46,9 @@ def expansion_sum(*args: Union[int, float] # numbers to sum ) -> Union[int, List[Union[int, float]]]: # sum as int or list "For the expansion sum of floating points" g = sorted(args, reverse = True) - q, *h = fast_two_sum(np.array(g[0]), np.array(g[1])) + q, *h = fast_two_sum(g[0], g[1]) for val in g[2:]: - z = two_sum(q, np.array(val)) + z = two_sum(q, val) q, *extra = z if extra: h += extra @@ -270,7 +270,7 @@ def jtkdist(timepoints: Union[int, np.ndarray], # number/array of timepoints wit param_dic.update({"GRP_SIZE": tim, "NUM_GRPS": len(tim), "NUM_VALS": nn, "MAX": M, "DIMS": [int(nn * (nn - 1) / 2), 1]}) if normal: - param_dic["VAR"] = (nn ** 2 * (2 * nn + 3) - np.sum(np.fromiter((np.square(t) * (2 * t + 3) for t in tim), dtype = float))) / 72 # Variance of JTK + param_dic["VAR"] = (nn ** 2 * (2 * nn + 3) - np.sum(np.fromiter((np.square(tim) * (2 * tim + 3)), dtype = float))) / 72 # Variance of JTK param_dic["SDV"] = math.sqrt(param_dic["VAR"]) # Standard deviation of JTK param_dic["EXV"] = M / 2 # Expected value of JTK param_dic["EXACT"] = False