1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 from math import pi
24 from numpy import array, float64, ones
25 from unittest import TestCase
26
27
28 from target_functions.n_state_model import N_state_opt
29
30
32 """Unit tests for the target_functions.n_state_model relax module."""
33
35 """Unit test 1 of the func() method.
36
37 The number of states is 2 and the number of tensors is 3. All states are equi-probable with
38 Euler rotations of {0, 0, 0}, hence the reduced tensors should be the same size as the full
39 tensors. The target function is designed to be zero.
40 """
41
42
43 N = 2
44 init_params = array([0.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], float64)
45 full_tensors = array([1.0, 0.5, 0.0, 0.0, 0.0, 1.0, 0.5, 1.0, 0.0, 0.0, 1.0, 0.5, 0.0, 1.0, 0.0], float64)
46 red_data = array([1.0, 0.5, 0.0, 0.0, 0.0, 1.0, 0.5, 1.0, 0.0, 0.0, 1.0, 0.5, 0.0, 1.0, 0.0], float64)
47 err = ones(3*5, float64)
48 full_in_ref_frame = [1, 1, 1]
49
50
51 model = N_state_opt(model='2-domain', N=2, init_params=init_params, full_tensors=full_tensors, red_data=red_data, red_errors=err, full_in_ref_frame=full_in_ref_frame)
52
53
54 for i in range(3):
55
56 chi2 = model.func_2domain(init_params)
57
58
59 self.assertEqual(chi2, 0.0)
60
61
63 """Unit test 2 of the func() method.
64
65 The number of states is 2 and the number of tensors is 3. All states are equi-probable with
66 Euler rotations of {0, 0, 0}, hence the reduced tensors should be the same size as the full
67 tensors. The target function is designed to be one.
68 """
69
70
71 N = 2
72 init_params = array([0.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], float64)
73 full_tensors = array([1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0], float64)
74 red_data = array([1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0], float64)
75 err = ones(3*5, float64)
76 full_in_ref_frame = [1, 1, 1]
77
78
79 model = N_state_opt(model='2-domain', N=2, init_params=init_params, full_tensors=full_tensors, red_data=red_data, red_errors=err, full_in_ref_frame=full_in_ref_frame)
80
81
82 for i in range(3):
83
84 chi2 = model.func_2domain(init_params)
85
86
87 self.assertEqual(chi2, 1.0)
88
89
91 """Unit test 3 of the func() method.
92
93 The number of states is 2 and the number of tensors is 3. The first state has a prob of 1.0
94 with Euler rotations of {90, 0, 0}, hence the reduced tensors should be the same size as the full
95 tensors but rotated by 90 degrees. The target function is designed to be zero.
96 """
97
98
99 N = 2
100 init_params = array([1.0, -pi/2.0, 0.0, 0.0, 0.0, 0.0, 0.0], float64)
101 full_tensors = array([1.0, 0.5, 0.0, 0.0, 0.0, 1.0, 0.5, 1.0, 0.0, 0.0, 1.0, 0.5, 0.0, 1.0, 0.0], float64)
102 red_data = array([0.5, 1.0, 0.0, 0.0, 0.0, 0.5, 1.0, -1.0, 0.0, 0.0, 0.5, 1.0, 0.0, 0.0, 1.0], float64)
103 err = ones(3*5, float64)
104 full_in_ref_frame = [1, 1, 1]
105
106
107 model = N_state_opt(model='2-domain', N=2, init_params=init_params, full_tensors=full_tensors, red_data=red_data, red_errors=err, full_in_ref_frame=full_in_ref_frame)
108
109
110 for i in range(3):
111
112 chi2 = model.func_2domain(init_params)
113
114
115 self.assertAlmostEqual(chi2, 0.0)
116
117
119 """Unit test 4 of the func() method.
120
121 The number of states is 2 and the number of tensors is 3. All states are equi-probable with
122 Euler rotations of {90, 0, 0} for only the first. The target function is designed to be
123 zero.
124 """
125
126
127 N = 2
128 init_params = array([0.5, -pi/2.0, 0.0, 0.0, 0.0, 0.0, 0.0], float64)
129 full_tensors = array([1.0, 0.5, 0.0, 0.0, 0.0, 1.0, 0.5, 1.0, 0.0, 0.0, 1.0, 0.5, 0.0, 1.0, 0.0], float64)
130 red_data = array([0.75, 0.75, 0.0, 0.0, 0.0, 0.75, 0.75, 0.0, 0.0, 0.0, 0.75, 0.75, 0.0, 0.5, 0.5], float64)
131 err = ones(3*5, float64)
132 full_in_ref_frame = [1, 1, 1]
133
134
135 model = N_state_opt(model='2-domain', N=2, init_params=init_params, full_tensors=full_tensors, red_data=red_data, red_errors=err, full_in_ref_frame=full_in_ref_frame)
136
137
138 for i in range(3):
139
140 chi2 = model.func_2domain(init_params)
141
142
143 self.assertAlmostEqual(chi2, 0.0)
144