mailr25276 - /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 26, 2014 - 12:10:
Author: bugman
Date: Tue Aug 26 12:10:46 2014
New Revision: 25276

URL: http://svn.gna.org/viewcvs/relax?rev=25276&view=rev
Log:
Created a unit test to check the dfunc() function of the relax_fit C module 
off the minimum.


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=25276&r1=25275&r2=25276&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 12:10:46 2014
@@ -34,12 +34,12 @@
         """Create a number of objects for the calculation and testing of the 
relaxation curve-fitting equations."""
 
         # The parameter scaling.
-        scaling_list = [1, 1000]
+        self.scaling_list = [1, 1000]
 
         # The parameter values at the minimum.
         self.I0 = 1000
         self.R = 1
-        self.params = [self.R/scaling_list[0], self.I0/scaling_list[1]]
+        self.params = [self.R/self.scaling_list[0], 
self.I0/self.scaling_list[1]]
 
         # The time points.
         relax_times = [0, 1, 2, 3, 4]
@@ -51,7 +51,7 @@
         errors = [10, 10, 10, 10, 10]
 
         # Setup the C module.
-        setup(num_params=2, num_times=len(relax_times), values=I, sd=errors, 
relax_times=relax_times, scaling_matrix=scaling_list)
+        setup(num_params=2, num_times=len(relax_times), values=I, sd=errors, 
relax_times=relax_times, scaling_matrix=self.scaling_list)
 
 
     def test_func(self):
@@ -76,3 +76,25 @@
         # Assert that the elements must be 0.0.
         self.assertAlmostEqual(grad[0], 0.0, 6)
         self.assertAlmostEqual(grad[1], 0.0, 6)
+
+
+    def test_dfunc_off_minimum(self):
+        """Unit test for the gradient returned by the dfunc() function at a 
position away from the minimum.
+
+        This uses the data from 
test_suite/shared_data/curve_fitting/numeric_gradient/integrate.log.
+        """
+
+        # The off-minimum parameter values.
+        I0 = 500
+        R = 2
+        params = [R/self.scaling_list[0], I0/self.scaling_list[1]]
+
+        # Get the chi-squared gradient.
+        grad = dfunc(params)
+
+        # Printout.
+        print("The gradient at %s is:\n%s" % (params, grad))
+
+        # Check that the gradient matches the numerically derived values.
+        self.assertAlmostEqual(grad[0], 722.67864120737488, 6)
+        self.assertAlmostEqual(grad[1], -11.564651301654292, 6)




Related Messages


Powered by MHonArc, Updated Tue Aug 26 12:20:02 2014