38 using namespace gtsam;
65 initial.
insert<
double>(
X(0), 1);
66 initial.
insert<
double>(
X(1), 2);
67 initial.
insert<
double>(
X(2), 3);
70 isam.
update(graph1, initial);
90 isam.
update(graph2, initial);
120 initial.
insert<
double>(
X(0), 1);
121 initial.
insert<
double>(
X(1), 2);
124 isam.
update(graph1, initial);
127 auto discreteConditional_m0 = bayesTree[
M(0)]->conditional()->asDiscrete();
135 initial.
insert<
double>(
X(2), 3);
141 isam.
update(graph2, initial);
149 const auto [expectedHybridBayesTree, expectedRemainingGraph] =
151 .BaseEliminateable::eliminatePartialMultifrontal(
ordering);
155 bayesTree[
X(0)]->conditional()->inner());
157 (*expectedHybridBayesTree)[
X(0)]->conditional()->inner());
162 bayesTree[
X(1)]->conditional()->inner());
164 (*expectedHybridBayesTree)[
X(1)]->conditional()->inner());
169 bayesTree[
X(2)]->conditional()->inner());
171 (*expectedHybridBayesTree)[
X(2)]->conditional()->inner());
178 expectedRemainingGraph->BaseEliminateable::eliminateMultifrontal(
182 m00[
M(0)] = 0, m00[
M(1)] = 0;
184 *(*discreteBayesTree)[
M(1)]->conditional()->asDiscrete();
185 double m00_prob = decisionTree(m00);
187 auto discreteConditional = bayesTree[
M(1)]->conditional()->asDiscrete();
192 assignment[
M(0)] = 0;
193 assignment[
M(1)] = 0;
195 assignment[
M(0)] = 1;
196 assignment[
M(1)] = 0;
198 assignment[
M(0)] = 0;
199 assignment[
M(1)] = 1;
201 assignment[
M(0)] = 1;
202 assignment[
M(1)] = 1;
207 auto expectedChordal = expectedRemainingGraph->eliminateMultifrontal();
209 bayesTree[
M(1)]->conditional()->inner());
212 vector<double> probs = {0.095292197, 0.31417524, 0.28275772, 0.30777485};
213 auto expectedConditional =
214 std::make_shared<DecisionTreeFactor>(discrete_keys, probs);
227 for (
size_t i = 1;
i < 4;
i++) {
234 for (
size_t i = 4;
i <= 7;
i++) {
241 for (
size_t j = 0;
j < 4;
j++) {
242 ordering.push_back(
X(
j));
246 const auto [unprunedHybridBayesTree, unprunedRemainingGraph] =
248 .BaseEliminateable::eliminatePartialMultifrontal(ordering);
250 size_t maxNrLeaves = 5;
251 incrementalHybrid.
update(graph1, initial);
254 bayesTree.
prune(maxNrLeaves);
291 bayesTree[
M(0)]->conditional()->inner());
295 auto count = [](
const double &
value,
int count) {
296 return value > 0 ? count + 1 : count;
304 unprunedHybridBayesTree->clique(
X(3))->conditional()->inner());
306 bayesTree[
X(3)]->conditional()->inner());
308 std::vector<std::pair<DiscreteValues, double>> assignments =
309 discreteConditional_m0.enumerate();
311 for (
auto &&av : assignments) {
313 const double value = av.second;
316 EXPECT(lastDensity(assignment) ==
nullptr);
318 CHECK(lastDensity(assignment));
320 *lastDensity(assignment)));
335 for (
size_t i = 1;
i < 4;
i++) {
342 initial.
insert<
double>(
X(0), 1);
343 for (
size_t i = 5;
i <= 7;
i++) {
349 size_t maxComponents = 5;
350 incrementalHybrid.
update(graph1, initial);
351 incrementalHybrid.
prune(maxComponents);
358 2, bayesTree[
X(0)]->conditional()->asMixture()->nrComponents());
360 3, bayesTree[
X(1)]->conditional()->asMixture()->nrComponents());
362 5, bayesTree[
X(2)]->conditional()->asMixture()->nrComponents());
364 5, bayesTree[
X(3)]->conditional()->asMixture()->nrComponents());
371 initial.
insert<
double>(
X(4), 5);
374 incrementalHybrid.
update(graph2, initial);
375 incrementalHybrid.
prune(maxComponents);
376 bayesTree = incrementalHybrid.
bayesTree();
382 5, bayesTree[
X(3)]->conditional()->asMixture()->nrComponents());
384 5, bayesTree[
X(4)]->conditional()->asMixture()->nrComponents());
401 auto priorNoise = noiseModel::Diagonal::Sigmas(
406 auto poseNoise = noiseModel::Isotropic::Sigma(3, 0.1);
421 initial.insert(
X(0),
Pose2(0.0, 0.0, 0.0));
422 initial.insert(
Y(0),
Pose2(0.0, 1.0, 0.0));
423 initial.insert(
Z(0),
Pose2(0.0, 2.0, 0.0));
424 initial.insert(
W(0),
Pose2(0.0, 3.0, 0.0));
434 auto noise_model = noiseModel::Isotropic::Sigma(3, 1.0);
435 auto still = std::make_shared<PlanarMotionModel>(
W(0),
W(1),
Pose2(0, 0, 0),
437 moving = std::make_shared<PlanarMotionModel>(
W(0),
W(1),
odometry,
439 std::vector<PlanarMotionModel::shared_ptr> components = {moving, still};
440 auto mixtureFactor = std::make_shared<MixtureFactor>(
455 initial.insert(
X(1),
Pose2(1.0, 0.0, 0.0));
456 initial.insert(
Y(1),
Pose2(1.0, 1.0, 0.0));
457 initial.insert(
Z(1),
Pose2(1.0, 2.0, 0.0));
459 initial.insert(
W(1),
Pose2(0.0, 3.0, 0.0));
474 contKeys = {
W(1),
W(2)};
475 still = std::make_shared<PlanarMotionModel>(
W(1),
W(2),
Pose2(0, 0, 0),
478 std::make_shared<PlanarMotionModel>(
W(1),
W(2),
odometry, noise_model);
479 components = {moving, still};
480 mixtureFactor = std::make_shared<MixtureFactor>(
495 initial.insert(
X(2),
Pose2(2.0, 0.0, 0.0));
496 initial.insert(
Y(2),
Pose2(2.0, 1.0, 0.0));
497 initial.insert(
Z(2),
Pose2(2.0, 2.0, 0.0));
498 initial.insert(
W(2),
Pose2(0.0, 3.0, 0.0));
517 contKeys = {
W(2),
W(3)};
518 still = std::make_shared<PlanarMotionModel>(
W(2),
W(3),
Pose2(0, 0, 0),
521 std::make_shared<PlanarMotionModel>(
W(2),
W(3),
odometry, noise_model);
522 components = {moving, still};
523 mixtureFactor = std::make_shared<MixtureFactor>(
538 initial.insert(
X(3),
Pose2(3.0, 0.0, 0.0));
539 initial.insert(
Y(3),
Pose2(3.0, 1.0, 0.0));
540 initial.insert(
Z(3),
Pose2(3.0, 2.0, 0.0));
541 initial.insert(
W(3),
Pose2(0.0, 3.0, 0.0));
554 auto discreteTree = bayesTree[
M(3)]->conditional()->asDiscrete();
563 expected_assignment[
M(1)] = 1;
564 expected_assignment[
M(2)] = 1;
565 expected_assignment[
M(3)] = 1;
571 auto lastConditional = bayesTree[
X(3)]->conditional()->asMixture();
Matrix< RealScalar, Dynamic, Dynamic > M
TEST(HybridNonlinearISAM, IncrementalElimination)
IsDerived< DERIVEDFACTOR > emplace_shared(Args &&... args)
Emplace a shared pointer to factor of given type.
static int runAllTests(TestResult &result)
const HybridGaussianISAM & bayesTree() const
Point2 prior(const Point2 &x)
Prior on a single pose.
std::shared_ptr< This > shared_ptr
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)
void update(const HybridNonlinearFactorGraph &newFactors, const Values &initialValues, const std::optional< size_t > &maxNrLeaves={}, const std::optional< Ordering > &ordering={})
static enum @1107 ordering
void prune(const size_t maxNumberLeaves)
Prune the underlying Bayes tree.
void prune(const size_t maxNumberLeaves)
Prune the underlying Bayes tree.
HybridGaussianFactorGraph linearizedFactorGraph
A conditional of gaussian mixtures indexed by discrete variables, as part of a Bayes Network...
#define EXPECT(condition)
Array< double, 1, 3 > e(1./3., 0.5, 2.)
NonlinearISAM isam(relinearizeInterval)
Linear Factor Graph where all factors are Gaussians.
NonlinearFactorGraph graph2()
std::vector< float > Values
#define EXPECT_LONGS_EQUAL(expected, actual)
HybridNonlinearFactorGraph nonlinearFactorGraph
const sharedFactor at(size_t i) const
std::pair< Key, size_t > DiscreteKey
Chordal Bayes Net, the result of eliminating a factor graph.
void insert(Key j, const Value &val)
Pose2 odometry(2.0, 0.0, 0.0)
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
#define CHECK_EQUAL(expected, actual)
DiscreteKeys is a set of keys that can be assembled using the & operator.