33 using namespace gtsam;
37 if (get<0>(a) == get<0>(b) && get<1>(a) == get<1>(b) &&
38 get<2>(a) == get<2>(b))
return true;
40 cout <<
"not equal:" << endl;
41 cout <<
"\texpected: " 42 "(" << get<0>(
a) <<
", " << get<1>(a) <<
") = " << get<2>(
a) << endl;
44 "(" << get<0>(
b) <<
", " << get<1>(b) <<
") = " << get<2>(
b) << endl;
65 1., 2., 1., 2., 3., 4., 3., 4., 3., 4., 5., 6., 5., 6., 6., 7., 8., 7., 8., 7., 8.,
66 1., 2., 7., 7., 1., 2., 3., 4., 7., 7., 1., 2., 5., 6., 7., 3., 4., 5., 6., 7., 7.,
67 10., 10., -1., -1., -10., -10., 10., 10., 2., -1., -5., -5., 5., 5.,
68 1., -5., -5., 5., 5., -1., 1.5).finished();
99 4., 6.,32.).finished();
102 Matrix expectedMatlab = expected.transpose();
106 const Key x123 = 0, x45 = 1;
107 gfg.
add(x123, (
Matrix(2, 3) << 1, 2, 3, 5, 6, 7).finished(),
109 gfg.
add(x123, (
Matrix(2, 3) << 9, 10, 0, 0, 0, 0).finished(),
110 x45, (
Matrix(2, 2) << 11, 12, 14, 15.).finished(),
122 for (
int i = 0;
i < 16;
i++) {
138 Matrix A00 = (
Matrix(2, 3) << 1, 2, 3, 5, 6, 7).finished();
139 Matrix A10 = (
Matrix(2, 3) << 9, 10, 0, 0, 0, 0).finished();
145 gfg.
add(0, A10, 1, A11,
Vector2(13., 16.), model);
148 Ab << 1, 2, 3, 0, 0, 4, 5, 6, 7, 0, 0, 8, 9, 10, 0, 11, 12, 13, 0, 0, 0, 14, 15, 16;
155 Matrix A = Ab.leftCols(Ab.cols() - 1);
156 Vector b = Ab.col(Ab.cols() - 1);
157 const auto [actualA, actualb] = gfg.
jacobian();
163 Vector eta = A.transpose() *
b;
164 const auto [actualL, actualEta] = gfg.
hessian();
170 expectLdiagonal.
insert(0,
Vector3(1 + 25 + 81, 4 + 36 + 100, 9 + 49));
260 const auto [AtA, eta] = gfg.
hessian();
264 expectedAtA << 125, 0, -25, 0, -100, 0,
265 0, 125, 0, -25, 0, -100,
266 -25, 0, 50, 0, -25, 0,
267 0, -25, 0, 50, 0, -25,
268 -100, 0, -25, 0, 225, 0,
269 0, -100, 0, -25, 0, 225;
297 400 * I_2x2,
Vector2(1.0, 1.0), 3.0);
306 const auto [AtA, eta] = gfg.
hessian();
308 X << 1, 2, 3, 4, 5, 6;
310 Y << -450, -450, 300, 400, 2950, 3450;
332 const auto [AtA, eta] = gfg.
hessian();
354 blockMatrix.
matrix() << 1.0, 0.0, 2.0, 0.0, 3.0, 0.0, 0.1, 0.0, 1.0, 0.0, 2.0, 0.0, 3.0, 0.2, 0.0,
355 0.0, 3.0, 0.0, 4.0, 0.0, 0.3, 0.0, 0.0, 0.0, 3.0, 0.0, 4.0, 0.4;
359 init_graph.push_back(GaussianFactor::shared_ptr());
364 exp_graph.
push_back(GaussianFactor::shared_ptr());
371 JacobianFactor::shared_ptr jacFactor0 =
374 jacFactor0->getA(jacFactor0->begin()) *= 7.;
382 init_graph.
push_back(GaussianFactor::shared_ptr());
390 expNegation.
push_back(GaussianFactor::shared_ptr());
399 Vector d = infoMatrix.diagonal();
402 expected.
insert(0, d.segment<2>(0));
403 expected.
insert(1, d.segment<2>(2));
404 expected.
insert(2, d.segment<2>(4));
420 noiseModel::Isotropic::Sigma(1, 1.0));
Provides additional testing facilities for common data structures.
#define EQUALITY(expected, actual)
bool triplet_equal(SparseTriplet a, SparseTriplet b)
IsDerived< DERIVEDFACTOR > emplace_shared(Args &&... args)
Emplace a shared pointer to factor of given type.
double probPrime(const VectorValues &c) const
static int runAllTests(TestResult &result)
noiseModel::Diagonal::shared_ptr model
static GaussianFactorGraph createGaussianFactorGraphWithHessianFactor()
EIGEN_DONT_INLINE Scalar zero()
A matrix with column blocks of pre-defined sizes. Used in JacobianFactor and GaussianConditional.
IsDerived< DERIVEDFACTOR > push_back(std::shared_ptr< DERIVEDFACTOR > factor)
Add a factor directly using a shared_ptr.
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
std::pair< std::shared_ptr< BayesNetType >, std::shared_ptr< FactorGraphType > > eliminatePartialSequential(const Ordering &ordering, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex={}) const
const Matrix & matrix() const
Matrix augmentedHessian(const Ordering &ordering) const
Pose3 x2(Rot3::Ypr(0.0, 0.0, 0.0), l2)
iterator insert(const std::pair< Key, Vector > &key_value)
static GaussianFactorGraph createSimpleGaussianFactorGraph()
Factor graph with 2 2D factors on 3 2D variables.
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
double error(const VectorValues &x) const
#define EXPECT_DOUBLES_EQUAL(expected, actual, threshold)
VectorValues optimize(const Eliminate &function=EliminationTraitsType::DefaultEliminate) const
std::vector< std::tuple< int, int, double > > sparseJacobian(const Ordering &ordering, size_t &nrows, size_t &ncols) const
VariableSlots describes the structure of a combined factor in terms of where each block comes from in...
EIGEN_DEVICE_FUNC const ExpReturnType exp() const
GaussianFactorGraph negate() const
void add(const GaussianFactor &factor)
bool assert_inequal(const Matrix &A, const Matrix &B, double tol)
std::tuple< size_t, size_t, double > SparseTriplet
virtual std::map< Key, Matrix > hessianBlockDiagonal() const
#define EXPECT(condition)
virtual GaussianFactorGraph clone() const
Array< double, 1, 3 > e(1./3., 0.5, 2.)
Conditional Gaussian Base class.
Linear Factor Graph where all factors are Gaussians.
void multiplyHessianAdd(double alpha, const VectorValues &x, VectorValues &y) const
virtual VectorValues hessianDiagonal() const
Matrix augmentedJacobian(const Ordering &ordering) const
#define LONGS_EQUAL(expected, actual)
std::pair< Matrix, Vector > hessian(const Ordering &ordering) const
noiseModel::Diagonal::shared_ptr SharedDiagonal
TEST(GaussianFactorGraph, initialization)
VectorValues transposeMultiply(const Errors &e) const
VectorValues optimizeDensely() const
#define EXPECT_LONGS_EQUAL(expected, actual)
std::pair< Matrix, Vector > jacobian(const Ordering &ordering) const
const sharedFactor at(size_t i) const
A Gaussian factor using the canonical parameters (information form)
Chordal Bayes Net, the result of eliminating a factor graph.
void insert(Key j, const Value &val)
VectorValues gradient(const VectorValues &x0) const
Matrix sparseJacobian_() const
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > Matrix
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
virtual VectorValues gradientAtZero() const
std::uint64_t Key
Integer nonlinear key type.