aboutsummaryrefslogtreecommitdiffhomepage
path: root/unsupported/Eigen/NonLinear
blob: dbb9e8703a78bac36dae2b1dc1831838dc85d24b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// Copyright (C) 2009 Thomas Capricelli <orzel@freehackers.org>
//
// Eigen is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
//
// Alternatively, you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of
// the License, or (at your option) any later version.
//
// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License and a copy of the GNU General Public License along with
// Eigen. If not, see <http://www.gnu.org/licenses/>.


#ifndef EIGEN_NONLINEAR_MODULE_H
#define EIGEN_NONLINEAR_MODULE_H

#include <Eigen/Core>

namespace Eigen {

/** \ingroup Unsupported_modules
  * \defgroup Support for non linear optimization and non linear least
  * square using minpack routines.
  */
//@{

#define min(a,b) ((a) <= (b) ? (a) : (b))
#define max(a,b) ((a) >= (b) ? (a) : (b))
#define abs(x) ((x) >= 0 ? (x) : -(x))
#define TRUE_ (1)
#define FALSE_ (0)
#define p1 .1
#define p5 .5
#define p25 .25
#define p75 .75
#define p001 .001
#define p0001 1e-4

#if 1
#include <cminpack.h>
#else

/* Declarations for minpack */
typedef int (*minpack_func_nn)(void *p, int n, const double *x, double *fvec, int iflag );
typedef int (*minpack_funcder_nn)(void *p, int n, const double *x, double *fvec, double *fjac, int ldfjac, int iflag );
typedef int (*minpack_func_mn)(void *p, int m, int n, const double *x, double *fvec, int iflag );
typedef int (*minpack_funcder_mn)(void *p, int m, int n, const double *x, double *fvec, double *fjac, int ldfjac, int iflag );
typedef int (*minpack_funcderstr_mn)(void *p, int m, int n, const double *x, double *fvec, double *fjrow, int iflag );

/* MINPACK functions: */
int hybrd1 ( minpack_func_nn fcn, void *p, int n, double *x, double *fvec, double tol,
	       double *wa, int lwa );
int hybrd ( minpack_func_nn fcn,
	      void *p, int n, double *x, double *fvec, double xtol, int maxfev,
	      int ml, int mu, double epsfcn, double *diag, int mode,
	      double factor, int nprint, int *nfev,
	      double *fjac, int ldfjac, double *r, int lr, double *qtf,
	      double *wa1, double *wa2, double *wa3, double *wa4);
  
int hybrj1 ( minpack_funcder_nn fcn, void *p, int n, double *x,
	       double *fvec, double *fjac, int ldfjac, double tol,
	       double *wa, int lwa );
int hybrj ( minpack_funcder_nn fcn, void *p, int n, double *x,
	      double *fvec, double *fjac, int ldfjac, double xtol,
	      int maxfev, double *diag, int mode, double factor,
	      int nprint, int *nfev, int *njev, double *r,
	      int lr, double *qtf, double *wa1, double *wa2,
	      double *wa3, double *wa4 );

int lmdif1 ( minpack_func_mn fcn,
	       void *p, int m, int n, double *x, double *fvec, double tol,
	       int *iwa, double *wa, int lwa );
int lmdif ( minpack_func_mn fcn,
	      void *p, 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 nprint,
	      int *nfev, double *fjac, int ldfjac, int *ipvt,
	      double *qtf, double *wa1, double *wa2, double *wa3,
	      double *wa4 );

int lmder1 ( minpack_funcder_mn fcn,
	       void *p, int m, int n, double *x, double *fvec, double *fjac,
	       int ldfjac, double tol, int *ipvt,
	       double *wa, int lwa );
int lmder ( minpack_funcder_mn fcn,
	      void *p, int m, int n, double *x, double *fvec, double *fjac,
	      int ldfjac, double ftol, double xtol, double gtol,
	      int maxfev, double *diag, int mode, double factor,
	      int nprint, int *nfev, int *njev, int *ipvt,
	      double *qtf, double *wa1, double *wa2, double *wa3,
	      double *wa4 );

int lmstr1 ( minpack_funcderstr_mn fcn, void *p, int m, int n,
	       double *x, double *fvec, double *fjac, int ldfjac,
	       double tol, int *ipvt, double *wa, int lwa );
int lmstr (  minpack_funcderstr_mn fcn, void *p, int m,
	      int n, double *x, double *fvec, double *fjac,
	      int ldfjac, double ftol, double xtol, double gtol,
	      int maxfev, double *diag, int mode, double factor,
	      int nprint, int *nfev, int *njev, int *ipvt,
	      double *qtf, double *wa1, double *wa2, double *wa3,
	      double *wa4 );
 
void chkder ( int m, int n, const double *x, double *fvec, double *fjac,
	       int ldfjac, double *xp, double *fvecp, int mode,
	       double *err  );

void covar(int n, double *r__, int ldr, const int *ipvt, double tol, double *wa);
#endif


template<typename Scalar>
Scalar ei_enorm ( int n, const Scalar *x ){
    return Map< Matrix< Scalar, Dynamic, 1 > >(x,n).stableNorm();
//    return Map< Matrix< Scalar, Dynamic, 1 > >(x,n).blueNorm();
}

#include "src/NonLinear/lmder.h"
#include "src/NonLinear/hybrd1.h"
#include "src/NonLinear/hybrd.h"
#include "src/NonLinear/lmstr.h"
#include "src/NonLinear/lmdif1.h"
#include "src/NonLinear/lmdif.h"
#include "src/NonLinear/hybrj1.h"
#include "src/NonLinear/hybrj.h"
#include "src/NonLinear/chkder.h"
#include "src/NonLinear/MathFunctions.h"
#include "src/NonLinear/lmder1.h"
#include "src/NonLinear/lmstr1.h"

//@}

}



#endif // EIGEN_NONLINEAR_MODULE_H