mailr25448 - /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:18:
Author: bugman
Date: Fri Aug 29 18:18:40 2014
New Revision: 25448

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

This compares the calculated Jacobian to the numerically integrated values 
from the
test_suite/shared_data/curve_fitting/numeric_gradient/jacobian.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=25448&r1=25447&r2=25448&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:18:40 2014
@@ -20,11 +20,11 @@
 
###############################################################################
 
 # Python module imports.
-from numpy import array, float64, zeros
+from numpy import array, float64, transpose, zeros
 from unittest import TestCase
 
 # relax module imports.
-from target_functions.relax_fit import setup, func, dfunc, d2func
+from target_functions.relax_fit import setup, func, dfunc, d2func, jacobian
 
 
 class Test_relax_fit(TestCase):
@@ -141,3 +141,68 @@
         self.assertAlmostEqual(hess[0][1],  
7.22678641e-01*self.scaling_list[0]*self.scaling_list[1], 3)
         self.assertAlmostEqual(hess[1][0],  
7.22678641e-01*self.scaling_list[0]*self.scaling_list[1], 3)
         self.assertAlmostEqual(hess[1][1],  
2.03731472e-02*self.scaling_list[1]**2, 3)
+
+
+    def test_jacobian(self):
+        """Unit test for the Jacobian returned by the jacobian() function at 
the minimum.
+
+        This uses the data from 
test_suite/shared_data/curve_fitting/numeric_gradient/Hessian.log.
+        """
+
+        # Get the exponential curve Jacobian.
+        matrix = jacobian(self.params)
+
+        # The real Jacobian.
+        real = [[  0.00000000e+00,   1.00000000e+00],
+                [ -3.67879441e+02,   3.67879441e-01],
+                [ -2.70670566e+02,   1.35335283e-01],
+                [ -1.49361205e+02,   4.97870684e-02],
+                [ -7.32625556e+01,   1.83156389e-02]]
+
+        # Numpy conversion.
+        matrix = array(matrix)
+        real = transpose(array(real))
+
+        # Printouts.
+        print("The Jacobian at the minimum is:\n%s" % matrix)
+        print("The real 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.
+
+        This uses the data from 
test_suite/shared_data/curve_fitting/numeric_gradient/Hessian.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(params)
+
+        # The real Jacobian.
+        real = [[  0.00000000e+00,   1.00000000e+00],
+                [ -6.76676416e+01,   1.35335283e-01],
+                [ -1.83156389e+01,   1.83156389e-02],
+                [ -3.71812826e+00,   2.47875218e-03],
+                [ -6.70925256e-01,   3.35462628e-04]]
+
+        # Numpy conversion.
+        matrix = array(matrix)
+        real = transpose(array(real))
+
+        # Printout.
+        print("The Jacobian at %s is:\n%s" % (params, matrix))
+        print("The real 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)




Related Messages


Powered by MHonArc, Updated Fri Aug 29 18:40:03 2014