27 #include <boost/assign/list_of.hpp> 28 #include <boost/range/adaptor/map.hpp> 33 using namespace gtsam;
34 using boost::shared_ptr;
47 boost::optional<Values&> init_values = boost::none,
48 boost::optional<NonlinearFactorGraph&> full_graph = boost::none,
51 ISAM2Params::CHOLESKY,
true,
53 size_t maxPoses = 10) {
72 isam.
update(newfactors, init);
85 init.
insert((i+1),
Pose2(
double(i+1)+0.1, -0.1, 0.01));
86 fullinit.
insert((i+1),
Pose2(
double(i+1)+0.1, -0.1, 0.01));
88 isam.
update(newfactors, init);
113 isam.
update(newfactors, init);
127 init.
insert((i+1),
Pose2(
double(i+1)+0.1, -0.1, 0.01));
128 fullinit.
insert((i+1),
Pose2(
double(i+1)+0.1, -0.1, 0.01));
130 isam.
update(newfactors, init);
151 isam.
update(newfactors, init);
158 *full_graph = fullgraph;
161 *init_values = fullinit;
205 consistent(true), isam(isam) {}
208 if(find(isam.
roots().begin(), isam.
roots().end(), node) == isam.
roots().end())
210 if(node->parent_.expired())
212 if(find(node->parent()->children.begin(), node->parent()->children.end(), node) == node->parent()->children.end())
215 for(
Key j: node->conditional()->frontals())
217 if(isam.
nodes().at(
j).get() != node.get())
228 const string name_ = test.getName();
237 isamGraph += isam.
roots().front()->cachedFactor_;
240 expectedHessian.bottomRightCorner(1,1) = actualHessian.bottomRightCorner(1,1);
241 bool isamTreeEqual =
assert_equal(expectedHessian, actualHessian);
252 bool nodeGradientsOk =
true;
254 for(
const sharedClique& clique: isam.
nodes() | br::map_values) {
257 jfg += clique->conditional();
261 for(GaussianConditional::const_iterator jit = clique->conditional()->begin(); jit != clique->conditional()->end(); ++jit) {
263 Vector actual = clique->gradientContribution().segment(variablePosition, dim);
264 bool gradOk =
assert_equal(expectedGradient[*jit], actual);
266 nodeGradientsOk = nodeGradientsOk && gradOk;
267 variablePosition +=
dim;
269 bool dimOk = clique->gradientContribution().rows() == variablePosition;
271 nodeGradientsOk = nodeGradientsOk && dimOk;
278 bool expectedGradOk =
assert_equal(expectedGradient2, expectedGradient);
280 bool totalGradOk =
assert_equal(expectedGradient, actualGradient);
283 return nodeGradientsOk && expectedGradOk && totalGradOk && isamEqual && isamTreeEqual && consistent;
289 for(
size_t i = 0;
i < 10; ++
i) {
395 toRemove.push_back(12);
415 toRemove.push_back(7);
416 toRemove.push_back(14);
442 toRemove.push_back(swap_idx);
443 fullgraph.
remove(swap_idx);
458 for(
const sharedClique& clique: isam.
nodes() | br::map_values) {
461 jfg += clique->conditional();
465 for(GaussianConditional::const_iterator jit = clique->conditional()->begin(); jit != clique->conditional()->end(); ++jit) {
467 Vector actual = clique->gradientContribution().segment(variablePosition, dim);
469 variablePosition +=
dim;
471 EXPECT_LONGS_EQUAL((
long)clique->gradientContribution().rows(), (long)variablePosition);
492 constrained.insert(make_pair((3), 1));
493 constrained.insert(make_pair((4), 2));
508 isam.
update(newfactors, init);
520 init.
insert((i+1),
Pose2(
double(i+1)+0.1, -0.1, 0.01));
521 fullinit.
insert((i+1),
Pose2(
double(i+1)+0.1, -0.1, 0.01));
526 isam.
update(newfactors, init);
556 init.
insert((i+1),
Pose2(
double(i+1)+0.1, -0.1, 0.01));
557 fullinit.
insert((i+1),
Pose2(
double(i+1)+0.1, -0.1, 0.01));
583 for(
const sharedClique& clique: isam.
nodes() | br::map_values) {
586 jfg += clique->conditional();
590 for(GaussianConditional::const_iterator jit = clique->conditional()->begin(); jit != clique->conditional()->end(); ++jit) {
592 Vector actual = clique->gradientContribution().segment(variablePosition, dim);
594 variablePosition +=
dim;
596 LONGS_EQUAL((
long)clique->gradientContribution().rows(), (long)variablePosition);
608 TEST(
ISAM2, slamlike_solution_partial_relinearization_check)
623 Matrix expectedAugmentedHessian, expected3AugmentedHessian;
626 if(find(leafKeys.begin(), leafKeys.end(),
j) == leafKeys.end())
638 ->marginal(toKeep,
EliminateQR)->augmentedHessian();
649 assert(actualAugmentedHessian.allFinite());
653 bool treeEqual =
assert_equal(expectedAugmentedHessian, actualAugmentedHessian, 1
e-6);
656 actualAugmentedHessian.bottomRightCorner(1,1) = expected3AugmentedHessian.bottomRightCorner(1,1);
bool nonlinEqual =
assert_equal(expected3AugmentedHessian, actualAugmentedHessian, 1
e-6);
660 bool afterNonlinCorrect =
assert_equal(expected3AugmentedHessian, actual3AugmentedHessian, 1
e-6);
662 bool ok = treeEqual && nonlinEqual && afterNonlinCorrect;
678 values.insert(0, 0.0);
679 values.insert(1, 0.0);
680 values.insert(2, 0.0);
683 constrainedKeys.insert(make_pair(0, 0));
684 constrainedKeys.insert(make_pair(1, 1));
685 constrainedKeys.insert(make_pair(2, 2));
690 EXPECT(checkMarginalizeLeaves(isam, leafKeys));
706 values.insert(0, 0.0);
707 values.insert(1, 0.0);
708 values.insert(2, 0.0);
709 values.insert(3, 0.0);
712 constrainedKeys.insert(make_pair(0, 0));
713 constrainedKeys.insert(make_pair(1, 1));
714 constrainedKeys.insert(make_pair(2, 2));
715 constrainedKeys.insert(make_pair(3, 3));
720 EXPECT(checkMarginalizeLeaves(isam, leafKeys));
741 values.insert(0, 0.0);
742 values.insert(1, 0.0);
743 values.insert(2, 0.0);
744 values.insert(3, 0.0);
745 values.insert(4, 0.0);
746 values.insert(5, 0.0);
749 constrainedKeys.insert(make_pair(0, 0));
750 constrainedKeys.insert(make_pair(1, 1));
751 constrainedKeys.insert(make_pair(2, 2));
752 constrainedKeys.insert(make_pair(3, 3));
753 constrainedKeys.insert(make_pair(4, 4));
754 constrainedKeys.insert(make_pair(5, 5));
759 EXPECT(checkMarginalizeLeaves(isam, leafKeys));
772 values.insert(0, 0.0);
773 values.insert(1, 0.0);
774 values.insert(2, 0.0);
777 constrainedKeys.insert(make_pair(0, 0));
778 constrainedKeys.insert(make_pair(1, 1));
779 constrainedKeys.insert(make_pair(2, 2));
784 EXPECT(checkMarginalizeLeaves(isam, leafKeys));
795 EXPECT(checkMarginalizeLeaves(isam, marginalizeKeys));
815 int actual = isam.
roots().front()->calculate_nnz();
Provides additional testing facilities for common data structures.
ConsistencyVisitor(const ISAM2 &isam)
static const SharedNoiseModel model
static int runAllTests(TestResult &result)
ISAM2 createSlamlikeISAM2(boost::optional< Values & > init_values=boost::none, boost::optional< NonlinearFactorGraph & > full_graph=boost::none, const ISAM2Params ¶ms=ISAM2Params(ISAM2GaussNewtonParams(0.001), 0.0, 0, false, true, ISAM2Params::CHOLESKY, true, DefaultKeyFormatter, true), size_t maxPoses=10)
T between(const T &t1, const T &t2)
A non-templated config holding any types of Manifold-group elements.
Factor Graph consisting of non-linear factors.
Matrix marginalCovariance(Key key) const
boost::shared_ptr< FactorGraphType > marginal(const KeyVector &variables, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex=boost::none) const
void insert(Key j, const Value &val)
FastVector< FactorIndex > FactorIndices
Define collection types:
const Nodes & nodes() const
EIGEN_DEVICE_FUNC const SqrtReturnType sqrt() const
GaussianFactorGraph factors(list_of(factor1)(factor2)(factor3))
Values retract(const VectorValues &delta) const
IsDerived< DERIVEDFACTOR > push_back(boost::shared_ptr< DERIVEDFACTOR > factor)
Add a factor directly using a shared_ptr.
static const KeyFormatter DefaultKeyFormatter
ptrdiff_t DenseIndex
The index type for Eigen objects.
void DepthFirstForest(FOREST &forest, DATA &rootData, VISITOR_PRE &visitorPre, VISITOR_POST &visitorPost)
void addPrior(Key key, const T &prior, const SharedNoiseModel &model=nullptr)
Values calculateEstimate() const
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
int operator()(const ISAM2::sharedClique &node, int &parentData)
void marginalizeLeaves(const FastList< Key > &leafKeys, boost::optional< FactorIndices & > marginalFactorsIndices=boost::none, boost::optional< FactorIndices & > deletedFactorsIndices=boost::none)
VectorValues gradient(const VectorValues &x0) const
Incremental update functionality (ISAM2) for BayesTree, with fluid relinearization.
#define EXPECT(condition)
Matrix augmentedHessian(const Ordering &ordering) const
Array< double, 1, 3 > e(1./3., 0.5, 2.)
NonlinearISAM isam(relinearizeInterval)
bool isam_check(const NonlinearFactorGraph &fullgraph, const Values &fullinit, const ISAM2 &isam, Test &test, TestResult &result)
Linear Factor Graph where all factors are Gaussians.
Base::sharedClique sharedClique
Shared pointer to a clique.
static SmartStereoProjectionParams params
VectorValues gradientAtZero() const
#define LONGS_EQUAL(expected, actual)
const mpreal dim(const mpreal &a, const mpreal &b, mp_rnd_t r=mpreal::get_default_rnd())
noiseModel::Diagonal::shared_ptr SharedDiagonal
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
const VectorValues & getDelta() const
std::vector< float > Values
#define EXPECT_LONGS_EQUAL(expected, actual)
detail::initimpl::constructor< Args... > init()
Binds an existing constructor taking arguments Args...
bool enablePartialRelinearizationCheck
Create small example with two poses and one landmark.
Chordal Bayes Net, the result of eliminating a factor graph.
virtual ISAM2Result update(const NonlinearFactorGraph &newFactors=NonlinearFactorGraph(), const Values &newTheta=Values(), const FactorIndices &removeFactorIndices=FactorIndices(), const boost::optional< FastMap< Key, int > > &constrainedKeys=boost::none, const boost::optional< FastList< Key > > &noRelinKeys=boost::none, const boost::optional< FastList< Key > > &extraReelimKeys=boost::none, bool force_relinearize=false)
A class for computing marginals in a NonlinearFactorGraph.
const NonlinearFactorGraph & getFactorsUnsafe() const
boost::shared_ptr< GaussianFactorGraph > linearize(const Values &linearizationPoint) const
Linearize a nonlinear factor graph.
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
std::pair< GaussianConditional::shared_ptr, JacobianFactor::shared_ptr > EliminateQR(const GaussianFactorGraph &factors, const Ordering &keys)
Gaussian Bayes Tree, the result of eliminating a GaussianJunctionTree.
const Roots & roots() const
std::uint64_t Key
Integer nonlinear key type.
noiseModel::Base::shared_ptr SharedNoiseModel
const Values & getLinearizationPoint() const
Access the current linearization point.
virtual VectorValues gradientAtZero() const