Author: bugman
Date: Tue Aug 26 19:51:12 2014
New Revision: 25319

URL: http://svn.gna.org/viewcvs/relax?rev=25319&view=rev
Log:
Implemented two unit tests to check the Hessian of the 
target_functions.relax_fit.d2func() function.

This compares the calculated Hessian to the numerically integrated values from 
the
test_suite/shared_data/curve_fitting/numeric_gradient/Hessian.py script, 
showing that the d2func()
function is implemented correctly.


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=25319&r1=25318&r2=25319&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     Tue Aug 
26 19:51:12 2014
@@ -24,7 +24,7 @@
 from unittest import TestCase
 
 # relax module imports.
-from target_functions.relax_fit import setup, func, dfunc
+from target_functions.relax_fit import setup, func, dfunc, d2func
 
 
 class Test_relax_fit(TestCase):
@@ -98,3 +98,46 @@
         # Check that the gradient matches the numerically derived values.
         self.assertAlmostEqual(grad[0], 
456.36655522098829*self.scaling_list[0], 3)
         self.assertAlmostEqual(grad[1], 
-10.8613338920982*self.scaling_list[1], 3)
+
+
+    def test_d2func(self):
+        """Unit test for the Hessian returned by the d2func() function at the 
minimum.
+
+        This uses the data from 
test_suite/shared_data/curve_fitting/numeric_gradient/Hessian.log.
+        """
+
+        # Get the chi-squared Hessian.
+        hess = d2func(self.params)
+
+        # Printout.
+        print("The Hessian at the minimum is:\n%s" % hess)
+
+        # Check that the Hessian matches the numerically derived values.
+        self.assertAlmostEqual(hess[0][0],  
4.72548021e+03*self.scaling_list[0]**2, 3)
+        self.assertAlmostEqual(hess[0][1], 
-3.61489336e+00*self.scaling_list[0]*self.scaling_list[1], 3)
+        self.assertAlmostEqual(hess[1][0], 
-3.61489336e+00*self.scaling_list[0]*self.scaling_list[1], 3)
+        self.assertAlmostEqual(hess[1][1],  
2.31293027e-02*self.scaling_list[1]**2, 3)
+
+
+    def test_d2func_off_minimum(self):
+        """Unit test for the Hessian returned by the d2func() 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 chi-squared Hessian.
+        hess = d2func(params)
+
+        # Printout.
+        print("The Hessian at %s is:\n%s" % (params, hess))
+
+        # Check that the Hessian matches the numerically derived values.
+        self.assertAlmostEqual(hess[0][0], 
-4.11964848e+02*self.scaling_list[0]**2, 3)
+        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)


_______________________________________________
relax (http://www.nmr-relax.com)

This is the relax-commits mailing list
[email protected]

To unsubscribe from this list, get a password
reminder, or change your subscription options,
visit the list information page at
https://mail.gna.org/listinfo/relax-commits

Reply via email to