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