HybridNonlinearFactorGraph.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 
25 
26 namespace gtsam {
27 
28 /* ************************************************************************* */
29 void HybridNonlinearFactorGraph::print(const std::string& s,
30  const KeyFormatter& keyFormatter) const {
31  // Base::print(str, keyFormatter);
32  std::cout << (s.empty() ? "" : s + " ") << std::endl;
33  std::cout << "size: " << size() << std::endl;
34  for (size_t i = 0; i < factors_.size(); i++) {
35  std::stringstream ss;
36  ss << "factor " << i << ": ";
37  if (factors_[i]) {
38  factors_[i]->print(ss.str(), keyFormatter);
39  std::cout << std::endl;
40  }
41  }
42 }
43 
44 /* ************************************************************************* */
46  const Values& continuousValues) const {
47  using std::dynamic_pointer_cast;
48 
49  // create an empty linear FG
50  auto linearFG = std::make_shared<HybridGaussianFactorGraph>();
51 
52  linearFG->reserve(size());
53 
54  // linearize all hybrid factors
55  for (auto& f : factors_) {
56  // First check if it is a valid factor
57  if (!f) {
58  // TODO(dellaert): why?
59  linearFG->push_back(GaussianFactor::shared_ptr());
60  continue;
61  }
62  // Check if it is a nonlinear mixture factor
63  if (auto mf = dynamic_pointer_cast<MixtureFactor>(f)) {
65  mf->linearize(continuousValues);
66  linearFG->push_back(gmf);
67  } else if (auto nlf = dynamic_pointer_cast<NonlinearFactor>(f)) {
68  const GaussianFactor::shared_ptr& gf = nlf->linearize(continuousValues);
69  linearFG->push_back(gf);
70  } else if (dynamic_pointer_cast<DecisionTreeFactor>(f)) {
71  // If discrete-only: doesn't need linearization.
72  linearFG->push_back(f);
73  } else if (auto gmf = dynamic_pointer_cast<GaussianMixtureFactor>(f)) {
74  linearFG->push_back(gmf);
75  } else if (auto gm = dynamic_pointer_cast<GaussianMixture>(f)) {
76  linearFG->push_back(gm);
77  } else if (dynamic_pointer_cast<GaussianFactor>(f)) {
78  linearFG->push_back(f);
79  } else {
80  auto& fr = *f;
81  throw std::invalid_argument(
82  std::string("HybridNonlinearFactorGraph::linearize: factor type "
83  "not handled: ") +
84  demangle(typeid(fr).name()));
85  }
86  }
87  return linearFG;
88 }
89 
90 } // namespace gtsam
void print(const std::string &s="HybridNonlinearFactorGraph", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
Print the factor graph.
A hybrid conditional in the Conditional Linear Gaussian scheme.
Nonlinear hybrid factor graph that uses type erasure.
Nonlinear Mixture factor of continuous and discrete.
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
RealScalar s
std::shared_ptr< This > shared_ptr
shared_ptr to This
std::shared_ptr< This > shared_ptr
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition: Key.h:35
Linearized Hybrid factor graph that uses type erasure.
std::shared_ptr< This > shared_ptr
shared_ptr to this class
static std::stringstream ss
Definition: testBTree.cpp:31
traits
Definition: chartTesting.h:28
std::string demangle(const char *name)
Pretty print Value type name.
Definition: types.cpp:37
Non-linear factor base classes.
std::shared_ptr< HybridGaussianFactorGraph > linearize(const Values &continuousValues) const
Linearize all the continuous factors in the HybridNonlinearFactorGraph.
Matrix2f mf
FastVector< sharedFactor > factors_
Definition: FactorGraph.h:135


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:34:20