mailr25446 - /trunk/test_suite/shared_data/curve_fitting/numeric_gradient/jacobian.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:05:
Author: bugman
Date: Fri Aug 29 18:05:20 2014
New Revision: 25446

URL: http://svn.gna.org/viewcvs/relax?rev=25446&view=rev
Log:
Added a script and log file for calculating the numerical Jacobian for an 
exponential curve.

This uses the data at 
http://thread.gmane.org/gmane.science.nmr.relax.devel/6807/focus=6840 and
calculates the Jacobian using the numdifftools.Jacobian object construct and 
obtain the matrix, both
at the minimum and at a point away from the minimum.  The values will be used 
to construct a unit
test to check the C module implementation.


Added:
    trunk/test_suite/shared_data/curve_fitting/numeric_gradient/jacobian.py
      - copied, changed from r25445, 
trunk/test_suite/shared_data/curve_fitting/numeric_gradient/Hessian.py

Copied: 
trunk/test_suite/shared_data/curve_fitting/numeric_gradient/jacobian.py (from 
r25445, 
trunk/test_suite/shared_data/curve_fitting/numeric_gradient/Hessian.py)
URL: 
http://svn.gna.org/viewcvs/relax/trunk/test_suite/shared_data/curve_fitting/numeric_gradient/jacobian.py?p2=trunk/test_suite/shared_data/curve_fitting/numeric_gradient/jacobian.py&p1=trunk/test_suite/shared_data/curve_fitting/numeric_gradient/Hessian.py&r1=25445&r2=25446&rev=25446&view=diff
==============================================================================
--- trunk/test_suite/shared_data/curve_fitting/numeric_gradient/Hessian.py    
  (original)
+++ trunk/test_suite/shared_data/curve_fitting/numeric_gradient/jacobian.py   
  Fri Aug 29 18:05:20 2014
@@ -3,11 +3,11 @@
 # Python module imports.
 from math import exp
 from numpy import array, float64
-from numdifftools import Hessian
+from numdifftools import Jacobian
 
 
 def func(params):
-    """Calculate the chi-squared value."""
+    """Back-calculate the intensities."""
 
     global times, I, errors
 
@@ -19,13 +19,8 @@
     for i in range(len(times)):
         back_calc.append(I0 * exp(-R*times[i]))
 
-    # The chi2.
-    chi2 = 0.0
-    for i in range(len(times)):
-        chi2 += (I[i] - back_calc[i])**2 / errors[i]**2
-
-    # Return the value.
-    return chi2
+    # Return the back-calculated intensities.
+    return array(back_calc)
 
 
 # The real parameters.
@@ -41,17 +36,17 @@
 # The intensity errors.
 errors = [10.0, 10.0, 10.0, 10.0, 10.0]
 
-# Set up the Hessian function.
-d2func = Hessian(func)
+# Set up the Jacobian function.
+jacobian = Jacobian(func)
 
-# The numeric Hessian at the minimum.
+# The numeric Jacobian at the minimum.
 print("\n\nOn-minimum:\n")
-hess = d2func([R, I0])
-print("The Hessian at %s is:\n%s" % ([R, I0], hess))
+matrix = jacobian([R, I0])
+print("The Jacobian at %s is:\n%s" % ([R, I0], matrix))
 
-# The numeric Hessian off the minimum.
+# The numeric Jacobian off the minimum.
 print("\n\nOff-minimum:\n")
 R = 2.0
 I0 = 500.0
-hess = d2func([R, I0])
-print("The Hessian at %s is:\n%s" % ([R, I0], hess))
+matrix = jacobian([R, I0])
+print("The Jacobian at %s is:\n%s" % ([R, I0], matrix))




Related Messages


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