mailr6949 - /1.3/test_suite/unit_tests/_maths_fns/test_chi2.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on July 24, 2008 - 14:45:
Author: bugman
Date: Thu Jul 24 14:45:23 2008
New Revision: 6949

URL: http://svn.gna.org/viewcvs/relax?rev=6949&view=rev
Log:
Fixed the unit tests for dchi2_element and d2chi2_element.

Two new unit tests have been added for the dchi2 and d2chi2 functions as well.


Modified:
    1.3/test_suite/unit_tests/_maths_fns/test_chi2.py

Modified: 1.3/test_suite/unit_tests/_maths_fns/test_chi2.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/test_suite/unit_tests/_maths_fns/test_chi2.py?rev=6949&r1=6948&r2=6949&view=diff
==============================================================================
--- 1.3/test_suite/unit_tests/_maths_fns/test_chi2.py (original)
+++ 1.3/test_suite/unit_tests/_maths_fns/test_chi2.py Thu Jul 24 14:45:23 2008
@@ -21,7 +21,7 @@
 
###############################################################################
 
 # Python module imports.
-from numpy import float64, array
+from numpy import array, float64, zeros
 from unittest import TestCase
 
 # relax module imports.
@@ -103,8 +103,35 @@
         """
 
         # Calculate the gradient elements.
-        grad0 = dchi2(self.data, self.back_calc, self.back_calc_grad[0], 
self.errors)
-        grad1 = dchi2(self.data, self.back_calc, self.back_calc_grad[1], 
self.errors)
+        grad = zeros(2, float64)
+        dchi2(grad, 2, self.data, self.back_calc, self.back_calc_grad, 
self.errors)
+
+        # Assert, to a precision of 13 decimal places, that the gradient is 
[0, 10].
+        self.assertAlmostEqual(grad[0], 0.0, places=13)
+        self.assertAlmostEqual(grad[1], 10.0, places=13)
+
+        # Delete the gradient data.
+        del grad
+
+
+    def test_dchi2_element(self):
+        """Unit test for the chi-squared gradient created by the 
dchi2_element function.
+
+        The chi-squared gradient is [0, 10] for the following data
+
+            data =              |  1.0  1.5  2.0  2.5  3.0 |,
+
+            back_calc =         |  0.9  1.45 2.0  2.55 3.1 |,
+
+            back_calc_grad =    |  0.1  0.2  0.3  0.2  0.1 |
+                                | -0.2 -0.1  0.0  0.1  0.2 |,
+
+            errors =            |  0.1  0.1  0.1  0.1  0.1 |.
+        """
+
+        # Calculate the gradient elements.
+        grad0 = dchi2_element(self.data, self.back_calc, 
self.back_calc_grad[0], self.errors)
+        grad1 = dchi2_element(self.data, self.back_calc, 
self.back_calc_grad[1], self.errors)
 
         # Assert, to a precision of 13 decimal places, that the gradient is 
[0, 10].
         self.assertAlmostEqual(grad0, 0.0, places=13)
@@ -140,11 +167,51 @@
                       |  0.0  20.0 |.
         """
 
+        # Calculate the Hessian.
+        hess = zeros((2,2), float64)
+        d2chi2(hess, 2, self.data, self.back_calc, self.back_calc_grad, 
self.back_calc_hess, self.errors)
+
+        # Assert, to a precision of 13 decimal places, that the Hessian is 
[[38.0, 0], [0, 20]].
+        self.assertAlmostEqual(hess[0, 0], 38.0, places=13)
+        self.assertAlmostEqual(hess[0, 1], 0.0, places=13)
+        self.assertAlmostEqual(hess[1, 0], 0.0, places=13)
+        self.assertAlmostEqual(hess[1, 1], 20.0, places=13)
+
+        # Delete the Hessian data.
+        del hess
+
+
+    def test_d2chi2_element(self):
+        """Unit test for the chi-squared Hessian created by the 
d2chi2_element function.
+
+        For the data
+
+            data =              | 1.0    1.5    2.0    2.5    3.0   |,
+
+            back_calc =         | 0.9    1.45   2.0    2.55   3.1   |,
+
+            back_calc_grad =    | 0.1    0.2    0.3    0.2    0.1   |
+                                |-0.2   -0.1    0.0    0.1    0.2   |,
+
+            back_calc_hess[0] = | 0.01   0.005  0.0    0.005  0.01  |
+                                | 0.05   0.01   0.0    0.01   0.05  |,
+
+            back_calc_hess[1] = | 0.001  0.0005 0.0    0.0005 0.001 |
+                                | 0.005  0.001  0.0    0.001  0.005 |,
+
+            errors =            | 0.1    0.1    0.1    0.1    0.1   |,
+
+        the chi-squared hessian is
+
+            Hessian = | 38.0   0.0 |
+                      |  0.0  20.0 |.
+        """
+
         # Calculate the Hessian elements.
-        hess00 = d2chi2(self.data, self.back_calc, self.back_calc_grad[0], 
self.back_calc_grad[0], self.back_calc_hess[0, 0], self.errors)
-        hess01 = d2chi2(self.data, self.back_calc, self.back_calc_grad[0], 
self.back_calc_grad[1], self.back_calc_hess[0, 1], self.errors)
-        hess10 = d2chi2(self.data, self.back_calc, self.back_calc_grad[1], 
self.back_calc_grad[0], self.back_calc_hess[1, 0], self.errors)
-        hess11 = d2chi2(self.data, self.back_calc, self.back_calc_grad[1], 
self.back_calc_grad[1], self.back_calc_hess[1, 1], self.errors)
+        hess00 = d2chi2_element(self.data, self.back_calc, 
self.back_calc_grad[0], self.back_calc_grad[0], self.back_calc_hess[0, 0], 
self.errors)
+        hess01 = d2chi2_element(self.data, self.back_calc, 
self.back_calc_grad[0], self.back_calc_grad[1], self.back_calc_hess[0, 1], 
self.errors)
+        hess10 = d2chi2_element(self.data, self.back_calc, 
self.back_calc_grad[1], self.back_calc_grad[0], self.back_calc_hess[1, 0], 
self.errors)
+        hess11 = d2chi2_element(self.data, self.back_calc, 
self.back_calc_grad[1], self.back_calc_grad[1], self.back_calc_hess[1, 1], 
self.errors)
 
         # Assert, to a precision of 13 decimal places, that the Hessian is 
[[38.0, 0], [0, 20]].
         self.assertAlmostEqual(hess00, 38.0, places=13)




Related Messages


Powered by MHonArc, Updated Thu Jul 24 15:00:22 2008