summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDaniel Friesel <daniel.friesel@uos.de>2020-04-29 08:58:14 +0200
committerDaniel Friesel <daniel.friesel@uos.de>2020-04-29 08:58:34 +0200
commit2747d21d4db8f4f123874743dfce512d0cabc875 (patch)
tree01561b0505a786455b264a126ce9b89c04b61ca7 /lib
parent0ec4c9ccfaae15b3ba5db74a8fdddc07adf20eb9 (diff)
move running_mean helper from dfatool to utils
Diffstat (limited to 'lib')
-rw-r--r--lib/dfatool.py13
-rw-r--r--lib/utils.py11
2 files changed, 12 insertions, 12 deletions
diff --git a/lib/dfatool.py b/lib/dfatool.py
index 607028e..b206250 100644
--- a/lib/dfatool.py
+++ b/lib/dfatool.py
@@ -16,7 +16,7 @@ from functions import analytic
from functions import AnalyticFunction
from parameters import ParamStats
from utils import vprint, is_numeric, soft_cast_int, param_slice_eq, remove_index_from_tuple
-from utils import by_name_to_by_param, match_parameter_values
+from utils import by_name_to_by_param, match_parameter_values, running_mean
try:
from pubcode import Code128
@@ -29,17 +29,6 @@ except ImportError:
arg_support_enabled = True
-def running_mean(x: np.ndarray, N: int) -> np.ndarray:
- """
- Compute `N` elements wide running average over `x`.
-
- :param x: 1-Dimensional NumPy array
- :param N: how many items to average
- """
- cumsum = np.cumsum(np.insert(x, 0, 0))
- return (cumsum[N:] - cumsum[:-N]) / N
-
-
def gplearn_to_function(function_str: str):
"""
Convert gplearn-style function string to Python function.
diff --git a/lib/utils.py b/lib/utils.py
index a582d6b..26a591e 100644
--- a/lib/utils.py
+++ b/lib/utils.py
@@ -14,6 +14,17 @@ def vprint(verbose, string):
print(string)
+def running_mean(x: np.ndarray, N: int) -> np.ndarray:
+ """
+ Compute `N` elements wide running average over `x`.
+
+ :param x: 1-Dimensional NumPy array
+ :param N: how many items to average
+ """
+ cumsum = np.cumsum(np.insert(x, 0, 0))
+ return (cumsum[N:] - cumsum[:-N]) / N
+
+
def human_readable(value, unit):
for prefix, factor in (('p', 1e-12), ('n', 1e-9), (u'ยต', 1e-6), ('m', 1e-3), ('', 1), ('k', 1e3)):
if value < 1e3 * factor: