UltraScan III
us_lm.h
Go to the documentation of this file.
1 /*
2  * Project: LevenbergMarquardtLeastSquaresFitting
3  *
4  * File: lmcurve.h
5  *
6  * Contents: Simplified interface for one-dimensional curve fitting
7  *
8  * Author: Joachim Wuttke 2010
9  *
10  * Homepage: joachimwuttke.de/lmfit
11  */
12 
13 #ifndef US_LM_H
14 #define US_LM_H
15 
16 #include "us_extern.h"
17 #include "us_math2.h"
18 #include <math.h>
19 #include <float.h>
20 
21 #define LM_USRTOL 30*DBL_EPSILON
22 
28 {
29  public:
30 
33  {
34  public:
35  double ftol;
36  double xtol;
37  double gtol;
38  double epsilon;
39  double stepbound;
40  int maxcall;
41  int scale_diag;
42  int printflags;
43 
45  LM_Control( double = LM_USRTOL, double = LM_USRTOL,
46  double = LM_USRTOL, double = LM_USRTOL,
47  double = 100.0, int = 100, int = 1, int = 0 );
48  };
49 
52  {
53  public:
54  double fnorm;
55  int nfev;
56  int info;
57 
59  LM_Status( double = 0.0, int = 0, int = 0 );
60  };
61 
64  {
65  public:
66  double* t;
67  double* y;
68  double (*f)( double , double* );
69 
71  LM_CurveData( double*, double*,
72  double(*)( double, double* ) );
73  };
74 
78 
80  static QString lm_statmsg( LM_Status*, bool = false );
81 
83  static void lm_printout_std( int n_par, double *par, int m_dat,
84  const void *data, const double *fvec,
85  int printflags, int iflag, int iter,
86  int nfev );
87 
89  static double lm_rmsdnorm( int, const double * );
90 
92  static double lm_enorm( int, const double * );
93 
95  static void lmmin( int n_par, double *par, int m_dat, const void *data,
96  void (*evaluate) (double *par, int m_dat,
97  const void *data, double *fvec, int *info ),
98  const LM_Control* control, LM_Status* status,
99  void (*printout) (int n_par, double *par,
100  int m_dat, const void *data, const double *fvec,
101  int printflags, int iflag, int iter, int nfev ) );
102 
103 
106  static void lm_lmdif( int m, int n, double *x, double *fvec, double ftol,
109  double xtol, double gtol, int maxfev, double epsfcn,
110  double *diag, int mode, double factor, int *info,
111  int *nfev, double *fjac, int *ipvt, double *qtf,
112  double *wa1, double *wa2, double *wa3, double *wa4,
113  void (*evaluate) ( double *par, int m_dat,
114  const void *data, double *fvec, int *info ),
115  void (*printout) ( int n_par, double *par,
116  int m_dat, const void *data, const double *fvec,
117  int printflags, int iflag, int iter, int nfev ),
118  int printflags, const void *data );
119 
120 // extern const char *lm_infmsg[];
121 // extern const char *lm_shortmsg[];
122 
123 
125  static void lmcurve_evaluate( double *par, int m_dat,
126  const void *data,
127  double *fvec, int * /* info */ );
128 
130  static void lmcurve_fit( int n_par, double *par, int m_dat,
131  const double *t, const double *y,
132  double (*f)( double t, double *par ),
133  const LM_Control* control, LM_Status* status );
134 
136  static void lmcurve_fit_rmsd( int n_par, double *par, int m_dat,
137  const double *t, const double *y,
138  double (*f)( double t, double *par ),
139  const LM_Control* control,
140  LM_Status* status );
141 
142  //*************************************************************************/
143  // lm_lmdif (low-level, modified legacy interface for full control)
144  //*************************************************************************/
145 
146  static void lm_lmpar( int n, double *r, int ldr, int *ipvt, double *diag,
147  double *qtb, double delta, double *par, double *x,
148  double *sdiag, double *aux, double *xdi );
149  static void lm_qrfac( int m, int n, double *a, int pivot, int *ipvt,
150  double *rdiag, double *acnorm, double *wa );
151  static void lm_qrsolv( int n, double *r, int ldr, int *ipvt, double *diag,
152  double *qtb, double *x, double *sdiag, double *wa );
153 // extern unsigned int exponential_terms;
154 // extern double minusoneoverfourpisq;
155 // double compute_exponential_f( double t, const double *par );
156 
157 }; // Class US_LM
158 
159 #endif /* US_LM_H */