GaussianBayesTree.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 
27 
28 namespace gtsam {
29 
30  // Instantiate base class
31  template class BayesTreeCliqueBase<GaussianBayesTreeClique, GaussianFactorGraph>;
32  template class BayesTree<GaussianBayesTreeClique>;
33 
34  /* ************************************************************************ */
35  namespace internal {
36 
43  // Use pointer so we can get the full result after tree traversal
44  double* logDet;
45  LogDeterminantData(double* logDet)
46  : logDet(logDet) {}
47  };
48  /* ************************************************************************ */
51  LogDeterminantData& parentSum) {
52  auto cg = clique->conditional();
53  double logDet = cg->logDeterminant();
54  // Add the current clique's log-determinant to the overall sum
55  (*parentSum.logDet) += logDet;
56  return parentSum;
57  }
58  } // namespace internal
59 
60  /* ************************************************************************* */
61  bool GaussianBayesTree::equals(const This& other, double tol) const
62  {
63  return Base::equals(other, tol);
64  }
65 
66  /* ************************************************************************* */
68  {
70  }
71 
72  /* ************************************************************************* */
74  {
75  gttic(GaussianBayesTree_optimizeGradientSearch);
77  }
78 
79  /* ************************************************************************* */
81  return GaussianFactorGraph(*this).gradient(x0);
82  }
83 
84  /* ************************************************************************* */
86  return GaussianFactorGraph(*this).gradientAtZero();
87  }
88 
89  /* ************************************************************************* */
90  double GaussianBayesTree::error(const VectorValues& x) const {
91  return GaussianFactorGraph(*this).error(x);
92  }
93 
94  /* ************************************************************************* */
96  {
97  if(this->roots_.empty()) {
98  return 0.0;
99  } else {
100  double sum = 0.0;
101  // Store the log-determinant in this struct.
102  internal::LogDeterminantData rootData(&sum);
103  // No need to do anything for post-operation.
104  treeTraversal::no_op visitorPost;
105  // Limits OpenMP threads if we're mixing TBB and OpenMP
106  TbbOpenMPMixedScope threadLimiter;
107  // Traverse the GaussianBayesTree depth first and call logDeterminant on each node.
109  return sum;
110  }
111  }
112 
113  /* ************************************************************************* */
115  {
116  return exp(logDeterminant());
117  }
118 
119  /* ************************************************************************* */
121  {
122  return marginalFactor(key)->information().inverse();
123  }
124 
125 
126 } // \namespace gtsam
gtsam::GaussianBayesTree::equals
bool equals(const This &other, double tol=1e-9) const
Definition: GaussianBayesTree.cpp:61
treeTraversal-inst.h
gtsam::BayesTree< GaussianBayesTreeClique >::roots_
Roots roots_
Definition: BayesTree.h:103
x
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
Definition: gnuplot_common_settings.hh:12
gtsam::GaussianBayesTree::optimizeGradientSearch
VectorValues optimizeGradientSearch() const
Definition: GaussianBayesTree.cpp:73
gtsam::GaussianBayesTree::gradientAtZero
VectorValues gradientAtZero() const
Definition: GaussianBayesTree.cpp:85
gtsam::Matrix
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:39
gtsam::BayesTree< GaussianBayesTreeClique >::marginalFactor
sharedConditional marginalFactor(Key j, const Eliminate &function=EliminationTraitsType::DefaultEliminate) const
Definition: BayesTree-inst.h:309
GaussianBayesNet.h
Chordal Bayes Net, the result of eliminating a factor graph.
exp
const EIGEN_DEVICE_FUNC ExpReturnType exp() const
Definition: ArrayCwiseUnaryOps.h:97
gtsam::internal::LogDeterminantData::LogDeterminantData
LogDeterminantData(double *logDet)
Definition: GaussianBayesTree.cpp:45
gtsam::internal::LogDeterminantData
Struct to help with traversing the Bayes Tree for log-determinant computation. Records the data which...
Definition: GaussianBayesTree.cpp:42
gtsam::GaussianFactorGraph::gradient
VectorValues gradient(const VectorValues &x0) const
Definition: GaussianFactorGraph.cpp:357
gtsam::GaussianFactorGraph
Definition: GaussianFactorGraph.h:73
gtsam::VectorValues
Definition: VectorValues.h:74
gtsam::GaussianFactorGraph::gradientAtZero
virtual VectorValues gradientAtZero() const
Definition: GaussianFactorGraph.cpp:369
gtsam::internal::logDeterminant
double logDeterminant(const typename BAYESTREE::sharedClique &clique)
Definition: GaussianBayesTree-inl.h:42
x0
static Symbol x0('x', 0)
VectorValues.h
Factor Graph Values.
gtsam::GaussianBayesTree::optimize
VectorValues optimize() const
Definition: GaussianBayesTree.cpp:67
gtsam::internal::linearAlgorithms::optimizeBayesTree
VectorValues optimizeBayesTree(const BAYESTREE &bayesTree)
Definition: linearAlgorithms-inst.h:143
linearAlgorithms-inst.h
Templated algorithms that are used in multiple places in linear.
key
const gtsam::Symbol key('X', 0)
gtsam::GaussianFactorGraph::optimizeGradientSearch
VectorValues optimizeGradientSearch() const
Definition: GaussianFactorGraph.cpp:381
gtsam::treeTraversal::DepthFirstForestParallel
void DepthFirstForestParallel(FOREST &forest, DATA &rootData, VISITOR_PRE &visitorPre, VISITOR_POST &visitorPost, int problemSizeThreshold=10)
Definition: treeTraversal-inst.h:156
gtsam
traits
Definition: SFMdata.h:40
gtsam::GaussianBayesTree
Definition: GaussianBayesTree.h:49
gtsam::GaussianFactorGraph::error
double error(const VectorValues &x) const
Definition: GaussianFactorGraph.cpp:71
gtsam::internal::LogDeterminantData::logDet
double * logDet
Definition: GaussianBayesTree.cpp:44
GaussianBayesTree.h
Gaussian Bayes Tree, the result of eliminating a GaussianJunctionTree.
gtsam::tol
const G double tol
Definition: Group.h:79
gtsam::GaussianBayesTree::determinant
double determinant() const
Definition: GaussianBayesTree.cpp:114
gtsam::GaussianBayesTree::marginalCovariance
Matrix marginalCovariance(Key key) const
Definition: GaussianBayesTree.cpp:120
gtsam::BayesTree< GaussianBayesTreeClique >::equals
bool equals(const This &other, double tol=1e-9) const
Definition: BayesTree-inst.h:269
BayesTreeCliqueBase-inst.h
Base class for cliques of a BayesTree.
gtsam::GaussianBayesTree::error
double error(const VectorValues &x) const
Definition: GaussianBayesTree.cpp:90
gtsam::GaussianBayesTree::logDeterminant
double logDeterminant() const
Definition: GaussianBayesTree.cpp:95
BayesTree-inst.h
Bayes Tree is a tree of cliques of a Bayes Chain.
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:97
gtsam::TbbOpenMPMixedScope
Definition: types.h:162
pybind_wrapper_test_script.other
other
Definition: pybind_wrapper_test_script.py:42
gttic
#define gttic(label)
Definition: timing.h:295
gtsam::internal::logDeterminant
LogDeterminantData & logDeterminant(const GaussianBayesTreeClique::shared_ptr &clique, LogDeterminantData &parentSum)
Definition: GaussianBayesTree.cpp:49
gtsam::GaussianBayesTreeClique::shared_ptr
std::shared_ptr< This > shared_ptr
Definition: GaussianBayesTree.h:41
gtsam::GaussianBayesTree::gradient
VectorValues gradient(const VectorValues &x0) const
Definition: GaussianBayesTree.cpp:80


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