1
/////////////////////////////////////////////////////////////////////////////////
3
// Levenberg - Marquardt non-linear minimization algorithm
4
// Copyright (C) 2004 Manolis Lourakis (lourakis at ics forth gr)
5
// Institute of Computer Science, Foundation for Research & Technology - Hellas
6
// Heraklion, Crete, Greece.
8
// This program is free software; you can redistribute it and/or modify
9
// it under the terms of the GNU General Public License as published by
10
// the Free Software Foundation; either version 2 of the License, or
11
// (at your option) any later version.
13
// This program is distributed in the hope that it will be useful,
14
// but WITHOUT ANY WARRANTY; without even the implied warranty of
15
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
// GNU General Public License for more details.
18
/////////////////////////////////////////////////////////////////////////////////
20
/********************************************************************************
21
* Levenberg-Marquardt nonlinear minimization. The same core code is used with
22
* appropriate #defines to derive single and double precision versions, see
24
********************************************************************************/
36
#define ONE_THIRD 0.3333333334 /* 1.0/3.0 */
38
#if !defined(LM_DBL_PREC) && !defined(LM_SNGL_PREC)
39
#error At least one of LM_DBL_PREC, LM_SNGL_PREC should be defined!
44
/* single precision (float) definitions */
48
#define LM_REAL_MAX FLT_MAX
49
#define LM_REAL_MIN -FLT_MAX
50
#define LM_REAL_EPSILON FLT_EPSILON
51
#define __SUBCNST(x) x##F
52
#define LM_CNST(x) __SUBCNST(x) // force substitution
54
#include "lm_core.c" // read in core code
59
#undef LM_REAL_EPSILON
63
#endif /* LM_SNGL_PREC */
66
/* double precision definitions */
67
#define LM_REAL double
70
#define LM_REAL_MAX DBL_MAX
71
#define LM_REAL_MIN -DBL_MAX
72
#define LM_REAL_EPSILON DBL_EPSILON
73
#define LM_CNST(x) (x)
75
#include "lm_core.c" // read in core code
80
#undef LM_REAL_EPSILON
83
#endif /* LM_DBL_PREC */