19 using namespace gtsam;
30 TEST(TestLinearContainerFactor, generic_jacobian_factor) {
34 0.0, 2.63624).finished();
36 -0.0455167, -0.0443573,
37 -0.0222154, -0.102489).finished();
58 GaussianFactor::shared_ptr actLinearizationA = actFactor.
linearize(values);
63 TEST(TestLinearContainerFactor, jacobian_factor_withlinpoints) {
67 0.0, 2.63624).finished();
69 -0.0455167, -0.0443573,
70 -0.0222154, -0.102489).finished();
102 delta.
at(l1) = delta_l1;
103 delta.
at(
l2) = delta_l2;
105 double expError = expLinFactor.
error(delta);
110 GaussianFactor::shared_ptr actLinearizationB = actFactor.
linearize(noisyValues);
111 Vector bprime = b - A1 * delta_l1 - A2 * delta_l2;
117 TEST(TestLinearContainerFactor, generic_hessian_factor) {
120 Matrix G13 = (
Matrix(1, 3) << 3.0, 6.0, 9.0).finished();
123 0.0, 6.0).finished();
125 1.0, 2.0, 4.0).finished();
129 0.0, 0.0, 9.0).finished();
138 G11, G12, G13, g1, G22, G23, g2, G33, g3, f);
150 GaussianFactor::shared_ptr actLinearization1 = actFactor.
linearize(values);
155 TEST(TestLinearContainerFactor, hessian_factor_withlinpoints) {
162 0.0, 0.0, 9.0).finished();
166 4.0, 6.0).finished();
171 0.0, 0.6).finished();
179 G << G11, G12, Matrix::Zero(2,3), G22;
183 Values linearizationPoint, expLinPoints;
186 expLinPoints = linearizationPoint;
204 delta.
at(l1) = delta_l1;
205 delta.
at(
x1) = delta_x1;
206 delta.
at(
x2) = delta_x2;
210 double expError = initFactor.
error(delta);
215 Vector dv = (
Vector(5) << 3.0, 4.0, 0.5, 1.0, 2.0).finished();
220 Vector g1_prime = g_prime.head(3);
221 Vector g2_prime = g_prime.tail(2);
222 double f_prime = f + dv.transpose() * G.selfadjointView<
Eigen::Upper>() * dv - 2.0 * dv.transpose() *
g;
223 HessianFactor expNewFactor(
x1, l1, G11, G12, g1_prime, G22, g2_prime, f_prime);
228 TEST(TestLinearContainerFactor, Creation) {
230 Key l1 = 11,
l3 = 13, l5 = 15;
235 l3, I_2x2, l5, 2.0 * I_2x2,
Z_2x1, model));
241 exp_values = full_values;
254 TEST(TestLinearContainerFactor, jacobian_relinearize)
277 double expected_error = betweenFactor.
error(linpoint2);
278 double actual_error = jacobianContainer.
error(linpoint2);
288 TEST(TestLinearContainerFactor, hessian_relinearize)
311 double expected_error = betweenFactor.
error(linpoint2);
312 double actual_error = hessianContainer.
error(linpoint2);
322 TEST(TestLinearContainerFactor, Rekey) {
324 auto nonlinear_factor =
325 std::make_shared<gtsam::BetweenFactor<gtsam::Point3>>(
335 nonlinear_factor->linearize(linearization_pt), linearization_pt);
338 std::map<gtsam::Key, gtsam::Key> key_map;
344 auto lcf_factor_rekeyed = lcf_factor.rekey(key_map);
349 CHECK(lcf_factor_rekey_ptr);
353 for (
auto key : linearization_pt.keys()) {
354 linearization_pt_rekeyed.
insert(key_map.at(
key), linearization_pt.at(
key));
364 TEST(TestLinearContainerFactor, Rekey2) {
366 auto nonlinear_factor =
367 std::make_shared<gtsam::BetweenFactor<gtsam::Point3>>(
377 nonlinear_factor->linearize(linearization_pt), linearization_pt);
381 std::map<gtsam::Key, gtsam::Key> key_map;
387 lcf_factor.rekey(key_map));
388 CHECK(lcf_factor_rekey_ptr);
const gtsam::Symbol key('X', 0)
Provides additional testing facilities for common data structures.
const gtsam::noiseModel::Diagonal::shared_ptr diag_model2
Pose2 poseA2(2.0, 0.0, 0.0)
static int runAllTests(TestResult &result)
double error(const VectorValues &c) const override
Pose2 poseA1(0.0, 0.0, 0.0)
Wrap Jacobian and Hessian linear factors to allow simple injection into a nonlinear graph...
std::shared_ptr< This > shared_ptr
A shared_ptr to this class.
JacobiRotation< float > G
noiseModel::Diagonal::shared_ptr model
const std::optional< Values > & linearizationPoint() const
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
GaussianFactor::shared_ptr clone() const override
Point2 landmark1(5.0, 1.5)
#define EXPECT_DOUBLES_EQUAL(expected, actual, threshold)
void g(const string &key, int i)
bool assert_container_equality(const std::map< size_t, V2 > &expected, const std::map< size_t, V2 > &actual)
Values retract(const VectorValues &delta) const
double error(const VectorValues &c) const override
bool assert_inequal(const Matrix &A, const Matrix &B, double tol)
Point2 landmark2(7.0, 1.5)
const Symbol key1('v', 1)
GaussianFactor::shared_ptr clone() const override
VectorValues zeroVectors() const
#define EXPECT(condition)
std::shared_ptr< This > shared_ptr
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Contains the HessianFactor class, a general quadratic factor.
Array< double, 1, 3 > e(1./3., 0.5, 2.)
std::shared_ptr< This > shared_ptr
shared_ptr to this class
std::shared_ptr< GaussianFactor > linearize(const Values &x) const override
std::shared_ptr< This > shared_ptr
shared_ptr to this class
noiseModel::Diagonal::shared_ptr SharedDiagonal
bool hasLinearizationPoint() const
Casting syntactic sugar.
double error(const Values &c) const override
#define EXPECT_LONGS_EQUAL(expected, actual)
Pose3 g1(Rot3(), Point3(100.0, 0.0, 300.0))
A Gaussian factor using the canonical parameters (information form)
const KeyVector & keys() const
Access the factor's involved variable keys.
void insert(Key j, const Value &val)
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > Matrix
std::shared_ptr< Diagonal > shared_ptr
Pose3 g2(g1.expmap(h *V1_g1))
GaussianFactor::shared_ptr linearize(const Values &c) const override
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
double error(const Values &c) const override
static const Eigen::MatrixBase< Vector2 >::ConstantReturnType Z_2x1
std::uint64_t Key
Integer nonlinear key type.
TEST(TestLinearContainerFactor, generic_jacobian_factor)
noiseModel::Base::shared_ptr SharedNoiseModel
static shared_ptr Sigma(size_t dim, double sigma, bool smart=true)
const Symbol key2('v', 2)