ERIS Pipeline Reference Manual 1.9.2
mpfit.h
1/*
2 * MINPACK-1 Least Squares Fitting Library
3 *
4 * Original public domain version by B. Garbow, K. Hillstrom, J. More'
5 * (Argonne National Laboratory, MINPACK project, March 1980)
6 *
7 * Tranlation to C Language by S. Moshier (moshier.net)
8 *
9 * Enhancements and packaging by C. Markwardt
10 * (comparable to IDL fitting routine MPFIT
11 * see http://cow.physics.wisc.edu/~craigm/idl/idl.html)
12 */
13
14/* Header file defining constants, data structures and functions of
15 mpfit library
16 $Id: mpfit.h,v 1.14 2010/11/13 08:15:07 craigm Exp $
17*/
18
19#ifndef MPFIT_H
20#define MPFIT_H
21
22/* This is a C library. Allow compilation with a C++ compiler */
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27/* MPFIT version string */
28#define MPFIT_VERSION "1.2"
29
30/* Definition of a parameter constraint structure */
31struct mp_par_struct {
32 int fixed; /* 1 = fixed; 0 = free */
33 int limited[2]; /* 1 = low/upper limit; 0 = no limit */
34 double limits[2]; /* lower/upper limit boundary value */
35
36 char *parname; /* Name of parameter, or 0 for none */
37 double step; /* Step size for finite difference */
38 double relstep; /* Relative step size for finite difference */
39 int side; /* Sidedness of finite difference derivative
40 0 - one-sided derivative computed automatically
41 1 - one-sided derivative (f(x+h) - f(x) )/h
42 -1 - one-sided derivative (f(x) - f(x-h))/h
43 2 - two-sided derivative (f(x+h) - f(x-h))/(2*h)
44 3 - user-computed analytical derivatives
45 */
46 int deriv_debug; /* Derivative debug mode: 1 = Yes; 0 = No;
47
48 If yes, compute both analytical and numerical
49 derivatives and print them to the console for
50 comparison.
51
52 NOTE: when debugging, do *not* set side = 3,
53 but rather to the kind of numerical derivative
54 you want to compare the user-analytical one to
55 (0, 1, -1, or 2).
56 */
57 double deriv_reltol; /* Relative tolerance for derivative debug
58 printout */
59 double deriv_abstol; /* Absolute tolerance for derivative debug
60 printout */
61};
62
63/* Just a placeholder - do not use!! */
64typedef void (*mp_iterproc)(void);
65
66/* Definition of MPFIT configuration structure */
67struct mp_config_struct {
68 /* NOTE: the user may set the value explicitly; OR, if the passed
69 value is zero, then the "Default" value will be substituted by
70 mpfit(). */
71 double ftol; /* Relative chi-square convergence criterium Default: 1e-10 */
72 double xtol; /* Relative parameter convergence criterium Default: 1e-10 */
73 double gtol; /* Orthogonality convergence criterium Default: 1e-10 */
74 double epsfcn; /* Finite derivative step size Default: MP_MACHEP0 */
75 double stepfactor; /* Initial step bound Default: 100.0 */
76 double covtol; /* Range tolerance for covariance calculation Default: 1e-14 */
77 int maxiter; /* Maximum number of iterations. If maxiter == 0,
78 then basic error checking is done, and parameter
79 errors/covariances are estimated based on input
80 parameter values, but no fitting iterations are done.
81 Default: 200
82 */
83 int maxfev; /* Maximum number of function evaluations, or 0 for no limit
84 Default: 0 (no limit) */
85 int nprint; /* Default: 1 */
86 int douserscale;/* Scale variables by user values?
87 1 = yes, user scale values in diag;
88 0 = no, variables scaled internally (Default) */
89 int nofinitecheck; /* Disable check for infinite quantities from user?
90 0 = do not perform check (Default)
91 1 = perform check
92 */
93 mp_iterproc iterproc; /* Placeholder pointer - must set to 0 */
94
95};
96
97/* Definition of results structure, for when fit completes */
98struct mp_result_struct {
99 double bestnorm; /* Final chi^2 */
100 double orignorm; /* Starting value of chi^2 */
101 int niter; /* Number of iterations */
102 int nfev; /* Number of function evaluations */
103 int status; /* Fitting status code */
104
105 int npar; /* Total number of parameters */
106 int nfree; /* Number of free parameters */
107 int npegged; /* Number of pegged parameters */
108 int nfunc; /* Number of residuals (= num. of data points) */
109
110 double *resid; /* Final residuals
111 nfunc-vector, or 0 if not desired */
112 double *xerror; /* Final parameter uncertainties (1-sigma)
113 npar-vector, or 0 if not desired */
114 double *covar; /* Final parameter covariance matrix
115 npar x npar array, or 0 if not desired */
116 char version[20]; /* MPFIT version string */
117};
118
119/* Convenience typedefs */
120typedef struct mp_par_struct mp_par;
121typedef struct mp_config_struct mp_config;
122typedef struct mp_result_struct mp_result;
123
124/* Enforce type of fitting function */
125typedef int (*mp_func)(int m, /* Number of functions (elts of fvec) */
126 int n, /* Number of variables (elts of x) */
127 double *x, /* I - Parameters */
128 double *fvec, /* O - function values */
129 double **dvec, /* O - function derivatives (optional)*/
130 void *private_data); /* I/O - function private data*/
131
132/* Error codes */
133#define MP_ERR_INPUT (0) /* General input parameter error */
134#define MP_ERR_NAN (-16) /* User function produced non-finite values */
135#define MP_ERR_FUNC (-17) /* No user function was supplied */
136#define MP_ERR_NPOINTS (-18) /* No user data points were supplied */
137#define MP_ERR_NFREE (-19) /* No free parameters */
138#define MP_ERR_MEMORY (-20) /* Memory allocation error */
139#define MP_ERR_INITBOUNDS (-21) /* Initial values inconsistent w constraints*/
140#define MP_ERR_BOUNDS (-22) /* Initial constraints inconsistent */
141#define MP_ERR_PARAM (-23) /* General input parameter error */
142#define MP_ERR_DOF (-24) /* Not enough degrees of freedom */
143
144/* Potential success status codes */
145#define MP_OK_CHI (1) /* Convergence in chi-square value */
146#define MP_OK_PAR (2) /* Convergence in parameter value */
147#define MP_OK_BOTH (3) /* Both MP_OK_PAR and MP_OK_CHI hold */
148#define MP_OK_DIR (4) /* Convergence in orthogonality */
149#define MP_MAXITER (5) /* Maximum number of iterations reached */
150#define MP_FTOL (6) /* ftol is too small; no further improvement*/
151#define MP_XTOL (7) /* xtol is too small; no further improvement*/
152#define MP_GTOL (8) /* gtol is too small; no further improvement*/
153
154/* Double precision numeric constants */
155#define MP_MACHEP0 2.2204460e-16
156#define MP_DWARF 2.2250739e-308
157#define MP_GIANT 1.7976931e+308
158
159#if 0
160/* Float precision */
161#define MP_MACHEP0 1.19209e-07
162#define MP_DWARF 1.17549e-38
163#define MP_GIANT 3.40282e+38
164#endif
165
166#define MP_RDWARF (sqrt(MP_DWARF*1.5)*10)
167#define MP_RGIANT (sqrt(MP_GIANT)*0.1)
168
169
170/* External function prototype declarations */
171extern int mpfit(mp_func funct, int m, int npar,
172 double *xall, mp_par *pars, mp_config *config,
173 void *private_data,
174 mp_result *result);
175
176
177
178/* C99 uses isfinite() instead of finite() */
179#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
180#define mpfinite(x) isfinite(x)
181
182/* Microsoft C uses _finite(x) instead of finite(x) */
183#elif defined(_MSC_VER) && _MSC_VER
184#include <float.h>
185#define mpfinite(x) _finite(x)
186
187/* Default is to assume that compiler/library has finite() function */
188#else
189#define mpfinite(x) finite(x)
190
191#endif
192
193#ifdef __cplusplus
194} /* extern "C" */
195#endif
196
197#endif /* MPFIT_H */
int nfev
Definition: sc_mpfit.c:51