TinyHybridExample.h
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010-2023, 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 
12 /*
13  * @file TinyHybridExample.h
14  * @date December, 2022
15  * @author Frank Dellaert
16  */
17 
20 #include <gtsam/inference/Symbol.h>
21 #pragma once
22 
23 namespace gtsam {
24 namespace tiny {
25 
29 
30 // Create mode key: 0 is low-noise, 1 is high-noise.
31 const DiscreteKey mode{M(0), 2};
32 
39 inline HybridBayesNet createHybridBayesNet(size_t num_measurements = 1,
40  bool manyModes = false) {
42 
43  // Create hybrid Gaussian factor z_i = x0 + noise for each measurement.
44  std::vector<std::pair<Vector, double>> measurementModels{{Z_1x1, 0.5},
45  {Z_1x1, 3.0}};
46  for (size_t i = 0; i < num_measurements; i++) {
47  const auto mode_i = manyModes ? DiscreteKey{M(i), 2} : mode;
48  bayesNet.emplace_shared<HybridGaussianConditional>(mode_i, Z(i), I_1x1,
49  X(0), measurementModels);
50  }
51 
52  // Create prior on X(0).
53  bayesNet.push_back(
55 
56  // Add prior on mode.
57  const size_t nrModes = manyModes ? num_measurements : 1;
58  for (size_t i = 0; i < nrModes; i++) {
59  bayesNet.emplace_shared<DiscreteConditional>(DiscreteKey{M(i), 2}, "4/6");
60  }
61  return bayesNet;
62 }
63 
71  size_t num_measurements = 1, std::optional<VectorValues> measurements = {},
72  bool manyModes = false) {
73  auto bayesNet = createHybridBayesNet(num_measurements, manyModes);
74  if (measurements) {
75  // Use the measurements to create a hybrid factor graph.
76  return bayesNet.toFactorGraph(*measurements);
77  } else {
78  // Sample from the generative model to create a hybrid factor graph.
79  return bayesNet.toFactorGraph(bayesNet.sample().continuous());
80  }
81 }
82 
83 } // namespace tiny
84 } // namespace gtsam
gtsam::Vector1
Eigen::Matrix< double, 1, 1 > Vector1
Definition: Vector.h:41
gtsam::HybridBayesNet
Definition: HybridBayesNet.h:37
gtsam::symbol_shorthand::M
Key M(std::uint64_t j)
Definition: inference/Symbol.h:160
HybridBayesNet.h
A Bayes net of Gaussian Conditionals indexed by discrete keys.
X
#define X
Definition: icosphere.cpp:20
gtsam::symbol_shorthand::X
Key X(std::uint64_t j)
Definition: inference/Symbol.h:171
gtsam::tiny::mode
const DiscreteKey mode
Definition: TinyHybridExample.h:31
different_sigmas::bayesNet
const HybridBayesNet bayesNet
Definition: testHybridBayesNet.cpp:242
gtsam::symbol_shorthand::Z
Key Z(std::uint64_t j)
Definition: inference/Symbol.h:173
gtsam::HybridGaussianConditional
A conditional of gaussian conditionals indexed by discrete variables, as part of a Bayes Network....
Definition: HybridGaussianConditional.h:54
gtsam::HybridGaussianFactorGraph
Definition: HybridGaussianFactorGraph.h:106
Symbol.h
gtsam::DiscreteConditional
Definition: DiscreteConditional.h:37
HybridGaussianFactorGraph.h
Linearized Hybrid factor graph that uses type erasure.
gtsam::tiny::createHybridGaussianFactorGraph
HybridGaussianFactorGraph createHybridGaussianFactorGraph(size_t num_measurements=1, std::optional< VectorValues > measurements={}, bool manyModes=false)
Definition: TinyHybridExample.h:70
gtsam
traits
Definition: SFMdata.h:40
estimation_fixture::measurements
std::vector< double > measurements
Definition: testHybridEstimation.cpp:51
gtsam::DiscreteKey
std::pair< Key, size_t > DiscreteKey
Definition: DiscreteKey.h:38
gtsam::tiny::createHybridBayesNet
HybridBayesNet createHybridBayesNet(size_t num_measurements=1, bool manyModes=false)
Definition: TinyHybridExample.h:39
Z
#define Z
Definition: icosphere.cpp:21
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
gtsam::GaussianConditional::sharedMeanAndStddev
static shared_ptr sharedMeanAndStddev(Args &&... args)
Create shared pointer by forwarding arguments to fromMeanAndStddev.
Definition: GaussianConditional.h:105
M
Matrix< RealScalar, Dynamic, Dynamic > M
Definition: bench_gemm.cpp:51


gtsam
Author(s):
autogenerated on Sun Nov 10 2024 04:07:34