27 template <
class VECTORLIKE,
class VECTORLIKE2,
class VECTORLIKE3,
28 class MATRIXLIKE,
class USERPARAM>
31 const std::function<
void(
32 const VECTORLIKE&
x,
const USERPARAM&
y, VECTORLIKE3& out)>& functor,
33 const VECTORLIKE2& increments,
const USERPARAM& userParam,
34 MATRIXLIKE& out_Jacobian)
37 ASSERT_(
x.size() > 0 && increments.size() ==
x.size());
40 const size_t n =
x.size();
42 for (
size_t j = 0; j <
n; j++)
47 VECTORLIKE3 f_minus, f_plus;
51 for (
size_t j = 0; j <
n; j++)
54 x_mod[j] =
x[j] + increments[j];
55 functor(x_mod, userParam, f_plus);
57 x_mod[j] =
x[j] - increments[j];
58 functor(x_mod, userParam, f_minus);
61 const double Ax_2_inv = 0.5 / increments[j];
67 out_Jacobian.setSize(m,
n);
70 for (
size_t i = 0; i < m; i++)
71 out_Jacobian.get_unsafe(i, j) = Ax_2_inv * (f_plus[i] - f_minus[i]);
void estimateJacobian(const VECTORLIKE &x, const std::function< void(const VECTORLIKE &x, const USERPARAM &y, VECTORLIKE3 &out)> &functor, const VECTORLIKE2 &increments, const USERPARAM &userParam, MATRIXLIKE &out_Jacobian)
Estimate the Jacobian of a multi-dimensional function around a point "x", using finite differences of...
#define ASSERT_(f)
Defines an assertion mechanism.
This base provides a set of functions for maths stuff.