Author: bugman
Date: Tue Aug 26 09:00:14 2014
New Revision: 25260
URL: http://svn.gna.org/viewcvs/relax?rev=25260&view=rev
Log:
Implemented the target_functions.relax_fit.dfunc() gradient function.
This is using the Python/C interface to provide a Python function for
calculating and returned the
chi-squared gradient for the exponential curves.
Modified:
trunk/target_functions/relax_fit.c
trunk/target_functions/relax_fit.h
Modified: trunk/target_functions/relax_fit.c
URL:
http://svn.gna.org/viewcvs/relax/trunk/target_functions/relax_fit.c?rev=25260&r1=25259&r2=25260&view=diff
==============================================================================
--- trunk/target_functions/relax_fit.c (original)
+++ trunk/target_functions/relax_fit.c Tue Aug 26 09:00:14 2014
@@ -123,19 +123,45 @@
/* Declarations */
PyObject *params_arg;
-
- /* Temp Declarations */
- double aaa[MAXPARAMS] = {1.0, 2.0};
+ PyObject *element;
int i;
- double *params;
/* Parse the function arguments, the only argument should be the parameter
array */
if (!PyArg_ParseTuple(args, "O", ¶ms_arg))
return NULL;
+ /* Place the parameter array elements into the C array */
+ for (i = 0; i < num_params; i++) {
+ /* Get the element */
+ element = PySequence_GetItem(params_arg, i);
+
+ /* Convert to a C double, then free the memory. */
+ params[i] = PyFloat_AsDouble(element);
+ Py_CLEAR(element);
+
+ /* Scale the parameter */
+ params[i] = params[i] * scaling_matrix[i];
+ }
+
/* Back calculated the peak intensities */
exponential(params, relax_times, back_calc, num_times);
+ /* The partial derivates */
+ exponential_dR(params, relax_times, back_calc_grad, num_times);
+ exponential_dI(params, relax_times, back_calc_grad, num_times);
+
+ /* The chi-squared gradient */
+ dchi2(dchi2_vals, values, back_calc, back_calc_grad, sd, num_times,
num_params);
+
+ /* Convert to a Python list */
+ PyObject *list = PyList_New(0);
+ Py_INCREF(list);
+ for (i = 0; i < num_params; i++) {
+ PyList_Append(list, PyFloat_FromDouble(dchi2_vals[i]));
+ }
+
+ /* Return the Jacobian */
+ return list;
return NULL;
}
Modified: trunk/target_functions/relax_fit.h
URL:
http://svn.gna.org/viewcvs/relax/trunk/target_functions/relax_fit.h?rev=25260&r1=25259&r2=25260&view=diff
==============================================================================
--- trunk/target_functions/relax_fit.h (original)
+++ trunk/target_functions/relax_fit.h Tue Aug 26 09:00:14 2014
@@ -40,6 +40,7 @@
/* Variables used for storage during the function calls of optimisation */
static double back_calc[MAXTIMES];
static double back_calc_grad[MAXPARAMS][MAXTIMES];
+static double dchi2_vals[MAXPARAMS];
static double params[MAXPARAMS];
static double values[MAXTIMES];
static double sd[MAXTIMES];
_______________________________________________
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