32 bool useCostFunctionsJacobian)
33 : epsfcn_(epsfcn), xtol_(xtol), gtol_(gtol),
34 useCostFunctionsJacobian_(useCostFunctionsJacobian) {}
53 std::unique_ptr<Real[]> xx(
new Real[
n]);
54 std::copy(
x_.begin(),
x_.end(), xx.get());
55 std::unique_ptr<Real[]> fvec(
new Real[m]);
56 std::unique_ptr<Real[]> diag(
new Real[
n]);
62 std::unique_ptr<Real[]> fjac(
new Real[m*
n]);
64 std::unique_ptr<int[]> ipvt(
new int[
n]);
65 std::unique_ptr<Real[]> qtf(
new Real[
n]);
66 std::unique_ptr<Real[]> wa1(
new Real[
n]);
67 std::unique_ptr<Real[]> wa2(
new Real[
n]);
68 std::unique_ptr<Real[]> wa3(
new Real[
n]);
69 std::unique_ptr<Real[]> wa4(
new Real[m]);
73 "less functions (" << m <<
74 ") than available variables (" <<
n <<
")");
76 "negative f tolerance");
80 "null number of evaluations");
85 [
this](
const auto m,
const auto n,
const auto x,
const auto fvec,
const auto iflag) {
86 this->
fcn(m,
n, x, fvec, iflag);
90 ? [
this](
const auto m,
const auto n,
const auto x,
const auto fjac,
const auto iflag) {
91 this->
jacFcn(m,
n, x, fjac, iflag);
100 diag.get(), mode, factor,
101 nprint, &info, &nfev, fjac.get(),
102 ldfjac, ipvt.get(), qtf.get(),
103 wa1.get(), wa2.get(), wa3.get(), wa4.get(),
108 QL_REQUIRE(info != 0,
"MINPACK: improper input parameters");
116 QL_REQUIRE(info != 7,
"MINPACK: xtol is too small. no further "
117 "improvement in the approximate "
118 "solution x is possible.");
119 QL_REQUIRE(info != 8,
"MINPACK: gtol is too small. fvec is "
120 "orthogonal to the columns of the "
121 "jacobian to machine precision.");
123 std::copy(xx.get(), xx.get()+
n,
x_.begin());
132 std::copy(x, x+
n, xt.
begin());
137 std::copy(tmp.
begin(), tmp.
end(), fvec);
145 std::copy(x, x+
n, xt.
begin());
152 std::copy(tmpT.
begin(), tmpT.
end(), fjac);
155 std::copy(tmpT.
begin(), tmpT.
end(), fjac);
1-D array used in linear algebra.
const_iterator end() const
Size size() const
dimension of the array
const_iterator begin() const
bool test(const Array &p) const
virtual Array values(const Array &x) const =0
method to overload to compute the cost function values in x
virtual Real value(const Array &x) const
method to overload to compute the cost function value in x
virtual void jacobian(Matrix &jac, const Array &x) const
method to overload to compute J_f, the jacobian of
Criteria to end optimization process:
@ StationaryFunctionValue
Real functionEpsilon() const
Size maxIterations() const
bool checkMaxIterations(Size iteration, EndCriteria::Type &ecType) const
void fcn(int m, int n, Real *x, Real *fvec, int *iflag)
virtual Integer getInfo() const
LevenbergMarquardt(Real epsfcn=1.0e-8, Real xtol=1.0e-8, Real gtol=1.0e-8, bool useCostFunctionsJacobian=false)
Problem * currentProblem_
void jacFcn(int m, int n, Real *x, Real *fjac, int *iflag)
bool useCostFunctionsJacobian_
EndCriteria::Type minimize(Problem &P, const EndCriteria &endCriteria) override
minimize the optimization problem P
Matrix used in linear algebra.
const_iterator begin() const
const_iterator end() const
Constrained optimization problem.
const Array & currentValue() const
current value of the local minimum
Constraint & constraint() const
Constraint.
Array values(const Array &x)
call cost values computation and increment evaluation counter
void setFunctionValue(Real functionValue)
CostFunction & costFunction() const
Cost function.
void setCurrentValue(const Array ¤tValue)
Abstract constraint class.
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Maps function, bind and cref to either the boost or std implementation.
QL_INTEGER Integer
integer number
Levenberg-Marquardt optimization method.
wrapper for MINPACK minimization routine
void lmdif(int m, int n, Real *x, Real *fvec, Real ftol, Real xtol, Real gtol, int maxfev, Real epsfcn, Real *diag, int mode, Real factor, int nprint, int *info, int *nfev, Real *fjac, int ldfjac, int *ipvt, Real *qtf, Real *wa1, Real *wa2, Real *wa3, Real *wa4, const QuantLib::MINPACK::LmdifCostFunction &fcn, const QuantLib::MINPACK::LmdifCostFunction &jacFcn)
ext::function< void(int, int, Real *, Real *, int *)> LmdifCostFunction
Matrix transpose(const Matrix &m)