Skip to content

Commit fa76b89

Browse files
committed
test_example_1 added.
1 parent 111f28a commit fa76b89

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

tests/test_example_1.py

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# B_LEAST ISO 6143:2001
2+
# Michael Wollensack METAS - 24.10.2024 - 29.11.2024
3+
4+
# pylint: disable=missing-module-docstring
5+
# pylint: disable=missing-class-docstring
6+
# pylint: disable=missing-function-docstring
7+
# pylint: disable=wildcard-import
8+
# pylint: disable=unused-wildcard-import
9+
10+
from pytest import approx
11+
from metas_b_least import *
12+
13+
def test_example_1():
14+
# See appendix B.2.1 Example 1, pages 23 - 25
15+
print('Example B LEAST 1\n')
16+
cal_data = b_read_cal_data(os.path.join(data_dir, 'b_least_1_data_cal.txt'))
17+
meas_data = b_read_meas_data(os.path.join(data_dir, 'b_least_1_data_meas.txt'))
18+
print('Linear function\n')
19+
b, b_cov, b_res, x, x_cov = b_test(cal_data, meas_data, b_linear_func)
20+
# intercept b0
21+
assert b[0] == approx(-3.5747e-1, abs=0.0001e-1)
22+
# slope b1
23+
assert b[1] == approx(2.4612e1, abs=0.0001e1)
24+
# standard uncertainty of the intercept
25+
assert np.sqrt(b_cov[0, 0]) == approx(1.5716e-1, abs=0.0005e-1) # 1.5711e-1
26+
# standard uncertainty of the slope
27+
assert np.sqrt(b_cov[1, 1]) == approx(4.8048e-1, abs=0.0022e-1) # 4.8026e-1
28+
# covariance between intercept and slope
29+
assert b_cov[0, 1] == approx(-5.6921e-2, abs=0.00520e-2) # 5.6869e-2
30+
# residual
31+
assert np.sum(b_res*b_res) == approx(0.6743, abs=0.0001)
32+
# goodness of fit
33+
assert np.max(np.abs(b_res)) == approx(0.568, abs=0.001)
34+
# mixture no 1
35+
assert x[0] == approx(5.9923, abs=0.0001)
36+
assert np.sqrt(x_cov[0, 0]) == approx(1.6377e-1, abs=0.0001e-1)
37+
# mixture no 2
38+
assert x[1] == approx(1.4409e1, abs=0.0001e1)
39+
assert np.sqrt(x_cov[1, 1]) == approx(3.5599e-1, abs=0.0005e-1) # 3.5594e-1
40+
# mixture no 3
41+
assert x[2] == approx(4.3943e1, abs=0.0001e1)
42+
assert np.sqrt(x_cov[2, 2]) == approx(1.1631, abs=0.0003) # 1.1628
43+
# covariance between values for mixtures 1 and 2
44+
assert x_cov[0, 1] == approx(1.16e-2, abs=0.01e-2)
45+
# covariance between values for mixtures 1 and 3
46+
assert x_cov[0, 2] == approx(1.48e-2, abs=0.01e-2)
47+
# covariance between values for mixtures 2 and 3
48+
assert x_cov[1, 2] == approx(1.37e-1, abs=0.01e-1)

0 commit comments

Comments
 (0)