OPERA
1.0
Open source echelle spectrograph reduction pipeline
|
00001 #ifndef OPERALMFIT_H 00002 #define OPERALMFIT_H 00003 00004 /******************************************************************* 00005 **** LIBRARY FOR OPERA v1.0 **** 00006 ******************************************************************* 00007 Library name: operaLMFit 00008 Version: 1.0 00009 Description: This C library implements least-squares minimization and 00010 curve fitting using the Levenberg-Marquardt method. This 00011 library has been based and adapted from the LMFIT-v3.2 00012 library by Joachim Wuttke. 00013 Author(s): CFHT OPERA team 00014 Affiliation: Canada France Hawaii Telescope 00015 Location: Hawaii USA 00016 Date: Aug/2011 00017 Contact: eder@cfht.hawaii.edu 00018 00019 Copyright (C) 2011 Opera Pipeline team, Canada France Hawaii Telescope 00020 00021 This program is free software: you can redistribute it and/or modify 00022 it under the terms of the GNU General Public License as published by 00023 the Free Software Foundation, either version 3 of the License, or 00024 (at your option) any later version. 00025 00026 This program is distributed in the hope that it will be useful, 00027 but WITHOUT ANY WARRANTY; without even the implied warranty of 00028 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00029 GNU General Public License for more details. 00030 00031 You should have received a copy of the GNU General Public License 00032 along with this program. If not, see: 00033 http://software.cfht.hawaii.edu/licenses 00034 -or- 00035 http://www.gnu.org/licenses/gpl-3.0.html 00036 ********************************************************************/ 00037 00038 // $Date$ 00039 // $Id$ 00040 // $Revision$ 00041 // $Locker$ 00042 // $Log$ 00043 00044 /* 00045 * Project: LevenbergMarquardtLeastSquaresFitting 00046 * 00047 * File: lmmin.h 00048 * 00049 * Contents: Public interface to the Levenberg-Marquardt core implementation. 00050 * 00051 * Author: Joachim Wuttke 2004-2010 00052 * 00053 * Homepage: www.messen-und-deuten.de/lmfit 00054 */ 00055 00056 #ifdef __cplusplus 00057 extern "C" { 00058 #endif 00059 00062 /* Collection of control (input) parameters. */ 00063 typedef struct { 00064 double ftol; /* relative error desired in the sum of squares. */ 00065 double xtol; /* relative error between last two approximations. */ 00066 double gtol; /* orthogonality desired between fvec and its derivs. */ 00067 double epsilon; /* step used to calculate the jacobian. */ 00068 double stepbound; /* initial bound to steps in the outer loop. */ 00069 int maxcall; /* maximum number of iterations. */ 00070 int scale_diag; /* UNDOCUMENTED, TESTWISE automatical diag rescaling? */ 00071 int printflags; /* OR'ed to produce more noise */ 00072 } lm_control_struct; 00073 00074 /* Collection of status (output) parameters. */ 00075 typedef struct { 00076 double fnorm; /* norm of the residue vector fvec. */ 00077 int nfev; /* actual number of iterations. */ 00078 int info; /* status of minimization. */ 00079 } lm_status_struct; 00080 00081 /* Recommended control parameter settings. */ 00082 extern const lm_control_struct lm_control_double; 00083 extern const lm_control_struct lm_control_float; 00084 00085 /* Standard monitoring routine. */ 00086 void lm_printout_std( int n_par, const double *par, int m_dat, 00087 const void *data, const double *fvec, 00088 int printflags, int iflag, int iter, int nfev); 00089 00090 /* Refined calculation of Eucledian norm, typically used in printout routine. */ 00091 double lm_enorm( int, const double * ); 00092 00093 /* The actual minimization. */ 00094 void lmmin( int n_par, double *par, int m_dat, const void *data, 00095 void (*evaluate) (int n_par, const double *par, int m_dat, const void *data, 00096 double *fvec, int *info), 00097 const lm_control_struct *control, lm_status_struct *status, 00098 void (*printout) (int n_par, const double *par, int m_dat, 00099 const void *data, const double *fvec, 00100 int printflags, int iflag, int iter, int nfev) ); 00101 00102 00105 /* Alternative to lm_minimize, allowing full control, and read-out 00106 of auxiliary arrays. For usage, see implementation of lm_minimize. */ 00107 void lm_lmdif( int m, int n, double *x, double *fvec, double ftol, 00108 double xtol, double gtol, int maxfev, double epsfcn, 00109 double *diag, int mode, double factor, int *info, int *nfev, 00110 double *fjac, int *ipvt, double *qtf, double *wa1, 00111 double *wa2, double *wa3, double *wa4, 00112 void (*evaluate) (int n_par, const double *par, int m_dat, const void *data, 00113 double *fvec, int *info), 00114 void (*printout) (int n_par, const double *par, int m_dat, 00115 const void *data, const double *fvec, 00116 int printflags, int iflag, int iter, int nfev), 00117 int printflags, const void *data ); 00118 00119 extern const char *lm_infmsg[]; 00120 extern const char *lm_shortmsg[]; 00121 00122 00123 #ifdef __cplusplus 00124 } 00125 #endif 00126 00127 /* 00128 * Project: LevenbergMarquardtLeastSquaresFitting 00129 * 00130 * File: lmcurve.c 00131 * 00132 * Contents: Simplified wrapper for one-dimensional curve fitting, 00133 * using Levenberg-Marquardt least-squares minimization. 00134 * 00135 * Usage: see application sample demo/curve1.c 00136 * 00137 * Author: Joachim Wuttke 2010 00138 * 00139 * Homepage: www.messen-und-deuten.de/lmfit 00140 */ 00141 00142 typedef struct { 00143 const double *x; 00144 const double *y; 00145 double (*function) (double x, const double *par, int n_par); 00146 } lmcurve_data_struct; 00147 00148 void lmcurve_evaluate( int n_par, const double *par, int m_dat, const void *data, 00149 double *fvec, int *info ); 00150 00151 void lmcurve_fit( int n_par, double *par, int m_dat, 00152 const double *x, const double *y, 00153 double (*function)( double x, const double *par, int n_par), 00154 lm_control_struct *control, lm_status_struct *status ); 00155 00156 #endif /* OPERALMFIT_H */