testHybridMotionModel.cpp
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
21 #include <gtsam/base/Testable.h>
31 #include <gtsam/inference/Symbol.h>
36 
37 // Include for test suite
39 
40 #include <memory>
41 
42 using namespace std;
43 using namespace gtsam;
47 
48 DiscreteKey m1(M(1), 2);
49 
50 void addMeasurement(HybridBayesNet &hbn, Key z_key, Key x_key, double sigma) {
51  auto measurement_model = noiseModel::Isotropic::Sigma(1, sigma);
52  hbn.emplace_shared<GaussianConditional>(z_key, Vector1(0.0), I_1x1, x_key,
53  -I_1x1, measurement_model);
54 }
55 
58  double mu0, double mu1, double sigma0, double sigma1) {
59  std::vector<std::pair<Vector, double>> motionModels{{Vector1(mu0), sigma0},
60  {Vector1(mu1), sigma1}};
61  return std::make_shared<HybridGaussianConditional>(m1, X(1), I_1x1, X(0),
62  motionModels);
63 }
64 
67  const HybridGaussianConditional::shared_ptr &hybridMotionModel,
68  bool add_second_measurement = false) {
69  HybridBayesNet hbn;
70 
71  // Add measurement model p(z0 | x0)
72  addMeasurement(hbn, Z(0), X(0), 3.0);
73 
74  // Optionally add second measurement model p(z1 | x1)
75  if (add_second_measurement) {
76  addMeasurement(hbn, Z(1), X(1), 3.0);
77  }
78 
79  // Add hybrid motion model
80  hbn.push_back(hybridMotionModel);
81 
82  // Discrete uniform prior.
83  hbn.emplace_shared<DiscreteConditional>(m1, "50/50");
84 
85  return hbn;
86 }
87 
89 std::pair<double, double> approximateDiscreteMarginal(
90  const HybridBayesNet &hbn,
91  const HybridGaussianConditional::shared_ptr &hybridMotionModel,
92  const VectorValues &given, size_t N = 100000) {
96  q.push_back(hybridMotionModel); // Add hybrid motion model
97  q.emplace_shared<GaussianConditional>(GaussianConditional::FromMeanAndStddev(
98  X(0), given.at(Z(0)), /* sigmaQ = */ 3.0)); // Add proposal q(x0) for x0
99  q.emplace_shared<DiscreteConditional>(m1, "50/50"); // Discrete prior.
100 
101  // Do importance sampling
102  double w0 = 0.0, w1 = 0.0;
103  std::mt19937_64 rng(42);
104  for (size_t i = 0; i < N; i++) {
105  HybridValues sample = q.sample(&rng);
106  sample.insert(given);
107  double weight = hbn.evaluate(sample) / q.evaluate(sample);
108  (sample.atDiscrete(M(1)) == 0) ? w0 += weight : w1 += weight;
109  }
110  double pm1 = w1 / (w0 + w1);
111  std::cout << "p(m0) = " << 100 * (1.0 - pm1) << std::endl;
112  std::cout << "p(m1) = " << 100 * pm1 << std::endl;
113  return {1.0 - pm1, pm1};
114 }
115 
116 /* ************************************************************************* */
129  double mu0 = 1.0, mu1 = 3.0;
130  double sigma = 0.5;
131  auto hybridMotionModel = CreateHybridMotionModel(mu0, mu1, sigma, sigma);
132 
133  // Start with no measurement on x1, only on x0
134  const Vector1 z0(0.5);
135 
136  VectorValues given;
137  given.insert(Z(0), z0);
138 
139  {
140  HybridBayesNet hbn = CreateBayesNet(hybridMotionModel);
141  HybridGaussianFactorGraph gfg = hbn.toFactorGraph(given);
143 
144  // Since no measurement on x1, we hedge our bets
145  // Importance sampling run with 100k samples gives 50.051/49.949
146  // approximateDiscreteMarginal(hbn, hybridMotionModel, given);
147  TableDistribution expected(m1, "50 50");
148  EXPECT(
149  assert_equal(expected, *(bn->at(2)->asDiscrete<TableDistribution>())));
150  }
151 
152  {
153  // If we set z1=4.5 (>> 2.5 which is the halfway point),
154  // probability of discrete mode should be leaning to m1==1.
155  const Vector1 z1(4.5);
156  given.insert(Z(1), z1);
157 
158  HybridBayesNet hbn = CreateBayesNet(hybridMotionModel, true);
159  HybridGaussianFactorGraph gfg = hbn.toFactorGraph(given);
161 
162  // Since we have a measurement on x1, we get a definite result
163  // Values taken from an importance sampling run with 100k samples:
164  // approximateDiscreteMarginal(hbn, hybridMotionModel, given);
165  TableDistribution expected(m1, "44.3854 55.6146");
166  EXPECT(assert_equal(expected, *(bn->at(2)->asDiscrete<TableDistribution>()),
167  0.02));
168  }
169 }
170 
171 /* ************************************************************************* */
184 TEST(HybridGaussianFactorGraph, TwoStateModel2) {
185  double mu0 = 1.0, mu1 = 3.0;
186  double sigma0 = 0.5, sigma1 = 2.0;
187  auto hybridMotionModel = CreateHybridMotionModel(mu0, mu1, sigma0, sigma1);
188 
189  // Start with no measurement on x1, only on x0
190  const Vector1 z0(0.5);
191  VectorValues given;
192  given.insert(Z(0), z0);
193 
194  {
195  HybridBayesNet hbn = CreateBayesNet(hybridMotionModel);
196  HybridGaussianFactorGraph gfg = hbn.toFactorGraph(given);
197 
199 
200  for (VectorValues vv :
201  {VectorValues{{X(0), Vector1(0.0)}, {X(1), Vector1(1.0)}},
202  VectorValues{{X(0), Vector1(0.5)}, {X(1), Vector1(3.0)}}}) {
203  vv.insert(given); // add measurements for HBN
204  const auto &expectedDiscretePosterior = hbn.discretePosterior(vv);
205 
206  // Equality of posteriors asserts that the factor graph is correct (same
207  // ratios for all modes)
208  EXPECT(
209  assert_equal(expectedDiscretePosterior, gfg.discretePosterior(vv)));
210 
211  // This one asserts that HBN resulting from elimination is correct.
212  EXPECT(assert_equal(expectedDiscretePosterior,
213  eliminated->discretePosterior(vv)));
214  }
215 
216  // Importance sampling run with 100k samples gives 50.095/49.905
217  // approximateDiscreteMarginal(hbn, hybridMotionModel, given);
218 
219  // Since no measurement on x1, we a 50/50 probability
220  auto p_m = eliminated->at(2)->asDiscrete();
221  EXPECT_DOUBLES_EQUAL(0.5, p_m->operator()({{M(1), 0}}), 1e-9);
222  EXPECT_DOUBLES_EQUAL(0.5, p_m->operator()({{M(1), 1}}), 1e-9);
223  }
224 
225  {
226  // Now we add a measurement z1 on x1
227  const Vector1 z1(4.0); // favors m==1
228  given.insert(Z(1), z1);
229 
230  HybridBayesNet hbn = CreateBayesNet(hybridMotionModel, true);
231  HybridGaussianFactorGraph gfg = hbn.toFactorGraph(given);
233 
234  // Check that ratio of Bayes net and factor graph for different modes is
235  // equal for several values of {x0,x1}.
236  for (VectorValues vv :
237  {VectorValues{{X(0), Vector1(0.0)}, {X(1), Vector1(1.0)}},
238  VectorValues{{X(0), Vector1(0.5)}, {X(1), Vector1(3.0)}}}) {
239  vv.insert(given); // add measurements for HBN
240  const auto &expectedDiscretePosterior = hbn.discretePosterior(vv);
241 
242  // Equality of posteriors asserts that the factor graph is correct (same
243  // ratios for all modes)
244  EXPECT(
245  assert_equal(expectedDiscretePosterior, gfg.discretePosterior(vv)));
246 
247  // This one asserts that HBN resulting from elimination is correct.
248  EXPECT(assert_equal(expectedDiscretePosterior,
249  eliminated->discretePosterior(vv)));
250  }
251 
252  // Values taken from an importance sampling run with 100k samples:
253  // approximateDiscreteMarginal(hbn, hybridMotionModel, given);
254  TableDistribution expected(m1, "48.3158 51.6842");
256  expected, *(eliminated->at(2)->asDiscrete<TableDistribution>()), 0.02));
257  }
258 
259  {
260  // Add a different measurement z1 on x1 that favors m==0
261  const Vector1 z1(1.1);
262  given.insert_or_assign(Z(1), z1);
263 
264  HybridBayesNet hbn = CreateBayesNet(hybridMotionModel, true);
265  HybridGaussianFactorGraph gfg = hbn.toFactorGraph(given);
267 
268  // Values taken from an importance sampling run with 100k samples:
269  // approximateDiscreteMarginal(hbn, hybridMotionModel, given);
270  TableDistribution expected(m1, "55.396 44.604");
271  EXPECT(assert_equal(expected, *(bn->at(2)->asDiscrete<TableDistribution>()),
272  0.02));
273  }
274 }
275 
276 /* ************************************************************************* */
289 TEST(HybridGaussianFactorGraph, TwoStateModel3) {
290  double mu = 1.0;
291  double sigma0 = 0.5, sigma1 = 2.0;
292  auto hybridMotionModel = CreateHybridMotionModel(mu, mu, sigma0, sigma1);
293 
294  // Start with no measurement on x1, only on x0
295  const Vector1 z0(0.5);
296  VectorValues given;
297  given.insert(Z(0), z0);
298 
299  {
300  HybridBayesNet hbn = CreateBayesNet(hybridMotionModel);
301  HybridGaussianFactorGraph gfg = hbn.toFactorGraph(given);
302 
303  // Check that ratio of Bayes net and factor graph for different modes is
304  // equal for several values of {x0,x1}.
305  for (VectorValues vv :
306  {VectorValues{{X(0), Vector1(0.0)}, {X(1), Vector1(1.0)}},
307  VectorValues{{X(0), Vector1(0.5)}, {X(1), Vector1(3.0)}}}) {
308  vv.insert(given); // add measurements for HBN
309  HybridValues hv0(vv, {{M(1), 0}}), hv1(vv, {{M(1), 1}});
310  EXPECT_DOUBLES_EQUAL(gfg.error(hv0) / hbn.error(hv0),
311  gfg.error(hv1) / hbn.error(hv1), 1e-9);
312  }
313 
315 
316  // Importance sampling run with 100k samples gives 50.095/49.905
317  // approximateDiscreteMarginal(hbn, hybridMotionModel, given);
318 
319  // Since no measurement on x1, we a 50/50 probability
320  auto p_m = bn->at(2)->asDiscrete();
321  EXPECT_DOUBLES_EQUAL(0.5, p_m->operator()({{M(1), 0}}), 1e-9);
322  EXPECT_DOUBLES_EQUAL(0.5, p_m->operator()({{M(1), 1}}), 1e-9);
323  }
324 
325  {
326  // Now we add a measurement z1 on x1
327  const Vector1 z1(4.0); // favors m==1
328  given.insert(Z(1), z1);
329 
330  HybridBayesNet hbn = CreateBayesNet(hybridMotionModel, true);
331  HybridGaussianFactorGraph gfg = hbn.toFactorGraph(given);
332 
333  // Check that ratio of Bayes net and factor graph for different modes is
334  // equal for several values of {x0,x1}.
335  for (VectorValues vv :
336  {VectorValues{{X(0), Vector1(0.0)}, {X(1), Vector1(1.0)}},
337  VectorValues{{X(0), Vector1(0.5)}, {X(1), Vector1(3.0)}}}) {
338  vv.insert(given); // add measurements for HBN
339  HybridValues hv0(vv, {{M(1), 0}}), hv1(vv, {{M(1), 1}});
340  EXPECT_DOUBLES_EQUAL(gfg.error(hv0) / hbn.error(hv0),
341  gfg.error(hv1) / hbn.error(hv1), 1e-9);
342  }
343 
345 
346  // Values taken from an importance sampling run with 100k samples:
347  // approximateDiscreteMarginal(hbn, hybridMotionModel, given);
348  TableDistribution expected(m1, "51.7762 48.2238");
349  EXPECT(assert_equal(expected, *(bn->at(2)->asDiscrete<TableDistribution>()),
350  0.02));
351  }
352 
353  {
354  // Add a different measurement z1 on x1 that favors m==1
355  const Vector1 z1(7.0);
356  given.insert_or_assign(Z(1), z1);
357 
358  HybridBayesNet hbn = CreateBayesNet(hybridMotionModel, true);
359  HybridGaussianFactorGraph gfg = hbn.toFactorGraph(given);
361 
362  // Values taken from an importance sampling run with 100k samples:
363  // approximateDiscreteMarginal(hbn, hybridMotionModel, given);
364  TableDistribution expected(m1, "49.0762 50.9238");
365  EXPECT(assert_equal(expected, *(bn->at(2)->asDiscrete<TableDistribution>()),
366  0.05));
367  }
368 }
369 
370 /* ************************************************************************* */
376 TEST(HybridGaussianFactorGraph, TwoStateModel4) {
377  double mu0 = 0.0, mu1 = 10.0;
378  double sigma0 = 0.2, sigma1 = 5.0;
379  auto hybridMotionModel = CreateHybridMotionModel(mu0, mu1, sigma0, sigma1);
380 
381  // We only check the 2-measurement case
382  const Vector1 z0(0.0), z1(10.0);
383  VectorValues given{{Z(0), z0}, {Z(1), z1}};
384 
385  HybridBayesNet hbn = CreateBayesNet(hybridMotionModel, true);
386  HybridGaussianFactorGraph gfg = hbn.toFactorGraph(given);
388 
389  // Values taken from an importance sampling run with 100k samples:
390  // approximateDiscreteMarginal(hbn, hybridMotionModel, given);
391  TableDistribution expected(m1, "8.91527 91.0847");
392  EXPECT(assert_equal(expected, *(bn->at(2)->asDiscrete<TableDistribution>()),
393  0.01));
394 }
395 
396 /* ************************************************************************* */
411  const gtsam::Values &values, const std::vector<double> &means,
412  const std::vector<double> &sigmas, DiscreteKey &m1,
413  double measurement_noise = 1e-3) {
414  auto model0 = noiseModel::Isotropic::Sigma(1, sigmas[0]);
415  auto model1 = noiseModel::Isotropic::Sigma(1, sigmas[1]);
416  auto prior_noise = noiseModel::Isotropic::Sigma(1, measurement_noise);
417 
418  auto f0 =
419  std::make_shared<BetweenFactor<double>>(X(0), X(1), means[0], model0)
420  ->linearize(values);
421  auto f1 =
422  std::make_shared<BetweenFactor<double>>(X(0), X(1), means[1], model1)
423  ->linearize(values);
424 
425  // Create HybridGaussianFactor
426  // We take negative since we want
427  // the underlying scalar to be log(\sqrt(|2πΣ|))
428  std::vector<GaussianFactorValuePair> factors{{f0, model0->negLogConstant()},
429  {f1, model1->negLogConstant()}};
430  HybridGaussianFactor motionFactor(m1, factors);
431 
433  hfg.push_back(motionFactor);
434 
435  hfg.push_back(PriorFactor<double>(X(0), values.at<double>(X(0)), prior_noise)
436  .linearize(values));
437 
438  return hfg;
439 }
440 } // namespace test_direct_factor_graph
441 
442 /* ************************************************************************* */
450 TEST(HybridGaussianFactorGraph, DifferentMeans) {
451  using namespace test_direct_factor_graph;
452 
453  DiscreteKey m1(M(1), 2);
454 
455  Values values;
456  double x1 = 0.0, x2 = 1.75;
457  values.insert(X(0), x1);
458  values.insert(X(1), x2);
459 
460  std::vector<double> means = {0.0, 2.0}, sigmas = {1e-0, 1e-0};
461 
463 
464  {
465  auto bn = hfg.eliminateSequential();
466  HybridValues actual = bn->optimize();
467 
469  VectorValues{{X(0), Vector1(0.0)}, {X(1), Vector1(-1.75)}},
470  DiscreteValues{{M(1), 0}});
471 
472  EXPECT(assert_equal(expected, actual));
473 
474  DiscreteValues dv0{{M(1), 0}};
475  VectorValues cont0 = bn->optimize(dv0);
476  double error0 = bn->error(HybridValues(cont0, dv0));
477  // regression
478  EXPECT_DOUBLES_EQUAL(0.69314718056, error0, 1e-9);
479 
480  DiscreteValues dv1{{M(1), 1}};
481  VectorValues cont1 = bn->optimize(dv1);
482  double error1 = bn->error(HybridValues(cont1, dv1));
483  EXPECT_DOUBLES_EQUAL(error0, error1, 1e-9);
484  }
485 
486  {
487  auto prior_noise = noiseModel::Isotropic::Sigma(1, 1e-3);
488  hfg.push_back(
489  PriorFactor<double>(X(1), means[1], prior_noise).linearize(values));
490 
491  auto bn = hfg.eliminateSequential();
492  HybridValues actual = bn->optimize();
493 
495  VectorValues{{X(0), Vector1(0.0)}, {X(1), Vector1(0.25)}},
496  DiscreteValues{{M(1), 1}});
497 
498  EXPECT(assert_equal(expected, actual));
499 
500  {
501  DiscreteValues dv{{M(1), 0}};
502  VectorValues cont = bn->optimize(dv);
503  double error = bn->error(HybridValues(cont, dv));
504  // regression
505  EXPECT_DOUBLES_EQUAL(2.12692448787, error, 1e-9);
506  }
507  {
508  DiscreteValues dv{{M(1), 1}};
509  VectorValues cont = bn->optimize(dv);
510  double error = bn->error(HybridValues(cont, dv));
511  // regression
512  EXPECT_DOUBLES_EQUAL(0.126928487854, error, 1e-9);
513  }
514  }
515 }
516 
517 /* ************************************************************************* */
525 TEST(HybridGaussianFactorGraph, DifferentCovariances) {
526  using namespace test_direct_factor_graph;
527 
528  DiscreteKey m1(M(1), 2);
529 
530  Values values;
531  double x1 = 1.0, x2 = 1.0;
532  values.insert(X(0), x1);
533  values.insert(X(1), x2);
534 
535  std::vector<double> means = {0.0, 0.0}, sigmas = {1e2, 1e-2};
536 
537  // Create FG with HybridGaussianFactor and prior on X1
539  auto hbn = fg.eliminateSequential();
540 
541  VectorValues cv;
542  cv.insert(X(0), Vector1(0.0));
543  cv.insert(X(1), Vector1(0.0));
544 
545  DiscreteValues dv0{{M(1), 0}};
546  DiscreteValues dv1{{M(1), 1}};
547 
548  TableDistribution expected_m1(m1, "0.5 0.5");
549  TableDistribution actual_m1 = *(hbn->at(2)->asDiscrete<TableDistribution>());
550 
551  EXPECT(assert_equal(expected_m1, actual_m1));
552 }
553 
554 /* ************************************************************************* */
555 int main() {
556  TestResult tr;
557  return TestRegistry::runAllTests(tr);
558 }
559 /* ************************************************************************* */
TestRegistry::runAllTests
static int runAllTests(TestResult &result)
Definition: TestRegistry.cpp:27
gtsam::EliminateableFactorGraph::eliminateSequential
std::shared_ptr< BayesNetType > eliminateSequential(OptionalOrderingType orderingType={}, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex={}) const
Definition: EliminateableFactorGraph-inst.h:29
TableDistribution.h
simple_graph::sigma1
double sigma1
Definition: testJacobianFactor.cpp:193
GaussianFactorGraph.h
Linear Factor Graph where all factors are Gaussians.
gtsam::HybridValues
Definition: HybridValues.h:37
rng
static std::mt19937 rng
Definition: timeFactorOverhead.cpp:31
test_constructor::f1
auto f1
Definition: testHybridNonlinearFactor.cpp:56
gtsam::HybridGaussianConditional::shared_ptr
std::shared_ptr< This > shared_ptr
Definition: HybridGaussianConditional.h:60
HybridGaussianConditional.h
A hybrid conditional in the Conditional Linear Gaussian scheme.
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
gtsam::FactorGraph::error
double error(const HybridValues &values) const
Definition: FactorGraph-inst.h:66
Testable.h
Concept check for values that can be used in unit tests.
EXPECT
#define EXPECT(condition)
Definition: Test.h:150
test_constructor::sigmas
Vector1 sigmas
Definition: testHybridNonlinearFactor.cpp:52
TestHarness.h
gtsam::HybridBayesNet
Definition: HybridBayesNet.h:37
mu
double mu
Definition: testBoundingConstraint.cpp:37
gtsam::HybridBayesNet::evaluate
double evaluate(const HybridValues &values) const
Evaluate hybrid probability density for given HybridValues.
Definition: HybridBayesNet.cpp:265
gtsam::VectorValues::insert
iterator insert(const std::pair< Key, Vector > &key_value)
Definition: VectorValues.cpp:90
z1
Point2 z1
Definition: testTriangulationFactor.cpp:45
gtsam::VectorValues::at
Vector & at(Key j)
Definition: VectorValues.h:145
simple_graph::factors
const GaussianFactorGraph factors
Definition: testJacobianFactor.cpp:213
m1
DiscreteKey m1(M(1), 2)
CreateHybridMotionModel
static HybridGaussianConditional::shared_ptr CreateHybridMotionModel(double mu0, double mu1, double sigma0, double sigma1)
Create hybrid motion model p(x1 | x0, m1)
Definition: testHybridMotionModel.cpp:57
gtsam::PriorFactor
Definition: nonlinear/PriorFactor.h:30
HybridBayesNet.h
A Bayes net of Gaussian Conditionals indexed by discrete keys.
different_sigmas::values
HybridValues values
Definition: testHybridBayesNet.cpp:247
X
#define X
Definition: icosphere.cpp:20
vv
static const VectorValues vv
Definition: testHybridGaussianConditional.cpp:45
DiscreteConditional.h
gtsam::means
Point2Pair means(const std::vector< Point2Pair > &abPointPairs)
Calculate the two means of a set of Point2 pairs.
Definition: Point2.cpp:116
HybridGaussianFactor.h
A set of GaussianFactors, indexed by a set of discrete keys.
approximateDiscreteMarginal
std::pair< double, double > approximateDiscreteMarginal(const HybridBayesNet &hbn, const HybridGaussianConditional::shared_ptr &hybridMotionModel, const VectorValues &given, size_t N=100000)
Approximate the discrete marginal P(m1) using importance sampling.
Definition: testHybridMotionModel.cpp:89
TestableAssertions.h
Provides additional testing facilities for common data structures.
sampling::sigma
static const double sigma
Definition: testGaussianBayesNet.cpp:170
addMeasurement
void addMeasurement(HybridBayesNet &hbn, Key z_key, Key x_key, double sigma)
Definition: testHybridMotionModel.cpp:50
gtsam::FactorGraph::at
const sharedFactor at(size_t i) const
Definition: FactorGraph.h:306
Vector1
Eigen::Matrix< double, 1, 1 > Vector1
Definition: testEvent.cpp:33
PriorFactor.h
gtsam::VectorValues
Definition: VectorValues.h:74
test_constructor::f0
auto f0
Definition: testHybridNonlinearFactor.cpp:55
Eigen::numext::q
EIGEN_DEVICE_FUNC const Scalar & q
Definition: SpecialFunctionsImpl.h:1984
BetweenFactor.h
x1
Pose3 x1
Definition: testPose3.cpp:692
gtsam::TableDistribution
Definition: TableDistribution.h:39
main
int main()
Definition: testHybridMotionModel.cpp:555
gtsam::GaussianConditional
Definition: GaussianConditional.h:40
cholesky::expected
Matrix expected
Definition: testMatrix.cpp:916
gtsam::HybridGaussianFactorGraph
Definition: HybridGaussianFactorGraph.h:106
Symbol.h
gtsam::HybridValues::insert
void insert(Key j, const Vector &value)
Definition: HybridValues.cpp:85
VectorValues.h
Factor Graph Values.
EXPECT_DOUBLES_EQUAL
#define EXPECT_DOUBLES_EQUAL(expected, actual, threshold)
Definition: Test.h:161
TestResult
Definition: TestResult.h:26
gtsam::HybridBayesNet::discretePosterior
AlgebraicDecisionTree< Key > discretePosterior(const VectorValues &continuousValues) const
Compute normalized posterior P(M|X=x) and return as a tree.
Definition: HybridBayesNet.cpp:256
TEST
TEST(HybridGaussianFactorGraph, TwoStateModel)
Definition: testHybridMotionModel.cpp:128
gtsam::HybridBayesNet::push_back
void push_back(std::shared_ptr< HybridConditional > conditional)
Add a hybrid conditional using a shared_ptr.
Definition: HybridBayesNet.h:76
gtsam::DiscreteConditional
Definition: DiscreteConditional.h:37
gtsam::HybridValues::at
Vector & at(Key j)
Definition: HybridValues.cpp:129
HybridGaussianFactorGraph.h
Linearized Hybrid factor graph that uses type erasure.
gtsam
traits
Definition: SFMdata.h:40
gtsam::HybridValues::atDiscrete
size_t & atDiscrete(Key j)
Definition: HybridValues.cpp:132
DiscreteValues.h
error
static double error
Definition: testRot3.cpp:37
gtsam::DiscreteValues
Definition: DiscreteValues.h:34
gtsam::FactorGraph::push_back
IsDerived< DERIVEDFACTOR > push_back(std::shared_ptr< DERIVEDFACTOR > factor)
Add a factor directly using a shared_ptr.
Definition: FactorGraph.h:147
gtsam::Values
Definition: Values.h:65
gtsam::DiscreteKey
std::pair< Key, size_t > DiscreteKey
Definition: DiscreteKey.h:38
std
Definition: BFloat16.h:88
gtsam::HybridGaussianFactor
Implementation of a discrete-conditioned hybrid factor. Implements a joint discrete-continuous factor...
Definition: HybridGaussianFactor.h:60
gtsam::assert_equal
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:41
hv0
static const HybridValues hv0
Definition: testHybridGaussianConditional.cpp:47
Eigen::Matrix
The matrix class, also used for vectors and row-vectors.
Definition: 3rdparty/Eigen/Eigen/src/Core/Matrix.h:178
test_direct_factor_graph::CreateFactorGraph
static HybridGaussianFactorGraph CreateFactorGraph(const gtsam::Values &values, const std::vector< double > &means, const std::vector< double > &sigmas, DiscreteKey &m1, double measurement_noise=1e-3)
Create a Factor Graph by directly specifying all the factors instead of creating conditionals first....
Definition: testHybridMotionModel.cpp:410
N
#define N
Definition: igam.h:9
gtsam::HybridBayesNet::shared_ptr
std::shared_ptr< HybridBayesNet > shared_ptr
Definition: HybridBayesNet.h:42
gtsam::HybridGaussianFactorGraph::discretePosterior
AlgebraicDecisionTree< Key > discretePosterior(const VectorValues &continuousValues) const
Computer posterior P(M|X=x) when all continuous values X are given. This is efficient as this simply ...
Definition: HybridGaussianFactorGraph.cpp:652
test_direct_factor_graph
Definition: testHybridMotionModel.cpp:397
gtsam::HybridBayesNet::toFactorGraph
HybridGaussianFactorGraph toFactorGraph(const VectorValues &measurements) const
Definition: HybridBayesNet.cpp:270
model1
noiseModel::Isotropic::shared_ptr model1
Definition: testEssentialMatrixFactor.cpp:26
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:97
hv1
static const HybridValues hv1
Definition: testHybridGaussianConditional.cpp:48
Z
#define Z
Definition: icosphere.cpp:21
CreateBayesNet
HybridBayesNet CreateBayesNet(const HybridGaussianConditional::shared_ptr &hybridMotionModel, bool add_second_measurement=false)
Create two state Bayes network with 1 or two measurement models.
Definition: testHybridMotionModel.cpp:66
HybridValues.h
x2
Pose3 x2(Rot3::Ypr(0.0, 0.0, 0.0), l2)
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
gtsam::HybridBayesNet::emplace_shared
void emplace_shared(Args &&...args)
Definition: HybridBayesNet.h:116
M
Matrix< RealScalar, Dynamic, Dynamic > M
Definition: bench_gemm.cpp:51


gtsam
Author(s):
autogenerated on Wed Mar 19 2025 03:06:50