43 std::vector<std::pair<Key, Matrix> > jacobians;
47 const size_t rows = e.size();
50 const double one_over_2delta = 1.0 / (2.0 *
delta);
55 Matrix J = Matrix::Zero(rows, cols);
57 Vector dx = Vector::Zero(cols);
61 const Vector left = factor.whitenedError(eval_values);
64 eval_values = values.
retract(dX);
65 const Vector right = factor.whitenedError(eval_values);
66 J.col(
col) = (left -
right) * one_over_2delta;
68 jacobians.emplace_back(
key, J);
87 if (!actual)
return false;
94 for (
size_t i = 0;
i < actual->size();
i++) {
97 (
Matrix)(actual->getA(actual->begin() +
i)), tolerance);
99 std::cout <<
"Mismatch in Jacobian " <<
i + 1
100 <<
" (base 1), as shown above" << std::endl;
114 #define EXPECT_CORRECT_FACTOR_JACOBIANS(factor, values, numerical_derivative_step, tolerance) \ 115 { EXPECT(gtsam::internal::testFactorJacobians(name_, factor, values, numerical_derivative_step, tolerance)); } const gtsam::Symbol key('X', 0)
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Some functions to compute numerical derivatives.
bool testFactorJacobians(const std::string &name_, const NoiseModelFactor &factor, const gtsam::Values &values, double delta, double tolerance)
Values retract(const VectorValues &delta) const
JacobianFactor linearizeNumerically(const NoiseModelFactor &factor, const Values &values, double delta=1e-5)
VectorValues zeroVectors() const
Array< double, 1, 3 > e(1./3., 0.5, 2.)
JacobiRotation< float > J
std::shared_ptr< GaussianFactor > linearize(const Values &x) const override
Non-linear factor base classes.
const_iterator begin() const
bool equal(const T &obj1, const T &obj2, double tol)
Vector whitenedError(const Values &c) const
std::uint64_t Key
Integer nonlinear key type.
constABlock getA(const_iterator variable) const