Package test_suite :: Package unit_tests :: Package _maths_fns :: Module test_n_state_model
[hide private]
[frames] | no frames]

Source Code for Module test_suite.unit_tests._maths_fns.test_n_state_model

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2008-2009 Edward d'Auvergne                                   # 
  4  #                                                                             # 
  5  # This file is part of the program relax.                                     # 
  6  #                                                                             # 
  7  # relax is free software; you can redistribute it and/or modify               # 
  8  # it under the terms of the GNU General Public License as published by        # 
  9  # the Free Software Foundation; either version 2 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # relax is distributed in the hope that it will be useful,                    # 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 15  # GNU General Public License for more details.                                # 
 16  #                                                                             # 
 17  # You should have received a copy of the GNU General Public License           # 
 18  # along with relax; if not, write to the Free Software                        # 
 19  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   # 
 20  #                                                                             # 
 21  ############################################################################### 
 22   
 23  # Python module imports. 
 24  from math import pi 
 25  from numpy import array, float64, ones 
 26  from unittest import TestCase 
 27   
 28  # relax module imports. 
 29  from maths_fns.n_state_model import N_state_opt 
 30   
 31   
32 -class Test_n_state_model(TestCase):
33 """Unit tests for the maths_fns.n_state_model relax module.""" 34
35 - def test_func1(self):
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 # Init vals. 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 # Set up the class. 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 # Call the target function 3 times. 55 for i in xrange(3): 56 # Target function. 57 chi2 = model.func_2domain(init_params) 58 59 # Test that the chi2 value is zero each time! 60 self.assertEqual(chi2, 0.0)
61 62
63 - def test_func2(self):
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 # Init vals. 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 # Set up the class. 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 # Call the target function 3 times. 83 for i in xrange(3): 84 # Target function. 85 chi2 = model.func_2domain(init_params) 86 87 # Test that the chi2 value is zero each time! 88 self.assertEqual(chi2, 1.0)
89 90
91 - def test_func3(self):
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 # Init vals. 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 # Set up the class. 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 # Call the target function 3 times. 111 for i in xrange(3): 112 # Target function. 113 chi2 = model.func_2domain(init_params) 114 115 # Test that the chi2 value is zero each time! 116 self.assertAlmostEqual(chi2, 0.0)
117 118
119 - def test_func4(self):
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 # Init vals. 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 # Set up the class. 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 # Call the target function 3 times. 139 for i in xrange(3): 140 # Target function. 141 chi2 = model.func_2domain(init_params) 142 143 # Test that the chi2 value is zero each time! 144 self.assertAlmostEqual(chi2, 0.0)
145