mailr25452 - /trunk/test_suite/unit_tests/_target_functions/test_relax_fit.py


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

Header


Content

Posted by edward on August 29, 2014 - 18:37:
Author: bugman
Date: Fri Aug 29 18:37:55 2014
New Revision: 25452

URL: http://svn.gna.org/viewcvs/relax?rev=25452&view=rev
Log:
Created two unit tests showing the target_functions.relax_fit.jacobian_chi2() 
function is correct.

This compares the calculated chi-squared Jacobian to the numerically 
integrated values from the
test_suite/shared_data/curve_fitting/numeric_topology/jacobian_chi2.py script.


Modified:
    trunk/test_suite/unit_tests/_target_functions/test_relax_fit.py

Modified: trunk/test_suite/unit_tests/_target_functions/test_relax_fit.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/test_suite/unit_tests/_target_functions/test_relax_fit.py?rev=25452&r1=25451&r2=25452&view=diff
==============================================================================
--- trunk/test_suite/unit_tests/_target_functions/test_relax_fit.py     
(original)
+++ trunk/test_suite/unit_tests/_target_functions/test_relax_fit.py     Fri 
Aug 29 18:37:55 2014
@@ -24,7 +24,7 @@
 from unittest import TestCase
 
 # relax module imports.
-from target_functions.relax_fit import setup, func, dfunc, d2func, jacobian
+from target_functions.relax_fit import setup, func, dfunc, d2func, jacobian, 
jacobian_chi2
 
 
 class Test_relax_fit(TestCase):
@@ -173,6 +173,71 @@
                 self.assertAlmostEqual(matrix[i, j], real[i, j], 3)
 
 
+    def test_jacobian_chi2(self):
+        """Unit test for the Jacobian returned by the jacobian_chi2() 
function at the minimum.
+
+        This uses the data from 
test_suite/shared_data/curve_fitting/numeric_gradient/jacobian_chi2.log.
+        """
+
+        # Get the exponential curve Jacobian.
+        matrix = jacobian_chi2(self.params)
+
+        # The real Jacobian.
+        real = [[  0.00000000e+00,   0.00000000e+00],
+                [ -3.25440806e-09,   3.25446070e-12],
+                [  2.09660266e-09,  -1.04831421e-12],
+                [  1.07707223e-10,  -3.58994022e-14],
+                [ -5.00778448e-11,   1.25201612e-14]]
+
+        # Numpy conversion.
+        matrix = array(matrix)
+        real = transpose(array(real))
+
+        # Printouts.
+        print("The chi-squared Jacobian at the minimum is:\n%s" % matrix)
+        print("The real chi-squared Jacobian at the minimum is:\n%s" % real)
+
+        # Check that the Jacobian matches the numerically derived values.
+        for i in range(len(matrix)):
+            for j in range(len(matrix[i])):
+                self.assertAlmostEqual(matrix[i, j], real[i, j], 3)
+
+
+    def test_jacobian_chi2_off_minimum(self):
+        """Unit test for the Jacobian returned by the jacobian_chi2() 
function at a position away from the minimum.
+
+        This uses the data from 
test_suite/shared_data/curve_fitting/numeric_gradient/jacobian_chi2.log.
+        """
+
+        # The off-minimum parameter values.
+        I0 = 500.0
+        R = 2.0
+        params = [R/self.scaling_list[0], I0/self.scaling_list[1]]
+
+        # Get the exponential curve Jacobian.
+        matrix = jacobian_chi2(params)
+
+        # The real Jacobian.
+        real = [[  0.00000000e+00,  -1.00000000e+01],
+                [  4.06292489e+02,  -8.12584978e-01],
+                [  4.62204173e+01,  -4.62204173e-02],
+                [  3.61013094e+00,  -2.40675396e-03],
+                [  2.43517791e-01,  -1.21758895e-04]]
+
+        # Numpy conversion.
+        matrix = array(matrix)
+        real = transpose(array(real))
+
+        # Printout.
+        print("The chi-squared Jacobian at %s is:\n%s" % (params, matrix))
+        print("The real chi-squared Jacobian at the minimum is:\n%s" % real)
+
+        # Check that the Jacobian matches the numerically derived values.
+        for i in range(len(matrix)):
+            for j in range(len(matrix[i])):
+                self.assertAlmostEqual(matrix[i, j], real[i, j], 3)
+
+
     def test_jacobian_off_minimum(self):
         """Unit test for the Jacobian returned by the jacobian() function at 
a position away from the minimum.
 




Related Messages


Powered by MHonArc, Updated Fri Aug 29 20:20:02 2014