mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-06-21 08:53:17 +08:00
porting hybrd1 to eigen
This commit is contained in:
parent
de7d14b2b3
commit
6027c4bedf
@ -128,7 +128,6 @@ Scalar ei_enorm ( int n, const Scalar *x ){
|
|||||||
}
|
}
|
||||||
|
|
||||||
#include "src/NonLinear/lmder.h"
|
#include "src/NonLinear/lmder.h"
|
||||||
#include "src/NonLinear/hybrd1.h"
|
|
||||||
#include "src/NonLinear/hybrd.h"
|
#include "src/NonLinear/hybrd.h"
|
||||||
#include "src/NonLinear/lmstr.h"
|
#include "src/NonLinear/lmstr.h"
|
||||||
#include "src/NonLinear/lmdif1.h"
|
#include "src/NonLinear/lmdif1.h"
|
||||||
@ -139,6 +138,7 @@ Scalar ei_enorm ( int n, const Scalar *x ){
|
|||||||
#include "src/NonLinear/MathFunctions.h"
|
#include "src/NonLinear/MathFunctions.h"
|
||||||
#include "src/NonLinear/lmder1.h"
|
#include "src/NonLinear/lmder1.h"
|
||||||
#include "src/NonLinear/lmstr1.h"
|
#include "src/NonLinear/lmstr1.h"
|
||||||
|
#include "src/NonLinear/hybrd1.h"
|
||||||
|
|
||||||
//@}
|
//@}
|
||||||
|
|
||||||
|
@ -25,20 +25,6 @@
|
|||||||
#ifndef EIGEN_NONLINEAR_MATHFUNCTIONS_H
|
#ifndef EIGEN_NONLINEAR_MATHFUNCTIONS_H
|
||||||
#define EIGEN_NONLINEAR_MATHFUNCTIONS_H
|
#define EIGEN_NONLINEAR_MATHFUNCTIONS_H
|
||||||
|
|
||||||
template<typename Functor, typename Scalar>
|
|
||||||
int ei_hybrd1(
|
|
||||||
Matrix< Scalar, Dynamic, 1 > &x,
|
|
||||||
Matrix< Scalar, Dynamic, 1 > &fvec,
|
|
||||||
Scalar tol = ei_sqrt(epsilon<Scalar>())
|
|
||||||
)
|
|
||||||
{
|
|
||||||
int lwa = (x.size()*(3*x.size()+13))/2;
|
|
||||||
Matrix< Scalar, Dynamic, 1 > wa(lwa);
|
|
||||||
|
|
||||||
fvec.resize(x.size());
|
|
||||||
return hybrd1_template<Scalar>(Functor::f, 0, x.size(), x.data(), fvec.data(), tol, wa.data(), lwa);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Functor, typename Scalar>
|
template<typename Functor, typename Scalar>
|
||||||
int ei_hybrd(
|
int ei_hybrd(
|
||||||
Matrix< Scalar, Dynamic, 1 > &x,
|
Matrix< Scalar, Dynamic, 1 > &x,
|
||||||
|
@ -1,63 +1,34 @@
|
|||||||
|
|
||||||
template<typename Scalar>
|
template<typename Functor, typename Scalar>
|
||||||
int hybrd1_template(minpack_func_nn fcn, void *p, int n, Scalar *x, Scalar *
|
int ei_hybrd1(
|
||||||
fvec, Scalar tol, Scalar *wa, int lwa)
|
Matrix< Scalar, Dynamic, 1 > &x,
|
||||||
|
Matrix< Scalar, Dynamic, 1 > &fvec,
|
||||||
|
Scalar tol = ei_sqrt(epsilon<Scalar>())
|
||||||
|
)
|
||||||
{
|
{
|
||||||
/* Initialized data */
|
const int n = x.size();
|
||||||
|
int info, nfev;
|
||||||
const Scalar factor = 100.;
|
Matrix< Scalar, Dynamic, Dynamic > fjac;
|
||||||
|
Matrix< Scalar, Dynamic, 1> R, qtf, diag;
|
||||||
/* System generated locals */
|
|
||||||
int i__1;
|
|
||||||
|
|
||||||
/* Local variables */
|
|
||||||
int j, ml, lr, mu, mode, nfev;
|
|
||||||
Scalar xtol;
|
|
||||||
int index;
|
|
||||||
Scalar epsfcn;
|
|
||||||
int maxfev, nprint;
|
|
||||||
int info;
|
|
||||||
|
|
||||||
/* Parameter adjustments */
|
|
||||||
--fvec;
|
|
||||||
--x;
|
|
||||||
--wa;
|
|
||||||
|
|
||||||
/* Function Body */
|
|
||||||
info = 0;
|
|
||||||
|
|
||||||
/* check the input parameters for errors. */
|
/* check the input parameters for errors. */
|
||||||
|
if (n <= 0 || tol < 0.) {
|
||||||
if (n <= 0 || tol < 0. || lwa < n * (n * 3 + 13) / 2) {
|
printf("ei_hybrd1 bad args : n,tol,...");
|
||||||
/* goto L20; */
|
return 0;
|
||||||
return info;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* call hybrd. */
|
diag.setConstant(n, 1.);
|
||||||
|
info = ei_hybrd<Functor,Scalar>(
|
||||||
maxfev = (n + 1) * 200;
|
x, fvec,
|
||||||
xtol = tol;
|
nfev,
|
||||||
ml = n - 1;
|
fjac,
|
||||||
mu = n - 1;
|
R, qtf, diag,
|
||||||
epsfcn = 0.;
|
2,
|
||||||
mode = 2;
|
-1, -1,
|
||||||
i__1 = n;
|
(n+1)*200,
|
||||||
for (j = 1; j <= i__1; ++j) {
|
100.,
|
||||||
wa[j] = 1.;
|
tol, Scalar(0.)
|
||||||
/* L10: */
|
);
|
||||||
}
|
return (info==5)?4:info;
|
||||||
nprint = 0;
|
|
||||||
lr = n * (n + 1) / 2;
|
|
||||||
index = n * 6 + lr;
|
|
||||||
info = hybrd(fcn, p, n, &x[1], &fvec[1], xtol, maxfev, ml, mu, epsfcn, &
|
|
||||||
wa[1], mode, factor, nprint, &nfev, &wa[index + 1], n, &
|
|
||||||
wa[n * 6 + 1], lr, &wa[n + 1], &wa[(n << 1) + 1], &wa[n * 3
|
|
||||||
+ 1], &wa[(n << 2) + 1], &wa[n * 5 + 1]);
|
|
||||||
if (info == 5) {
|
|
||||||
info = 4;
|
|
||||||
}
|
|
||||||
/* L20: */
|
|
||||||
return info;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user