Slight refactor of numerical derivatives
parent
2972671064
commit
7018afdd58
|
@ -318,20 +318,19 @@ Matrix numericalDerivative(boost::function<Y(const X&)> h, const X& x,
|
||||||
double delta = 1e-5) {
|
double delta = 1e-5) {
|
||||||
Y hx = h(x);
|
Y hx = h(x);
|
||||||
double factor = 1.0 / (2.0 * delta);
|
double factor = 1.0 / (2.0 * delta);
|
||||||
static const size_t m = manifold_traits<Y>::dimension, n =
|
static const size_t M = manifold_traits<Y>::dimension;
|
||||||
manifold_traits<X>::dimension;
|
static const size_t N = manifold_traits<X>::dimension;
|
||||||
Eigen::Matrix<double, n, 1> d;
|
Eigen::Matrix<double, N, 1> d;
|
||||||
|
Matrix H = zeros(M, N);
|
||||||
|
for (size_t j = 0; j < N; j++) {
|
||||||
d.setZero();
|
d.setZero();
|
||||||
Matrix H = zeros(m, n);
|
d(j) = delta;
|
||||||
for (size_t j = 0; j < n; j++) {
|
|
||||||
d(j) += delta;
|
|
||||||
Vector hxplus = manifold_traits<Y>::localCoordinates(hx,
|
Vector hxplus = manifold_traits<Y>::localCoordinates(hx,
|
||||||
h(manifold_traits<X>::retract(x, d)));
|
h(manifold_traits<X>::retract(x, d)));
|
||||||
d(j) -= 2 * delta;
|
d(j) = -delta;
|
||||||
Vector hxmin = manifold_traits<Y>::localCoordinates(hx,
|
Vector hxmin = manifold_traits<Y>::localCoordinates(hx,
|
||||||
h(manifold_traits<X>::retract(x, d)));
|
h(manifold_traits<X>::retract(x, d)));
|
||||||
d(j) += delta;
|
H.block<M, 1>(0, j) << (hxplus - hxmin) * factor;
|
||||||
H.block<m, 1>(0, j) << (hxplus - hxmin) * factor;
|
|
||||||
}
|
}
|
||||||
return H;
|
return H;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue