1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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()
|