Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
lmmin.cc
Go to the documentation of this file.
1 // Project: LevenbergMarquardtLeastSquaresFitting
2 //
3 // File: lmmin.c
4 //
5 // Contents: Levenberg-Marquardt core implementation,
6 // and simplified user interface.
7 // Author: Joachim Wuttke <j.wuttke@fz-juelich.de>
8 //
9 // Homepage: www.messen-und-deuten.de/lmfit
10 
11 
12 // lmfit is released under the LMFIT-BEER-WARE licence:
13 //
14 // In writing this software, I borrowed heavily from the public domain,
15 // especially from work by Burton S. Garbow, Kenneth E. Hillstrom,
16 // Jorge J. MorĂ©, Steve Moshier, and the authors of lapack. To avoid
17 // unneccessary complications, I put my additions and amendments also
18 // into the public domain. Please retain this notice. Otherwise feel
19 // free to do whatever you want with this stuff. If we meet some day,
20 // and you think this work is worth it, you can buy me a beer in return.
21 //
22 
23 
24 #include <stdlib.h>
25 #include <stdio.h>
26 #include <math.h>
27 #include <float.h>
28 #include <new>
29 #include <numeric/nls/lmmin.hh>
30 
31 namespace numeric {
32 namespace nls {
33 
34 // set numeric constants
35 #define LM_MACHEP 1.2e-16
36 #define LM_DWARF 1.0e-38
37 #define LM_SQRT_DWARF 3.834e-20
38 #define LM_SQRT_GIANT 1.304e19
39 #define LM_USERTOL 1.e-14
40 
41 // lm_printout_std (default monitoring routine)
42 
43 void lm_printout_std( int n_par, const double *par, int m_dat,
44  const void */*data*/, const double *fvec,
45  int printflags, int iflag, int iter, int nfev)
46 //
47 // data : for soft control of printout behaviour, add control
48 // variables to the data struct
49 // iflag : 0 (init) 1 (outer loop) 2(inner loop) -1(terminated)
50 // iter : outer loop counter
51 // nfev : number of calls to *evaluate
52 //
53 {
54  if ( !printflags ) {
55  return;
56  }
57 
58  int i;
59 
60  if ( printflags & 1 ) {
61  // location of printout call within lmdif
62  if ( iflag == 2 ) {
63  printf("trying step in gradient direction ");
64  } else if ( iflag == 1 ) {
65  printf("determining gradient (iteration %2d)", iter);
66  } else if ( iflag == 0 ) {
67  printf("starting minimization ");
68  } else if ( iflag == -1 ) {
69  printf("terminated after %3d evaluations ", nfev);
70  }
71  }
72 
73  if ( printflags & 2 ) {
74  printf(" par: ");
75  for ( i = 0; i < n_par; ++i ) {
76  printf(" %18.11g", par[i]);
77  }
78  printf(" => norm: %18.11g", lm_enorm(m_dat, fvec));
79  }
80 
81  if ( printflags & 3 ) {
82  printf( "\n" );
83  }
84 
85  if ( (printflags & 8) || ((printflags & 4) && iflag == -1) ) {
86  printf(" residuals:\n");
87  for ( i = 0; i < m_dat; ++i ) {
88  printf(" fvec[%2d]=%12g\n", i, fvec[i] );
89  }
90  }
91 }
92 
93 
94 // lm_minimize (intermediate-level interface)
95 
96 void lmmin( int n_par, double *par, int m_dat, const void *data,
97  void (*evaluate) (const double *par, int m_dat, const void *data,
98  double *fvec, int *info),
100  void (*printout) (int n_par, const double *par, int m_dat,
101  const void *data, const double *fvec,
102  int printflags, int iflag, int iter, int nfev) )
103 {
104  const lm_control_struct lm_control_double = {
105  LM_USERTOL, LM_USERTOL, LM_USERTOL, LM_USERTOL, 100., 100, 1, 0 };
106  const lm_control_struct *control = &lm_control_double;
107 
108  // allocate work space.
109 
110  double *fvec, *diag, *fjac, *qtf, *wa1, *wa2, *wa3, *wa4;
111  int *ipvt;
112 
113  int n = n_par;
114  int m = m_dat;
115 
116  try {
117  fvec = new double[m];
118  diag = new double[n];
119  qtf = new double[n];
120  fjac = new double[n*m];
121  wa1 = new double[n];
122  wa2 = new double[n];
123  wa3 = new double[n];
124  wa4 = new double[m];
125  ipvt = new int[n];
126  }
127 catch (const std::bad_alloc &) {
128  status->info=9;
129  return;
130 }
131 
132  if ( ! control->scale_diag ) {
133  for ( int j=0; j<n_par; ++j ) {
134  diag[j] = 1;
135  }
136  }
137 
138  //perform fit.
139  status->info = 0;
140 
141  // this goes through the modified legacy interface:
142  lm_lmdif( m, n, par, fvec, control->ftol, control->xtol, control->gtol,
143  control->maxcall * (n + 1), control->epsilon, diag,
144  ( control->scale_diag ? 1 : 2 ),
145  control->stepbound, &(status->info),
146  &(status->nfev), fjac, ipvt, qtf, wa1, wa2, wa3, wa4,
147  evaluate, printout, control->printflags, data );
148 
149  if ( printout ) {
150  (*printout)( n, par, m, data, fvec,
151  control->printflags, -1, 0, status->nfev );
152  }
153  status->fnorm = lm_enorm(m, fvec);
154  if ( status->info < 0 ) {
155  status->info = 11;
156  }
157 
158  // clean up.
159  delete [] fvec;
160  delete [] diag;
161  delete [] qtf;
162  delete [] fjac;
163  delete [] wa1;
164  delete [] wa2;
165  delete [] wa3;
166  delete [] wa4;
167  delete [] ipvt;
168 
169 } // lm_minimize.
170 
171 
172 // lm_lmdif (low-level, modified legacy interface for full control)
173 
174 void lm_lmpar( int n, double *r, int ldr, int *ipvt, double *diag,
175  double *qtb, double delta, double *par, double *x,
176  double *sdiag, double *aux, double *xdi );
177 void lm_qrfac( int m, int n, double *a, int pivot, int *ipvt,
178  double *rdiag, double *acnorm, double *wa );
179 void lm_qrsolv( int n, double *r, int ldr, int *ipvt, double *diag,
180  double *qtb, double *x, double *sdiag, double *wa );
181 
182 #define MIN(a,b) (((a)<=(b)) ? (a) : (b))
183 #define MAX(a,b) (((a)>=(b)) ? (a) : (b))
184 #define SQR(x) (x)*(x)
185 
186 
187 void lm_lmdif( int m, int n, double *x, double *fvec, double ftol,
188  double xtol, double gtol, int maxfev, double epsfcn,
189  double *diag, int mode, double factor, int *info, int *nfev,
190  double *fjac, int *ipvt, double *qtf, double *wa1,
191  double *wa2, double *wa3, double *wa4,
192  void (*evaluate) (const double *par, int m_dat, const void *data,
193  double *fvec, int *info),
194  void (*printout) (int n_par, const double *par, int m_dat,
195  const void *data, const double *fvec,
196  int printflags, int iflag, int iter, int nfev),
197  int printflags, const void *data )
198 {
199  //
200  // The purpose of lmdif is to minimize the sum of the squares of
201  // m nonlinear functions in n variables by a modification of
202  // the levenberg-marquardt algorithm. The user must provide a
203  // subroutine evaluate which calculates the functions. The jacobian
204  // is then calculated by a forward-difference approximation.
205  //
206  // The multi-parameter interface lm_lmdif is for users who want
207  // full control and flexibility. Most users will be better off using
208  // the simpler interface lmmin provided above.
209  //
210  // Parameters:
211  //
212  // m is a positive integer input variable set to the number
213  // of functions.
214  //
215  // n is a positive integer input variable set to the number
216  // of variables; n must not exceed m.
217  //
218  // x is an array of length n. On input x must contain an initial
219  // estimate of the solution vector. On OUTPUT x contains the
220  // final estimate of the solution vector.
221  //
222  // fvec is an OUTPUT array of length m which contains
223  // the functions evaluated at the output x.
224  //
225  // ftol is a nonnegative input variable. Termination occurs when
226  // both the actual and predicted relative reductions in the sum
227  // of squares are at most ftol. Therefore, ftol measures the
228  // relative error desired in the sum of squares.
229  //
230  // xtol is a nonnegative input variable. Termination occurs when
231  // the relative error between two consecutive iterates is at
232  // most xtol. Therefore, xtol measures the relative error desired
233  // in the approximate solution.
234  //
235  // gtol is a nonnegative input variable. Termination occurs when
236  // the cosine of the angle between fvec and any column of the
237  // jacobian is at most gtol in absolute value. Therefore, gtol
238  // measures the orthogonality desired between the function vector
239  // and the columns of the jacobian.
240  //
241  // maxfev is a positive integer input variable. Termination
242  // occurs when the number of calls to lm_fcn is at least
243  // maxfev by the end of an iteration.
244  //
245  // epsfcn is an input variable used in choosing a step length for
246  // the forward-difference approximation. The relative errors in
247  // the functions are assumed to be of the order of epsfcn.
248  //
249  // diag is an array of length n. If mode = 1 (see below), diag is
250  // internally set. If mode = 2, diag must contain positive entries
251  // that serve as multiplicative scale factors for the variables.
252  //
253  // mode is an integer input variable. If mode = 1, the
254  // variables will be scaled internally. If mode = 2,
255  // the scaling is specified by the input diag.
256  //
257  // factor is a positive input variable used in determining the
258  // initial step bound. This bound is set to the product of
259  // factor and the euclidean norm of diag*x if nonzero, or else
260  // to factor itself. In most cases factor should lie in the
261  // interval (0.1,100.0). Generally, the value 100.0 is recommended.
262  //
263  // info is an integer OUTPUT variable that indicates the termination
264  // status of lm_lmdif as follows:
265  //
266  // info < 0 termination requested by user-supplied routine *evaluate;
267  //
268  // info = 0 fnorm almost vanishing;
269  //
270  // info = 1 both actual and predicted relative reductions
271  // in the sum of squares are at most ftol;
272  //
273  // info = 2 relative error between two consecutive iterates
274  // is at most xtol;
275  //
276  // info = 3 conditions for info = 1 and info = 2 both hold;
277  //
278  // info = 4 the cosine of the angle between fvec and any
279  // column of the jacobian is at most gtol in
280  // absolute value;
281  //
282  // info = 5 number of calls to lm_fcn has reached or
283  // exceeded maxfev;
284  //
285  // info = 6 ftol is too small: no further reduction in
286  // the sum of squares is possible;
287  //
288  // info = 7 xtol is too small: no further improvement in
289  // the approximate solution x is possible;
290  //
291  // info = 8 gtol is too small: fvec is orthogonal to the
292  // columns of the jacobian to machine precision;
293  //
294  // info =10 improper input parameters;
295  //
296  // nfev is an OUTPUT variable set to the number of calls to the
297  // user-supplied routine *evaluate.
298  //
299  // fjac is an OUTPUT m by n array. The upper n by n submatrix
300  // of fjac contains an upper triangular matrix r with
301  // diagonal elements of nonincreasing magnitude such that
302  //
303  // pT*(jacT*jac)*p = rT*r
304  //
305  // (NOTE: T stands for matrix transposition),
306  //
307  // where p is a permutation matrix and jac is the final
308  // calculated jacobian. Column j of p is column ipvt(j)
309  // (see below) of the identity matrix. The lower trapezoidal
310  // part of fjac contains information generated during
311  // the computation of r.
312  //
313  // ipvt is an integer OUTPUT array of length n. It defines a
314  // permutation matrix p such that jac*p = q*r, where jac is
315  // the final calculated jacobian, q is orthogonal (not stored),
316  // and r is upper triangular with diagonal elements of
317  // nonincreasing magnitude. Column j of p is column ipvt(j)
318  // of the identity matrix.
319  //
320  // qtf is an OUTPUT array of length n which contains
321  // the first n elements of the vector (q transpose)*fvec.
322  //
323  // wa1, wa2, and wa3 are work arrays of length n.
324  //
325  // wa4 is a work array of length m, used among others to hold
326  // residuals from evaluate.
327  //
328  // evaluate points to the subroutine which calculates the
329  // m nonlinear functions. Implementations should be written as follows:
330  //
331  // void evaluate( double* par, int m_dat, void *data,
332  // double* fvec, int *info )
333  // {
334  // // for ( i=0; i<m_dat; ++i )
335  // // calculate fvec[i] for given parameters par;
336  // // to stop the minimization,
337  // // set *info to a negative integer.
338  // }
339  //
340  // printout points to the subroutine which informs about fit progress.
341  // Call with printout=0 if no printout is desired.
342  // Call with printout=lm_printout_std to use the default implementation.
343  //
344  // printflags is passed to printout.
345  //
346  // data is an input pointer to an arbitrary structure that is passed to
347  // evaluate. Typically, it contains experimental data to be fitted.
348  //
349  //
350  int i, iter, j;
351  double actred, delta, dirder, eps, fnorm, fnorm1, par, pnorm,
352  prered, ratio, step, sum, temp, temp1, temp2, temp3, xnorm;
353  static double p1 = 0.1;
354  static double p0001 = 1.0e-4;
355 
356  *nfev = 0; // function evaluation counter
357  iter = 0; // outer loop counter
358  par = 0; // levenberg-marquardt parameter
359  delta = 0; // to prevent a warning (initialization within if-clause)
360  xnorm = 0; // ditto
361  temp = MAX(epsfcn, LM_MACHEP);
362  eps = sqrt(temp); // for calculating the Jacobian by forward differences
363 
364  // lmdif: check input parameters for errors.
365 
366  if ( (n <= 0) || (m < n) || (ftol < 0.)
367  || (xtol < 0.) || (gtol < 0.) || (maxfev <= 0) || (factor <= 0.) ) {
368  *info = 10; // invalid parameter
369  return;
370  }
371  if ( mode == 2 ) { // scaling by diag[]
372  for ( j = 0; j < n; j++ ) { // check for nonpositive elements
373  if ( diag[j] <= 0.0 ) {
374  *info = 10; // invalid parameter
375  return;
376  }
377  }
378  }
379 #ifdef LMFIT_DEBUG_MESSAGES
380  printf("lmdif\n");
381 #endif
382 
383  // lmdif: evaluate function at starting point and calculate norm.
384 
385  *info = 0;
386  (*evaluate) (x, m, data, fvec, info);
387  ++(*nfev);
388  if ( printout ) {
389  (*printout) (n, x, m, data, fvec, printflags, 0, 0, *nfev);
390  }
391  if ( *info < 0 ) {
392  return;
393  }
394  fnorm = lm_enorm(m, fvec);
395  if ( fnorm <= LM_DWARF ) {
396  *info = 0;
397  return;
398  }
399 
400  // lmdif: the outer loop.
401 
402  do {
403 #ifdef LMFIT_DEBUG_MESSAGES
404  printf("lmdif/ outer loop iter=%d nfev=%d fnorm=%.10e\n",
405  iter, *nfev, fnorm);
406 #endif
407 
408  // outer: calculate the Jacobian.
409 
410  for ( j = 0; j < n; j++ ) {
411  temp = x[j];
412  step = MAX(eps*eps, eps * fabs(temp));
413  x[j] = temp + step; // replace temporarily
414  *info = 0;
415  (*evaluate) (x, m, data, wa4, info);
416  ++(*nfev);
417  if ( printout ) {
418  (*printout) (n, x, m, data, wa4, printflags, 1, iter, *nfev);
419  }
420  if ( *info < 0 ) {
421  return; // user requested break
422  }
423  for ( i = 0; i < m; i++ ) {
424  fjac[j*m+i] = (wa4[i] - fvec[i]) / step;
425  }
426  x[j] = temp; // restore
427  }
428 #ifdef LMFIT_DEBUG_MATRIX
429  // print the entire matrix
430  for (i = 0; i < m; i++) {
431  for (j = 0; j < n; j++)
432  printf("%.5e ", fjac[j*m+i]);
433  printf("\n");
434  }
435 #endif
436 
437  // outer: compute the qr factorization of the Jacobian.
438 
439  lm_qrfac(m, n, fjac, 1, ipvt, wa1, wa2, wa3);
440  // return values are ipvt, wa1=rdiag, wa2=acnorm
441 
442  if ( !iter ) {
443  // first iteration only
444  if ( mode != 2 ) {
445  // diag := norms of the columns of the initial Jacobian
446  for ( j = 0; j < n; j++ ) {
447  diag[j] = wa2[j];
448  if ( wa2[j] == 0. ) {
449  diag[j] = 1.;
450  }
451  }
452  }
453  // use diag to scale x, then calculate the norm
454  for ( j = 0; j < n; j++ ) {
455  wa3[j] = diag[j] * x[j];
456  }
457  xnorm = lm_enorm(n, wa3);
458  // initialize the step bound delta.
459  delta = factor * xnorm;
460  if ( delta == 0. ) {
461  delta = factor;
462  }
463  } else {
464  if ( mode != 2 ) {
465  for ( j = 0; j < n; j++ ) {
466  diag[j] = MAX( diag[j], wa2[j] );
467  }
468  }
469  }
470 
471  // outer: form (q transpose)*fvec and store first n components in qtf.
472 
473  for ( i = 0; i < m; i++ ) {
474  wa4[i] = fvec[i];
475  }
476 
477  for ( j = 0; j < n; j++ ) {
478  temp3 = fjac[j*m+j];
479  if ( temp3 != 0. ) {
480  sum = 0;
481  for ( i = j; i < m; i++ ) {
482  sum += fjac[j*m+i] * wa4[i];
483  }
484  temp = -sum / temp3;
485  for ( i = j; i < m; i++ ) {
486  wa4[i] += fjac[j*m+i] * temp;
487  }
488  }
489  fjac[j*m+j] = wa1[j];
490  qtf[j] = wa4[j];
491  }
492 
493  // outer: compute norm of scaled gradient and test for convergence.
494 
495  double gnorm = 0;
496  for ( j = 0; j < n; j++ ) {
497  if ( wa2[ipvt[j]] == 0 ) {
498  continue;
499  }
500  sum = 0.;
501  for ( i = 0; i <= j; i++ ) {
502  sum += fjac[j*m+i] * qtf[i];
503  }
504  gnorm = MAX( gnorm, fabs( sum / wa2[ipvt[j]] / fnorm ) );
505  }
506 
507  if ( gnorm <= gtol ) {
508  *info = 4;
509  return;
510  }
511 
512  // the inner loop.
513  do {
514 #ifdef LMFIT_DEBUG_MESSAGES
515  printf("lmdif/ inner loop iter=%d nfev=%d\n", iter, *nfev);
516 #endif
517 
518  // inner: determine the levenberg-marquardt parameter.
519 
520  lm_lmpar( n, fjac, m, ipvt, diag, qtf, delta, &par,
521  wa1, wa2, wa4, wa3 );
522  // used return values are fjac (partly), par, wa1=x, wa3=diag*x
523 
524  for ( j = 0; j < n; j++ ) {
525  wa2[j] = x[j] - wa1[j]; // new parameter vector ?
526  }
527 
528  pnorm = lm_enorm(n, wa3);
529 
530  // at first call, adjust the initial step bound.
531 
532  if ( *nfev <= 1+n ) {
533  delta = MIN(delta, pnorm);
534  }
535 
536  // inner: evaluate the function at x + p and calculate its norm.
537 
538  *info = 0;
539  (*evaluate) (wa2, m, data, wa4, info);
540  ++(*nfev);
541  if ( printout ) {
542  (*printout) (n, wa2, m, data, wa4, printflags, 2, iter, *nfev);
543  }
544  if ( *info < 0 ) {
545  return; // user requested break.
546  }
547 
548  fnorm1 = lm_enorm(m, wa4);
549 #ifdef LMFIT_DEBUG_MESSAGES
550  printf("lmdif/ pnorm %.10e fnorm1 %.10e fnorm %.10e"
551  " delta=%.10e par=%.10e\n",
552  pnorm, fnorm1, fnorm, delta, par);
553 #endif
554 
555  // inner: compute the scaled actual reduction.
556 
557  if ( p1 * fnorm1 < fnorm ) {
558  actred = 1 - SQR(fnorm1 / fnorm);
559  } else {
560  actred = -1;
561  }
562 
563  // inner: compute the scaled predicted reduction and
564  // the scaled directional derivative.
565 
566  for ( j = 0; j < n; j++ ) {
567  wa3[j] = 0;
568  for ( i = 0; i <= j; i++ ) {
569  wa3[i] -= fjac[j*m+i] * wa1[ipvt[j]];
570  }
571  }
572  temp1 = lm_enorm(n, wa3) / fnorm;
573  temp2 = sqrt(par) * pnorm / fnorm;
574  prered = SQR(temp1) + 2 * SQR(temp2);
575  dirder = -(SQR(temp1) + SQR(temp2));
576 
577  // inner: compute the ratio of the actual to the predicted reduction.
578 
579  ratio = prered != 0 ? actred / prered : 0;
580 #ifdef LMFIT_DEBUG_MESSAGES
581  printf("lmdif/ actred=%.10e prered=%.10e ratio=%.10e"
582  " sq(1)=%.10e sq(2)=%.10e dd=%.10e\n",
583  actred, prered, prered != 0 ? ratio : 0.,
584  SQR(temp1), SQR(temp2), dirder);
585 #endif
586 
587  // inner: update the step bound.
588 
589  if ( ratio <= 0.25 ) {
590  if ( actred >= 0. ) {
591  temp = 0.5;
592  } else {
593  temp = 0.5 * dirder / (dirder + 0.55 * actred);
594  }
595  if ( p1 * fnorm1 >= fnorm || temp < p1 ) {
596  temp = p1;
597  }
598  delta = temp * MIN(delta, pnorm / p1);
599  par /= temp;
600  } else if ( par == 0. || ratio >= 0.75 ) {
601  delta = pnorm / 0.5;
602  par *= 0.5;
603  }
604 
605  // inner: test for successful iteration.
606 
607  if ( ratio >= p0001 ) {
608  // yes, success: update x, fvec, and their norms.
609  for ( j = 0; j < n; j++ ) {
610  x[j] = wa2[j];
611  wa2[j] = diag[j] * x[j];
612  }
613  for ( i = 0; i < m; i++ ) {
614  fvec[i] = wa4[i];
615  }
616  xnorm = lm_enorm(n, wa2);
617  fnorm = fnorm1;
618  iter++;
619  }
620 #ifdef LMFIT_DEBUG_MESSAGES
621  else {
622  printf("ATTN: iteration considered unsuccessful\n");
623  }
624 #endif
625 
626  // inner: test for convergence.
627 
628  if ( fnorm<=LM_DWARF ) {
629  *info = 0;
630  return;
631  }
632 
633  *info = 0;
634  if ( fabs(actred) <= ftol && prered <= ftol && 0.5 * ratio <= 1 ) {
635  *info = 1;
636  }
637  if ( delta <= xtol * xnorm ) {
638  *info += 2;
639  }
640  if ( *info != 0 ) {
641  return;
642  }
643 
644  // inner: tests for termination and stringent tolerances.
645 
646  if ( *nfev >= maxfev ) {
647  *info = 5;
648  return;
649  }
650  if ( fabs(actred) <= LM_MACHEP &&
651  prered <= LM_MACHEP && 0.5 * ratio <= 1 ) {
652  *info = 6;
653  return;
654  }
655  if ( delta <= LM_MACHEP * xnorm ) {
656  *info = 7;
657  return;
658  }
659  if ( gnorm <= LM_MACHEP ) {
660  *info = 8;
661  return;
662  }
663 
664  // inner: end of the loop. repeat if iteration unsuccessful.
665 
666  } while (ratio < p0001);
667 
668  // outer: end of the loop.
669 
670  } while (1);
671 
672 } // lm_lmdif.
673 
674 
675 // lm_lmpar (determine Levenberg-Marquardt parameter)
676 
677 void lm_lmpar(int n, double *r, int ldr, int *ipvt, double *diag,
678  double *qtb, double delta, double *par, double *x,
679  double *sdiag, double *aux, double *xdi)
680 {
681  // Given an m by n matrix a, an n by n nonsingular diagonal
682  // matrix d, an m-vector b, and a positive number delta,
683  // the problem is to determine a value for the parameter
684  // par such that if x solves the system
685  //
686  // a*x = b and sqrt(par)*d*x = 0
687  //
688  // in the least squares sense, and dxnorm is the euclidean
689  // norm of d*x, then either par=0 and (dxnorm-delta) < 0.1*delta,
690  // or par>0 and std::abs(dxnorm-delta) < 0.1*delta.
691  //
692  // Using lm_qrsolv, this subroutine completes the solution of the problem
693  // if it is provided with the necessary information from the
694  // qr factorization, with column pivoting, of a. That is, if
695  // a*p = q*r, where p is a permutation matrix, q has orthogonal
696  // columns, and r is an upper triangular matrix with diagonal
697  // elements of nonincreasing magnitude, then lmpar expects
698  // the full upper triangle of r, the permutation matrix p,
699  // and the first n components of qT*b. On output
700  // lmpar also provides an upper triangular matrix s such that
701  //
702  // pT*(aT*a + par*d*d)*p = sT*s.
703  //
704  // s is employed within lmpar and may be of separate interest.
705  //
706  // Only a few iterations are generally needed for convergence
707  // of the algorithm. If, however, the limit of 10 iterations
708  // is reached, then the output par will contain the best
709  // value obtained so far.
710  //
711  // parameters:
712  //
713  // n is a positive integer input variable set to the order of r.
714  //
715  // r is an n by n array. on input the full upper triangle
716  // must contain the full upper triangle of the matrix r.
717  // on OUTPUT the full upper triangle is unaltered, and the
718  // strict lower triangle contains the strict upper triangle
719  // (transposed) of the upper triangular matrix s.
720  //
721  // ldr is a positive integer input variable not less than n
722  // which specifies the leading dimension of the array r.
723  //
724  // ipvt is an integer input array of length n which defines the
725  // permutation matrix p such that a*p = q*r. column j of p
726  // is column ipvt(j) of the identity matrix.
727  //
728  // diag is an input array of length n which must contain the
729  // diagonal elements of the matrix d.
730  //
731  // qtb is an input array of length n which must contain the first
732  // n elements of the vector (q transpose)*b.
733  //
734  // delta is a positive input variable which specifies an upper
735  // bound on the euclidean norm of d*x.
736  //
737  // par is a nonnegative variable. on input par contains an
738  // initial estimate of the levenberg-marquardt parameter.
739  // on OUTPUT par contains the final estimate.
740  //
741  // x is an OUTPUT array of length n which contains the least
742  // squares solution of the system a*x = b, sqrt(par)*d*x = 0,
743  // for the output par.
744  //
745  // sdiag is an array of length n which contains the
746  // diagonal elements of the upper triangular matrix s.
747  //
748  // aux is a multi-purpose work array of length n.
749  //
750  // xdi is a work array of length n. On OUTPUT: diag[j] * x[j].
751  //
752  //
753  int i, iter, j, nsing;
754  double dxnorm, fp, gnorm, parl, paru;
755  double sum, temp;
756  static double p1 = 0.1;
757 
758 #ifdef LMFIT_DEBUG_MESSAGES
759  printf("lmpar\n");
760 #endif
761 
762  // lmpar: compute and store in x the gauss-newton direction. if the
763  // jacobian is rank-deficient, obtain a least squares solution.
764 
765  nsing = n;
766  for ( j = 0; j < n; j++ ) {
767  aux[j] = qtb[j];
768  if ( r[j * ldr + j] == 0 && nsing == n ) {
769  nsing = j;
770  }
771  if ( nsing < n ) {
772  aux[j] = 0;
773  }
774  }
775 #ifdef LMFIT_DEBUG_MESSAGES
776  printf("nsing %d ", nsing);
777 #endif
778  for ( j = nsing - 1; j >= 0; j-- ) {
779  aux[j] = aux[j] / r[j + ldr * j];
780  temp = aux[j];
781  for ( i = 0; i < j; i++ ) {
782  aux[i] -= r[j * ldr + i] * temp;
783  }
784  }
785 
786  for ( j = 0; j < n; j++ ) {
787  x[ipvt[j]] = aux[j];
788  }
789 
790  // lmpar: initialize the iteration counter, evaluate the function at the
791  // origin, and test for acceptance of the gauss-newton direction.
792 
793  iter = 0;
794  for ( j = 0; j < n; j++ ) {
795  xdi[j] = diag[j] * x[j];
796  }
797  dxnorm = lm_enorm(n, xdi);
798  fp = dxnorm - delta;
799  if ( fp <= p1 * delta ) {
800 #ifdef LMFIT_DEBUG_MESSAGES
801  printf("lmpar/ terminate (fp<p1*delta)\n");
802 #endif
803  *par = 0;
804  return;
805  }
806 
807  // lmpar: if the jacobian is not rank deficient, the newton
808  // step provides a lower bound, parl, for the 0. of
809  // the function. otherwise set this bound to 0..
810 
811  parl = 0;
812  if ( nsing >= n ) {
813  for ( j = 0; j < n; j++ ) {
814  aux[j] = diag[ipvt[j]] * xdi[ipvt[j]] / dxnorm;
815  }
816 
817  for ( j = 0; j < n; j++ ) {
818  sum = 0.;
819  for ( i = 0; i < j; i++ ) {
820  sum += r[j * ldr + i] * aux[i];
821  }
822  aux[j] = (aux[j] - sum) / r[j + ldr * j];
823  }
824  temp = lm_enorm(n, aux);
825  parl = fp / delta / temp / temp;
826  }
827 
828  // lmpar: calculate an upper bound, paru, for the 0. of the function.
829 
830  for ( j = 0; j < n; j++ ) {
831  sum = 0;
832  for ( i = 0; i <= j; i++ ) {
833  sum += r[j * ldr + i] * qtb[i];
834  }
835  aux[j] = sum / diag[ipvt[j]];
836  }
837  gnorm = lm_enorm(n, aux);
838  paru = gnorm / delta;
839  if ( paru == 0. ) {
840  paru = LM_DWARF / MIN(delta, p1);
841  }
842 
843  // lmpar: if the input par lies outside of the interval (parl,paru),
844  // set par to the closer endpoint.
845 
846  *par = MAX(*par, parl);
847  *par = MIN(*par, paru);
848  if ( *par == 0. ) {
849  *par = gnorm / dxnorm;
850  }
851 #ifdef LMFIT_DEBUG_MESSAGES
852  printf("lmpar/ parl %.4e par %.4e paru %.4e\n", parl, *par, paru);
853 #endif
854 
855  // lmpar: iterate.
856 
857  for ( ; ; iter++ ) {
858 
859  // evaluate the function at the current value of par.
860 
861  if ( *par == 0. ) {
862  *par = MAX(LM_DWARF, 0.001 * paru);
863  }
864  temp = sqrt(*par);
865  for ( j = 0; j < n; j++ ) {
866  aux[j] = temp * diag[j];
867  }
868 
869  lm_qrsolv( n, r, ldr, ipvt, aux, qtb, x, sdiag, xdi );
870  // return values are r, x, sdiag
871 
872  for ( j = 0; j < n; j++ ) {
873  xdi[j] = diag[j] * x[j]; // used as output
874  }
875  dxnorm = lm_enorm(n, xdi);
876  double fp_old = fp;
877  fp = dxnorm - delta;
878 
879  // if the function is small enough, accept the current value
880  // of par. Also test for the exceptional cases where parl
881  // is zero or the number of iterations has reached 10.
882 
883  if ( fabs(fp) <= p1 * delta
884  || (parl == 0. && fp <= fp_old && fp_old < 0.)
885  || iter == 10 ) {
886  break; // the only exit from the iteration. //
887  }
888 
889  // compute the Newton correction.
890 
891  for ( j = 0; j < n; j++ ) {
892  aux[j] = diag[ipvt[j]] * xdi[ipvt[j]] / dxnorm;
893  }
894 
895  for ( j = 0; j < n; j++ ) {
896  aux[j] = aux[j] / sdiag[j];
897  for ( i = j + 1; i < n; i++ ) {
898  aux[i] -= r[j * ldr + i] * aux[j];
899  }
900  }
901  temp = lm_enorm(n, aux);
902  double parc = fp / delta / temp / temp;
903 
904  // depending on the sign of the function, update parl or paru.
905 
906  if ( fp > 0 ) {
907  parl = MAX(parl, *par);
908  } else if ( fp < 0 ) {
909  paru = MIN(paru, *par);
910  }
911  // the case fp==0 is precluded by the break condition //
912 
913  // compute an improved estimate for par. //
914 
915  *par = MAX(parl, *par + parc);
916 
917  }
918 
919 } // lm_lmpar.
920 
921 
922 // lm_qrfac (QR factorisation, from lapack)
923 
924 void lm_qrfac(int m, int n, double *a, int pivot, int *ipvt,
925  double *rdiag, double *acnorm, double *wa)
926 {
927  //
928  // This subroutine uses householder transformations with column
929  // pivoting (optional) to compute a qr factorization of the
930  // m by n matrix a. That is, qrfac determines an orthogonal
931  // matrix q, a permutation matrix p, and an upper trapezoidal
932  // matrix r with diagonal elements of nonincreasing magnitude,
933  // such that a*p = q*r. The householder transformation for
934  // column k, k = 1,2,...,min(m,n), is of the form
935  //
936  // i - (1/u(k))*u*uT
937  //
938  // where u has zeroes in the first k-1 positions. The form of
939  // this transformation and the method of pivoting first
940  // appeared in the corresponding linpack subroutine.
941  //
942  // Parameters:
943  //
944  // m is a positive integer input variable set to the number
945  // of rows of a.
946  //
947  // n is a positive integer input variable set to the number
948  // of columns of a.
949  //
950  // a is an m by n array. On input a contains the matrix for
951  // which the qr factorization is to be computed. On OUTPUT
952  // the strict upper trapezoidal part of a contains the strict
953  // upper trapezoidal part of r, and the lower trapezoidal
954  // part of a contains a factored form of q (the non-trivial
955  // elements of the u vectors described above).
956  //
957  // pivot is a logical input variable. If pivot is set true,
958  // then column pivoting is enforced. If pivot is set false,
959  // then no column pivoting is done.
960  //
961  // ipvt is an integer OUTPUT array of length lipvt. This array
962  // defines the permutation matrix p such that a*p = q*r.
963  // Column j of p is column ipvt(j) of the identity matrix.
964  // If pivot is false, ipvt is not referenced.
965  //
966  // rdiag is an OUTPUT array of length n which contains the
967  // diagonal elements of r.
968  //
969  // acnorm is an OUTPUT array of length n which contains the
970  // norms of the corresponding columns of the input matrix a.
971  // If this information is not needed, then acnorm can coincide
972  // with rdiag.
973  //
974  // wa is a work array of length n. If pivot is false, then wa
975  // can coincide with rdiag.
976  //
977  //
978  int i, j, k, kmax, minmn;
979  double ajnorm, sum, temp;
980 
981  // qrfac: compute initial column norms and initialize several arrays.
982 
983  for ( j = 0; j < n; j++ ) {
984  acnorm[j] = lm_enorm(m, &a[j*m]);
985  rdiag[j] = acnorm[j];
986  wa[j] = rdiag[j];
987  if ( pivot ) {
988  ipvt[j] = j;
989  }
990  }
991 #ifdef LMFIT_DEBUG_MESSAGES
992  printf("qrfac\n");
993 #endif
994 
995  // qrfac: reduce a to r with householder transformations.
996 
997  minmn = MIN(m, n);
998  for ( j = 0; j < minmn; j++ ) {
999  if ( !pivot ) {
1000  goto pivot_ok;
1001  }
1002 
1003  // bring the column of largest norm into the pivot position.
1004 
1005  kmax = j;
1006  for ( k = j + 1; k < n; k++ ) {
1007  if ( rdiag[k] > rdiag[kmax] ) {
1008  kmax = k;
1009  }
1010  }
1011  if ( kmax == j ) {
1012  goto pivot_ok;
1013  }
1014 
1015  for ( i = 0; i < m; i++ ) {
1016  temp = a[j*m+i];
1017  a[j*m+i] = a[kmax*m+i];
1018  a[kmax*m+i] = temp;
1019  }
1020  rdiag[kmax] = rdiag[j];
1021  wa[kmax] = wa[j];
1022  k = ipvt[j];
1023  ipvt[j] = ipvt[kmax];
1024  ipvt[kmax] = k;
1025 
1026  pivot_ok:
1027  // compute the Householder transformation to reduce the
1028  // j-th column of a to a multiple of the j-th unit vector.
1029 
1030  ajnorm = lm_enorm(m-j, &a[j*m+j]);
1031  if ( ajnorm == 0. ) {
1032  rdiag[j] = 0;
1033  continue;
1034  }
1035 
1036  if ( a[j*m+j] < 0. ) {
1037  ajnorm = -ajnorm;
1038  }
1039  for ( i = j; i < m; i++ ) {
1040  a[j*m+i] /= ajnorm;
1041  }
1042  a[j*m+j] += 1;
1043 
1044  // apply the transformation to the remaining columns
1045  // and update the norms.
1046 
1047  for ( k = j + 1; k < n; k++ ) {
1048  sum = 0;
1049 
1050  for ( i = j; i < m; i++ ) {
1051  sum += a[j*m+i] * a[k*m+i];
1052  }
1053 
1054  temp = sum / a[j + m * j];
1055 
1056  for ( i = j; i < m; i++ ) {
1057  a[k*m+i] -= temp * a[j*m+i];
1058  }
1059 
1060  if ( pivot && rdiag[k] != 0. ) {
1061  temp = a[m * k + j] / rdiag[k];
1062  temp = MAX(0., 1 - temp * temp);
1063  rdiag[k] *= sqrt(temp);
1064  temp = rdiag[k] / wa[k];
1065  if ( 0.05 * SQR(temp) <= LM_MACHEP ) {
1066  rdiag[k] = lm_enorm(m-j-1, &a[m*k+j+1]);
1067  wa[k] = rdiag[k];
1068  }
1069  }
1070  }
1071 
1072  rdiag[j] = -ajnorm;
1073  }
1074 }
1075 
1076 
1077 // lm_qrsolv (linear least-squares)
1078 void lm_qrsolv(int n, double *r, int ldr, int *ipvt, double *diag,
1079  double *qtb, double *x, double *sdiag, double *wa)
1080 {
1081  //
1082  // Given an m by n matrix a, an n by n diagonal matrix d,
1083  // and an m-vector b, the problem is to determine an x which
1084  // solves the system
1085  //
1086  // a*x = b and d*x = 0
1087  //
1088  // in the least squares sense.
1089  //
1090  // This subroutine completes the solution of the problem
1091  // if it is provided with the necessary information from the
1092  // qr factorization, with column pivoting, of a. That is, if
1093  // a*p = q*r, where p is a permutation matrix, q has orthogonal
1094  // columns, and r is an upper triangular matrix with diagonal
1095  // elements of nonincreasing magnitude, then qrsolv expects
1096  // the full upper triangle of r, the permutation matrix p,
1097  // and the first n components of (q transpose)*b. The system
1098  // a*x = b, d*x = 0, is then equivalent to
1099  //
1100  // r*z = qT*b, pT*d*p*z = 0,
1101  //
1102  // where x = p*z. If this system does not have full rank,
1103  // then a least squares solution is obtained. On output qrsolv
1104  // also provides an upper triangular matrix s such that
1105  //
1106  // pT *(aT *a + d*d)*p = sT *s.
1107  //
1108  // s is computed within qrsolv and may be of separate interest.
1109  //
1110  // Parameters
1111  //
1112  // n is a positive integer input variable set to the order of r.
1113  //
1114  // r is an n by n array. On input the full upper triangle
1115  // must contain the full upper triangle of the matrix r.
1116  // On OUTPUT the full upper triangle is unaltered, and the
1117  // strict lower triangle contains the strict upper triangle
1118  // (transposed) of the upper triangular matrix s.
1119  //
1120  // ldr is a positive integer input variable not less than n
1121  // which specifies the leading dimension of the array r.
1122  //
1123  // ipvt is an integer input array of length n which defines the
1124  // permutation matrix p such that a*p = q*r. Column j of p
1125  // is column ipvt(j) of the identity matrix.
1126  //
1127  // diag is an input array of length n which must contain the
1128  // diagonal elements of the matrix d.
1129  //
1130  // qtb is an input array of length n which must contain the first
1131  // n elements of the vector (q transpose)*b.
1132  //
1133  // x is an OUTPUT array of length n which contains the least
1134  // squares solution of the system a*x = b, d*x = 0.
1135  //
1136  // sdiag is an OUTPUT array of length n which contains the
1137  // diagonal elements of the upper triangular matrix s.
1138  //
1139  // wa is a work array of length n.
1140  //
1141  //
1142  int i, kk, j, k, nsing;
1143  double qtbpj, sum, temp;
1144  double _sin, _cos, _tan, _cot; // local variables, not functions
1145 
1146  // qrsolv: copy r and (q transpose)*b to preserve input and initialize s.
1147  // in particular, save the diagonal elements of r in x.
1148 
1149  for ( j = 0; j < n; j++ ) {
1150  for ( i = j; i < n; i++ ) {
1151  r[j * ldr + i] = r[i * ldr + j];
1152  }
1153  x[j] = r[j * ldr + j];
1154  wa[j] = qtb[j];
1155  }
1156 #ifdef LMFIT_DEBUG_MESSAGES
1157  printf("qrsolv\n");
1158 #endif
1159 
1160  // qrsolv: eliminate the diagonal matrix d using a Givens rotation.
1161 
1162  for ( j = 0; j < n; j++ ) {
1163 
1164  // qrsolv: prepare the row of d to be eliminated, locating the
1165  // diagonal element using p from the qr factorization.
1166 
1167  if ( diag[ipvt[j]] == 0. ) {
1168  goto L90;
1169  }
1170  for ( k = j; k < n; k++ ) {
1171  sdiag[k] = 0.;
1172  }
1173  sdiag[j] = diag[ipvt[j]];
1174 
1175  // qrsolv: the transformations to eliminate the row of d modify only
1176  // a single element of qT*b beyond the first n, which is initially 0.
1177 
1178  qtbpj = 0.;
1179  for ( k = j; k < n; k++ ) {
1180 
1181  // determine a Givens rotation which eliminates the
1182  // appropriate element in the current row of d.
1183 
1184  if ( sdiag[k] == 0. ) {
1185  continue;
1186  }
1187  kk = k + ldr * k;
1188  if ( fabs(r[kk]) < fabs(sdiag[k]) ) {
1189  _cot = r[kk] / sdiag[k];
1190  _sin = 1 / sqrt(1 + SQR(_cot));
1191  _cos = _sin * _cot;
1192  } else {
1193  _tan = sdiag[k] / r[kk];
1194  _cos = 1 / sqrt(1 + SQR(_tan));
1195  _sin = _cos * _tan;
1196  }
1197 
1198  // compute the modified diagonal element of r and
1199  // the modified element of ((q transpose)*b,0).
1200 
1201  r[kk] = _cos * r[kk] + _sin * sdiag[k];
1202  temp = _cos * wa[k] + _sin * qtbpj;
1203  qtbpj = -_sin * wa[k] + _cos * qtbpj;
1204  wa[k] = temp;
1205 
1206  // accumulate the tranformation in the row of s.
1207 
1208  for ( i = k + 1; i < n; i++ ) {
1209  temp = _cos * r[k * ldr + i] + _sin * sdiag[i];
1210  sdiag[i] = -_sin * r[k * ldr + i] + _cos * sdiag[i];
1211  r[k * ldr + i] = temp;
1212  }
1213  }
1214 
1215  L90:
1216  // store the diagonal element of s and restore
1217  // the corresponding diagonal element of r.
1218 
1219  sdiag[j] = r[j * ldr + j];
1220  r[j * ldr + j] = x[j];
1221  }
1222 
1223  // qrsolv: solve the triangular system for z. if the system is
1224  // singular, then obtain a least squares solution.
1225 
1226  nsing = n;
1227  for ( j = 0; j < n; j++ ) {
1228  if ( sdiag[j] == 0. && nsing == n ) {
1229  nsing = j;
1230  }
1231  if ( nsing < n ) {
1232  wa[j] = 0;
1233  }
1234  }
1235 
1236  for ( j = nsing - 1; j >= 0; j-- ) {
1237  sum = 0;
1238  for ( i = j + 1; i < nsing; i++ ) {
1239  sum += r[j * ldr + i] * wa[i];
1240  }
1241  wa[j] = (wa[j] - sum) / sdiag[j];
1242  }
1243 
1244  // qrsolv: permute the components of z back to components of x.
1245 
1246  for ( j = 0; j < n; j++ ) {
1247  x[ipvt[j]] = wa[j];
1248  }
1249 
1250 } // lm_qrsolv.
1251 
1252 
1253 // lm_enorm (Euclidean norm)
1254 
1255 double lm_enorm(int n, const double *x)
1256 {
1257  // Given an n-vector x, this function calculates the
1258  // euclidean norm of x.
1259  //
1260  // The euclidean norm is computed by accumulating the sum of
1261  // squares in three different sums. The sums of squares for the
1262  // small and large components are scaled so that no overflows
1263  // occur. Non-destructive underflows are permitted. Underflows
1264  // and overflows do not occur in the computation of the unscaled
1265  // sum of squares for the intermediate components.
1266  // The definitions of small, intermediate and large components
1267  // depend on two constants, LM_SQRT_DWARF and LM_SQRT_GIANT. The main
1268  // restrictions on these constants are that LM_SQRT_DWARF**2 not
1269  // underflow and LM_SQRT_GIANT**2 not overflow.
1270  //
1271  // Parameters
1272  //
1273  // n is a positive integer input variable.
1274  //
1275  // x is an input array of length n.
1276  //
1277  int i;
1278  double agiant, s1, s2, s3, x1max, x3max, temp;
1279 
1280  s1 = 0;
1281  s2 = 0;
1282  s3 = 0;
1283  x1max = 0;
1284  x3max = 0;
1285  agiant = LM_SQRT_GIANT / n;
1286 
1287  // sum squares.
1288 
1289  for ( i = 0; i < n; i++ ) {
1290  double xabs = fabs(x[i]);
1291  if ( xabs > LM_SQRT_DWARF ) {
1292  if ( xabs < agiant ) {
1293  s2 += xabs * xabs;
1294  } else if ( xabs > x1max ) {
1295  temp = x1max / xabs;
1296  s1 = 1 + s1 * SQR(temp);
1297  x1max = xabs;
1298  } else {
1299  temp = xabs / x1max;
1300  s1 += SQR(temp);
1301  }
1302  } else if ( xabs > x3max ) {
1303  temp = x3max / xabs;
1304  s3 = 1 + s3 * SQR(temp);
1305  x3max = xabs;
1306  } else if ( xabs != 0. ) {
1307  temp = xabs / x3max;
1308  s3 += SQR(temp);
1309  }
1310  }
1311 
1312  // calculation of norm.
1313 
1314  if ( s1 != 0 ) {
1315  return x1max * sqrt(s1 + (s2 / x1max) / x1max);
1316  } else if ( s2 != 0 ) {
1317  if ( s2 >= x3max ) {
1318  return sqrt(s2 * (1 + (x3max / s2) * (x3max * s3)));
1319  } else {
1320  return sqrt(x3max * ((s2 / x3max) + (x3max * s3)));
1321  }
1322  } else {
1323  return x3max * sqrt(s3);
1324  }
1325 
1326 } // lm_enorm.
1327 
1328 }
1329 }
def status
void lm_lmpar(int n, double *r, int ldr, int *ipvt, double *diag, double *qtb, double delta, double *par, double *x, double *sdiag, double *aux, double *xdi)
Definition: lmmin.cc:677
#define LM_SQRT_GIANT
Definition: lmmin.cc:38
#define MIN(a, b)
Definition: lmmin.cc:182
def x
static void info(const char *fmt,...)
Definition: Svm.cc:48
double lm_enorm(int n, const double *x)
Definition: lmmin.cc:1255
void lm_qrfac(int m, int n, double *a, int pivot, int *ipvt, double *rdiag, double *acnorm, double *wa)
Definition: lmmin.cc:924
#define LM_USERTOL
Definition: lmmin.cc:39
void lmmin(int n_par, double *par, int m_dat, const void *data, void(*evaluate)(const double *par, int m_dat, const void *data, double *fvec, int *info), lm_status_struct *status, void(*printout)(int n_par, const double *par, int m_dat, const void *data, const double *fvec, int printflags, int iflag, int iter, int nfev))
Definition: lmmin.cc:96
#define LM_SQRT_DWARF
Definition: lmmin.cc:37
#define SQR(x)
Definition: lmmin.cc:184
void lm_qrsolv(int n, double *r, int ldr, int *ipvt, double *diag, double *qtb, double *x, double *sdiag, double *wa)
Definition: lmmin.cc:1078
#define LM_DWARF
Definition: lmmin.cc:36
double sum(InputIterator first, InputIterator last)
Returns the sum of all elements on the range [first, last)
Definition: prob_util.hh:27
void lm_printout_std(int n_par, const double *par, int m_dat, const void *, const double *fvec, int printflags, int iflag, int iter, int nfev)
Definition: lmmin.cc:43
string mode
Definition: contacts.py:32
#define LM_MACHEP
Definition: lmmin.cc:35
#define MAX(a, b)
Definition: lmmin.cc:183
void lm_lmdif(int m, int n, double *x, double *fvec, double ftol, double xtol, double gtol, int maxfev, double epsfcn, double *diag, int mode, double factor, int *info, int *nfev, double *fjac, int *ipvt, double *qtf, double *wa1, double *wa2, double *wa3, double *wa4, void(*evaluate)(const double *par, int m_dat, const void *data, double *fvec, int *info), void(*printout)(int n_par, const double *par, int m_dat, const void *data, const double *fvec, int printflags, int iflag, int iter, int nfev), int printflags, const void *data)
Definition: lmmin.cc:187