From 230d52e784392fd7053099e345943f58e3a5e32e Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Fri, 3 Jul 2020 10:51:37 +0200 Subject: add a linear ParamFit test --- test/test_parameters.py | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 test/test_parameters.py diff --git a/test/test_parameters.py b/test/test_parameters.py new file mode 100644 index 0000000..a466d91 --- /dev/null +++ b/test/test_parameters.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python3 + +from dfatool import dfatool as dt +from dfatool import parameters +from dfatool.utils import by_name_to_by_param +import unittest + +import numpy as np + + +class TestModels(unittest.TestCase): + def test_distinct_param_values(self): + X = np.arange(35) + by_name = { + "TX": { + "param": [(x % 5, x % 7) for x in X], + "power": X, + "attributes": ["power"], + } + } + self.assertEqual( + parameters.distinct_param_values(by_name, "TX"), + [list(range(5)), list(range(7))], + ) + + def test_parameter_detection_linear(self): + rng = np.random.default_rng() + X = np.arange(200) % 50 + Y = X + rng.normal(size=X.size) + by_name = { + "TX": { + "param": [(x % 5, x) for x in X], + "power": Y, + "attributes": ["power"], + } + } + by_param = by_name_to_by_param(by_name) + stats = parameters.ParamStats(by_name, by_param, ["p_mod5", "p_linear"], dict()) + + self.assertEqual(stats.depends_on_param("TX", "power", "p_mod5"), False) + self.assertEqual(stats.depends_on_param("TX", "power", "p_linear"), True) + + paramfit = dt.ParallelParamFit(by_param) + paramfit.enqueue("TX", "power", 1, "p_linear") + paramfit.fit() + + fit_result = dt.get_fit_result(paramfit.results, "TX", "power") + self.assertEqual(fit_result["p_linear"]["best"], "linear") + + +if __name__ == "__main__": + unittest.main() -- cgit v1.2.3