Author: bugman Date: Tue Aug 26 19:04:09 2014 New Revision: 25312 URL: http://svn.gna.org/viewcvs/relax?rev=25312&view=rev Log: Partly implemented the front end target_functions.relax_fit.d2func() C module Python function. This is not fully implemented as the exponential curve double partial derivatives are not implemented. 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=25312&r1=25311&r2=25312&view=diff ============================================================================== --- trunk/target_functions/relax_fit.c (original) +++ trunk/target_functions/relax_fit.c Tue Aug 26 19:04:09 2014 @@ -166,10 +166,50 @@ d2func(PyObject *self, PyObject *args) { /* Target function for calculating and returning the chi-squared Hessian. * - * This is currently unimplemented. */ - return PyFloat_FromDouble(0.0); + /* Declarations. */ + PyObject *params_arg; + int j, k; + + /* Parse the function arguments, the only argument should be the parameter array. */ + if (!PyArg_ParseTuple(args, "O", ¶ms_arg)) + return NULL; + + /* Convert the parameters Python list to a C array. */ + param_to_c(params_arg); + + /* Back calculated the peak intensities. */ + exponential(params[index_I0], params[index_R], relax_times, back_calc, num_times); + + /* The partial derivatives. */ + exponential_dR(params[index_I0], params[index_R], index_R, relax_times, back_calc_grad, num_times); + exponential_dI0(params[index_I0], params[index_R], index_I0, relax_times, back_calc_grad, num_times); + + /* The second partial derivatives. */ + /* + exponential_dR2(params[index_I0], params[index_R], index_R, relax_times, back_calc_hess, num_times); + exponential_dI02(params[index_I0], params[index_R], index_I0, relax_times, back_calc_hess, num_times); + exponential_dR2_dI02(params[index_I0], params[index_R], index_R, index_I0, relax_times, back_calc_hess, num_times); + */ + + /* The chi-squared Hessian. */ + d2chi2(d2chi2_vals, values, back_calc, back_calc_grad, back_calc_hess, sd, num_times, num_params); + + /* Convert to a Python list, and scale the values. */ + PyObject *list = PyList_New(0); + Py_INCREF(list); + for (j = 0; j < num_params; j++) { + PyObject *list2 = PyList_New(0); + Py_INCREF(list2); + for (k = 0; k < num_params; k++) { + PyList_Append(list2, PyFloat_FromDouble(d2chi2_vals[j][k] * scaling_matrix[j] * scaling_matrix[k])); + } + PyList_Append(list, list2); + } + + /* Return the Hessian. */ + return list; } @@ -247,7 +287,7 @@ "d2func", d2func, METH_VARARGS, - "Target function for calculating and returning the chi-squared Hessian.\n\nThis is currently unimplemented." + "Target function for calculating and returning the chi-squared Hessian." }, { "back_calc_I", back_calc_I, Modified: trunk/target_functions/relax_fit.h URL: http://svn.gna.org/viewcvs/relax/trunk/target_functions/relax_fit.h?rev=25312&r1=25311&r2=25312&view=diff ============================================================================== --- trunk/target_functions/relax_fit.h (original) +++ trunk/target_functions/relax_fit.h Tue Aug 26 19:04:09 2014 @@ -41,7 +41,9 @@ /* Variables used for storage during the function calls of optimisation. */ static double back_calc[MAX_DATA]; static double back_calc_grad[MAX_PARAMS][MAX_DATA]; +static double back_calc_hess[MAX_PARAMS][MAX_PARAMS][MAX_DATA]; static double dchi2_vals[MAX_PARAMS]; +static double d2chi2_vals[MAX_PARAMS][MAX_PARAMS]; static double params[MAX_PARAMS]; static double values[MAX_DATA]; static double sd[MAX_DATA];