From f99073126193e346bfb66d3ad8e683025bd1a073 Mon Sep 17 00:00:00 2001 From: "Azalea (on HyDEV-Daisy)" Date: Thu, 25 Aug 2022 23:16:48 -0400 Subject: [PATCH] [+] Add stddev to scientific utils --- hypy_utils/nlp_utils.py | 1 + hypy_utils/scientific_utils.py | 15 +++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/hypy_utils/nlp_utils.py b/hypy_utils/nlp_utils.py index 2fd6985..f30ed63 100644 --- a/hypy_utils/nlp_utils.py +++ b/hypy_utils/nlp_utils.py @@ -1,6 +1,7 @@ """ Natual language processing utils """ +from __future__ import annotations def camel_split(camel: str) -> list[str]: diff --git a/hypy_utils/scientific_utils.py b/hypy_utils/scientific_utils.py index 5e3519d..b78463f 100644 --- a/hypy_utils/scientific_utils.py +++ b/hypy_utils/scientific_utils.py @@ -3,9 +3,7 @@ Importing this file requires numpy, matplotlib, and numba """ from __future__ import annotations -import time from dataclasses import dataclass -from typing import Callable import numpy as np from matplotlib import pyplot as plt @@ -23,13 +21,21 @@ class Statistics: maximum: float count: int total: float + stddev: float def get_metric_6(self) -> tuple[float, float, float, float, float, float]: return self.mean, self.median, self.minimum, self.maximum, self.lower_quartile, self.upper_quartile + def print(self, dec: int = 2): + print(f'> Mean: {round(self.mean, dec)}, Median: {round(self.median, dec)}') + print(f'> Min: {round(self.minimum, dec)}, Max: {round(self.maximum, dec)}') + print(f'> Q1: {round(self.lower_quartile, dec)}, Q3: {round(self.upper_quartile, dec)}') + print(f'> StdDev: {round(self.stddev, dec)}, IQR: {round(self.iqr, dec)}') + print(f'> N: {self.count}') + @njit(cache=True) -def _calc_col_stats_helper(col: np.ndarray) -> tuple[float, float, float, float, float, float, float, int, float]: +def _calc_col_stats_helper(col: np.ndarray) -> tuple[float, float, float, float, float, float, float, int, float, float]: q1 = np.quantile(col, 0.25) q3 = np.quantile(col, 0.75) return ( @@ -41,7 +47,8 @@ def _calc_col_stats_helper(col: np.ndarray) -> tuple[float, float, float, float, float(np.min(col)), float(np.max(col)), len(col), - float(np.sum(col)) + float(np.sum(col)), + float(np.std(col)) )