10 #ifndef EIGEN_FINITEDIFF_CHAIN_HESSIAN_H_ 11 #define EIGEN_FINITEDIFF_CHAIN_HESSIAN_H_ 21 template <
typename Functor, NumericalDiffMode mode = Forward>
27 typedef typename ValueType::Scalar
Scalar;
36 typedef Matrix<Scalar, ValuesAtCompileTime, JacobianInputsAtCompileTime>
JacobianType;
39 typedef typename JacobianType::Index
Index;
43 UpdateFunctionCallbackType
update_ = [](
const InputJacobianRowType &jx, InputType &
x) {
x = jx; };
50 #if EIGEN_HAS_VARIADIC_TEMPLATES 51 template <
typename... T>
55 template <
typename... T>
60 template <
typename T0>
64 template <
typename T0,
typename T1>
68 template <
typename T0,
typename T1,
typename T2>
73 template <
typename T0>
77 template <
typename T0,
typename T1>
78 FiniteDiffChainHessian(UpdateFunctionCallbackType update, Scalar epsfcn = 0.,
const T0 &a0,
const T1 &a1) :
Functor(a0, a1), update_(update), epsfcn_(epsfcn)
81 template <
typename T0,
typename T1,
typename T2>
82 FiniteDiffChainHessian(UpdateFunctionCallbackType update, Scalar epsfcn = 0.,
const T0 &a0,
const T1 &a1,
const T2 &a2) :
Functor(a0, a1, a2), update_(update), epsfcn_(epsfcn)
87 #if EIGEN_HAS_VARIADIC_TEMPLATES 91 int operator()(
const InputJacobianRowType &_jx, ValueType &v)
const 99 template <
typename... ParamsType>
100 int operator()(
const InputJacobianRowType &_jx, ValueType &v,
const ParamsType &... Params)
const 108 template <
typename... ParamsType>
109 int operator()(
const InputJacobianRowType &_jx, ValueType &v, JacobianType &jac,
const ParamsType &... Params)
const 112 return autoj(_jx, v, jac, Params...);
115 template <
typename... ParamsType>
116 int operator()(
const InputJacobianRowType &_jx, ValueType &v, JacobianType &jac, HessianType &hess,
const ParamsType &... Params)
const 119 int operator()(
const InputJacobianRowType &_jx, ValueType &v)
const 127 int operator()(
const InputJacobianRowType &_jx, ValueType &v, JacobianType &jac)
const 130 return autoj(_jx, v, jac);
133 int operator()(
const InputJacobianRowType &_jx, ValueType &v, JacobianType &jac, HessianType &hess)
const 142 const typename InputJacobianRowType::Index
n = _jx.size();
143 const typename ValueType::Index m = jac.rows();
144 const Scalar eps =
sqrt(((std::max)(epsfcn_, NumTraits<Scalar>::epsilon())));
145 JacobianType jac1(jac.rows(), jac.cols()), jac2(jac.rows(), jac.cols());
146 InputJacobianRowType jx = _jx;
148 Index cols = jac.cols();
152 for (Index i = 0; i < m; ++i)
154 hess[i].resize(cols, cols);
159 #if EIGEN_HAS_VARIADIC_TEMPLATES 160 nfev += autoj(_jx, v, jac, Params...);
162 nfev += autoj(_jx, v, jac);
179 for (
int j = 0; j <
n; ++j)
181 h = eps *
abs(jx[j]);
191 #if EIGEN_HAS_VARIADIC_TEMPLATES 192 nfev += autoj(jx, _v, jac2, Params...);
194 nfev += autoj(jx, _v, jac2);
197 for (
int l = 0; l < m; ++l)
199 hess[l].row(j) = (jac2.row(l) - jac1.row(l)) / h;
204 #if EIGEN_HAS_VARIADIC_TEMPLATES 205 nfev += autoj(jx, _v, jac2, Params...);
207 nfev += autoj(jx, _v, jac2);
210 #if EIGEN_HAS_VARIADIC_TEMPLATES 211 nfev += autoj(jx, _v, jac1, Params...);
213 nfev += autoj(jx, _v, jac1);
216 for (
int l = 0; l < m; ++l)
218 hess[l].col(j) = (jac2.row(l) - jac1.row(l)) / (2.0 * h);
230 #endif // EIGEN_FINITEDIFF_CHAIN_HESSIAN_H_ Matrix< Scalar, ValuesAtCompileTime, JacobianInputsAtCompileTime > JacobianType
UpdateFunctionCallbackType update_
FiniteDiffChainHessian(UpdateFunctionCallbackType update, Scalar epsfcn=0., const T0 &a0, const T1 &a1)
FiniteDiffChainHessian(const T0 &a0, const T1 &a1, Scalar epsfcn=0.)
FunctorBase< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::Dynamic > Functor
FiniteDiffChainHessian(const Functor &f, Scalar epsfcn=0.)
FiniteDiffChainHessian(UpdateFunctionCallbackType update, Scalar epsfcn=0., const T0 &a0)
void update(const std::string &key, const XmlRpc::XmlRpcValue &v)
Functor::InputType InputType
FiniteDiffChainHessian(const T0 &a0, Scalar epsfcn=0.)
Functor::ValueType ValueType
FiniteDiffChainHessian(UpdateFunctionCallbackType update, Scalar epsfcn=0., const T0 &a0, const T1 &a1, const T2 &a2)
INLINE Rall1d< T, V, S > sqrt(const Rall1d< T, V, S > &arg)
JacobianType::Index Index
Array< Matrix< Scalar, JacobianInputsAtCompileTime, JacobianInputsAtCompileTime >, ValuesAtCompileTime, 1 > HessianType
int operator()(const InputJacobianRowType &_jx, ValueType &v, JacobianType &jac, HessianType &hess) const
std::function< void(const InputJacobianRowType &, InputType &)> UpdateFunctionCallbackType
INLINE Rall1d< T, V, S > abs(const Rall1d< T, V, S > &x)
Matrix< Scalar, JacobianInputsAtCompileTime, 1 > InputJacobianRowType
EIGEN_STRONG_INLINE int operator()(const InputJacobianRowType &_jx, ValueType &v) const
FiniteDiffChainHessian(Scalar epsfcn=0.)
FiniteDiffChainHessian(const Functor &f, UpdateFunctionCallbackType update, Scalar epsfcn=0.)
int operator()(const InputJacobianRowType &_jx, ValueType &v, JacobianType &jac) const
FiniteDiffChainHessian(const T0 &a0, const T1 &a1, const T2 &a2, Scalar epsfcn=0.)