HybridGaussianProductFactor.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 
19 #include <gtsam/base/types.h>
24 
25 #include <string>
26 
27 namespace gtsam {
28 
30 
31 /* *******************************************************************************/
32 static Y add(const Y& y1, const Y& y2) {
34  result.push_back(y2.first);
35  return {result, y1.second + y2.second};
36 };
37 
38 /* *******************************************************************************/
41  return a.empty() ? b : HybridGaussianProductFactor(a.apply(b, add));
42 }
43 
44 /* *******************************************************************************/
46  const HybridGaussianFactor& factor) const {
47  return *this + factor.asProductFactor();
48 }
49 
50 /* *******************************************************************************/
52  const GaussianFactor::shared_ptr& factor) const {
53  return *this + HybridGaussianProductFactor(factor);
54 }
55 
56 /* *******************************************************************************/
58  const GaussianFactor::shared_ptr& factor) {
59  *this = *this + factor;
60  return *this;
61 }
62 
63 /* *******************************************************************************/
65  const HybridGaussianFactor& factor) {
66  *this = *this + factor;
67  return *this;
68 }
69 
70 /* *******************************************************************************/
71 void HybridGaussianProductFactor::print(const std::string& s,
72  const KeyFormatter& formatter) const {
73  KeySet keys;
74  auto printer = [&](const Y& y) {
75  if (keys.empty()) keys = y.first.keys();
76  return "Graph of size " + std::to_string(y.first.size()) +
77  ", scalar sum: " + std::to_string(y.second);
78  };
79  Base::print(s, formatter, printer);
80  if (!keys.empty()) {
81  std::cout << s << " Keys:";
82  for (auto&& key : keys) std::cout << " " << formatter(key);
83  std::cout << "." << std::endl;
84  }
85 }
86 
87 /* *******************************************************************************/
89  const HybridGaussianProductFactor& other, double tol) const {
90  return Base::equals(other, [tol](const Y& a, const Y& b) {
91  return a.first.equals(b.first, tol) && std::abs(a.second - b.second) < tol;
92  });
93 }
94 
95 /* *******************************************************************************/
97  auto emptyGaussian = [](const Y& y) {
98  bool hasNull =
99  std::any_of(y.first.begin(), y.first.end(),
100  [](const GaussianFactor::shared_ptr& ptr) { return !ptr; });
101  return hasNull ? Y{GaussianFactorGraph(), 0.0} : y;
102  };
103  return {Base(*this, emptyGaussian)};
104 }
105 
106 /* *******************************************************************************/
107 std::istream& operator>>(std::istream& is, GaussianFactorGraphValuePair& pair) {
108  // Dummy, don't do anything
109  return is;
110 }
111 
112 } // namespace gtsam
GaussianFactorGraph.h
Linear Factor Graph where all factors are Gaussians.
gtsam::operator>>
istream & operator>>(istream &inputStream, Matrix &destinationMatrix)
Definition: Matrix.cpp:173
gtsam::HybridGaussianProductFactor::print
void print(const std::string &s="", const KeyFormatter &formatter=DefaultKeyFormatter) const
Print the HybridGaussianProductFactor.
Definition: HybridGaussianProductFactor.cpp:71
gtsam::add
static Y add(const Y &y1, const Y &y2)
Definition: HybridGaussianProductFactor.cpp:32
s
RealScalar s
Definition: level1_cplx_impl.h:126
types.h
Typedefs for easier changing of types.
keys
const KeyVector keys
Definition: testRegularImplicitSchurFactor.cpp:40
gtsam::GaussianFactorGraphValuePair
std::pair< GaussianFactorGraph, double > GaussianFactorGraphValuePair
Definition: HybridGaussianProductFactor.h:31
gtsam::Y
GaussianFactorGraphValuePair Y
Definition: HybridGaussianProductFactor.cpp:29
gtsam::DecisionTree< Key, GaussianFactorGraphValuePair >::equals
bool equals(const DecisionTree &other, const CompareFunc &compare=&DefaultCompare) const
Definition: DecisionTree-inl.h:972
formatter
const KeyFormatter & formatter
Definition: treeTraversal-inst.h:204
gtsam::HybridGaussianProductFactor
Alias for DecisionTree of GaussianFactorGraphs and their scalar sums.
Definition: HybridGaussianProductFactor.h:34
gtsam::DecisionTree< Key, GaussianFactorGraphValuePair >::print
void print(const std::string &s, const LabelFormatter &labelFormatter, const ValueFormatter &valueFormatter) const
GTSAM-style print.
Definition: DecisionTree-inl.h:978
gtsam::FastSet< Key >
any_of
negation< all_of< negation< Ts >... > > any_of
Definition: wrap/pybind11/include/pybind11/detail/common.h:742
gtsam::HybridGaussianProductFactor::Base
DecisionTree< Key, GaussianFactorGraphValuePair > Base
Definition: HybridGaussianProductFactor.h:37
result
Values result
Definition: OdometryOptimize.cpp:8
HybridGaussianFactor.h
A set of GaussianFactors, indexed by a set of discrete keys.
gtsam::GaussianFactorGraph
Definition: GaussianFactorGraph.h:73
y1
double y1(double x)
Definition: j1.c:199
gtsam::KeyFormatter
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
gtsam::HybridGaussianProductFactor::HybridGaussianProductFactor
HybridGaussianProductFactor()=default
Default constructor.
HybridGaussianProductFactor.h
DecisionTree.h
Decision Tree for use in DiscreteFactors.
gtsam::GaussianFactor::shared_ptr
std::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition: GaussianFactor.h:42
gtsam::HybridGaussianProductFactor::operator+
HybridGaussianProductFactor operator+(const GaussianFactor::shared_ptr &factor) const
Add GaussianFactor into HybridGaussianProductFactor.
Definition: HybridGaussianProductFactor.cpp:51
gtsam::HybridGaussianProductFactor::removeEmpty
HybridGaussianProductFactor removeEmpty() const
Remove empty GaussianFactorGraphs from the decision tree.
Definition: HybridGaussianProductFactor.cpp:96
gtsam::HybridGaussianProductFactor::equals
bool equals(const HybridGaussianProductFactor &other, double tol=1e-9) const
Check if this HybridGaussianProductFactor is equal to another.
Definition: HybridGaussianProductFactor.cpp:88
y
Scalar * y
Definition: level1_cplx_impl.h:124
gtsam::operator+
HybridGaussianProductFactor operator+(const HybridGaussianProductFactor &a, const HybridGaussianProductFactor &b)
Definition: HybridGaussianProductFactor.cpp:39
key
const gtsam::Symbol key('X', 0)
gtsam::b
const G & b
Definition: Group.h:79
a
ArrayXXi a
Definition: Array_initializer_list_23_cxx11.cpp:1
gtsam
traits
Definition: SFMdata.h:40
gtsam::HybridGaussianFactor::asProductFactor
virtual HybridGaussianProductFactor asProductFactor() const
Helper function to return factors and functional to create a DecisionTree of Gaussian Factor Graphs.
Definition: HybridGaussianFactor.cpp:166
gtsam::HybridGaussianProductFactor::operator+=
HybridGaussianProductFactor & operator+=(const GaussianFactor::shared_ptr &factor)
Add-assign operator for GaussianFactor.
Definition: HybridGaussianProductFactor.cpp:57
gtsam::HybridGaussianFactor
Implementation of a discrete-conditioned hybrid factor. Implements a joint discrete-continuous factor...
Definition: HybridGaussianFactor.h:60
gtsam::tol
const G double tol
Definition: Group.h:79
abs
#define abs(x)
Definition: datatypes.h:17
pybind_wrapper_test_script.other
other
Definition: pybind_wrapper_test_script.py:42


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:02:26