Main Page | Modules | Alphabetical List | Class List | Class Members

High-level functions for non-linear fitting


Functions

cpl_error_code cpl_fit_lvmq (const cpl_matrix *x, const cpl_matrix *sigma_x, const cpl_vector *y, const cpl_vector *sigma_y, cpl_vector *a, const int ia[], int(*f)(const double x[], const double a[], double *result), int(*dfda)(const double x[], const double a[], double result[]), double relative_tolerance, int tolerance_count, int max_iterations, double *mse, double *red_chisq, cpl_matrix **covariance)
 Fit a function to a set of data.

Detailed Description

This module provides a routine for non-linear fitting.

Synopsis:
   #include "cpl_fit.h"

Function Documentation

cpl_error_code cpl_fit_lvmq const cpl_matrix *  x,
const cpl_matrix *  sigma_x,
const cpl_vector *  y,
const cpl_vector *  sigma_y,
cpl_vector *  a,
const int  ia[],
int(*)(const double x[], const double a[], double *result)  f,
int(*)(const double x[], const double a[], double result[])  dfda,
double  relative_tolerance,
int  tolerance_count,
int  max_iterations,
double *  mse,
double *  red_chisq,
cpl_matrix **  covariance
 

Fit a function to a set of data.

Parameters:
x N x D matrix of the positions to fit. Each matrix row is a D-dimensional position.
sigma_x Uncertainty (one sigma, gaussian errors assumed) assosiated with x. Taking into account the uncertainty of the independent variable is currently unsupported, and this parameter must therefore be set to NULL.
y The N values to fit.
sigma_y Vector of size N containing the uncertainties of the y-values. If this parameter is NULL, constant uncertainties are assumed.
a Vector containing M fit parameters. Must contain a guess solution on input and contains the best fit parameters on output.
ia Array of size M defining which fit parameters participate in the fit (non-zero) and which fit parameters are held constant (zero). At least one element must be non-zero. Alternatively, pass NULL to fit all parameters.
f Function that evaluates the fit function at the position specified by the first argument (an array of size D) using the fit parameters specified by the second argument (an array of size M). The result must be output using the third parameter, and the function must return zero iff the evaluation succeded.
dfda Function that evaluates the first order partial derivatives of the fit function with respect to the fit parameters at the position specified by the first argument (an array of size D) using the parameters specified by the second argument (an array of size M). The result must be output using the third parameter (array of size M), and the function must return zero iff the evaluation succeded.
relative_tolerance The algorithm converges by definition if the relative decrease in chi squared is less than tolerance tolerance_count times in a row. Recommended default: CPL_FIT_LVMQ_TOLERANCE
tolerance_count The algorithm converges by definition if the relative decrease in chi squared is less than tolerance tolerance_count times in a row. Recommended default: CPL_FIT_LVMQ_COUNT
max_iterations If this number of iterations is reached without convergence, the algorithm diverges, by definition. Recommended default: CPL_FIT_LVMQ_MAXITER
mse If non-NULL, the mean squared error of the best fit is computed.
red_chisq If non-NULL, the reduced chi square of the best fit is computed. This requires sigma_y to be specified.
covariance If non-NULL, the formal covariance matrix of the best fit parameters is computed (or NULL on error). On success the diagonal terms of the covariance matrix are guaranteed to be positive. However, terms that involve a constant parameter (as defined by the input array ia) are always set to zero. Computation of the covariacne matrix requires sigma_y to be specified.
Returns:
CPL_ERROR_NONE iff OK.
This function makes a minimum chi squared fit of the specified function to the specified data set using a Levenberg-Marquardt algorithm.

Possible _cpl_error_code_ set in this function:

  • CPL_ERROR_NULL_INPUT if an input pointer other than sigma_x, sigma_y, mse, red_chisq or covariance is NULL.
  • CPL_ERROR_ILLEGAL_INPUT if an input matrix/vector is empty, if ia contains only zero values, if any of relative_tolerance, tolerance_count or max_iterations is non-positive, if N <= M and red_chisq is non-NULL, if any element of sigma_x or sigma_y is non-positive, or if evaluation of the fit function or its derivative failed.
  • CPL_ERROR_INCOMPATIBLE_INPUT if the dimensions of the input vectors/matrices do not match, or if chi square or covariance computation is requested and sigma_y is NULL.
  • CPL_ERROR_ILLEGAL_OUTPUT if memory allocation failed.
  • CPL_ERROR_CONTINUE if the Levenberg-Marquardt algorithm failed to converge.
  • CPL_ERROR_SINGULAR_MATRIX if the covariance matrix could not be computed.


Generated on Sat Mar 24 01:33:21 2007 for Common Pipeline Library Reference Manual by  doxygen 1.3.9.1