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
const gtsam::Symbol key('X', 0)
Struct to help with traversing the Bayes Tree for log-determinant computation. Records the data which...
Matrix marginalCovariance(Key key) const
VectorValues optimizeGradientSearch() const
double logDeterminant(const typename BAYESTREE::sharedClique &clique)
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:39
Base class for cliques of a BayesTree.
bool equals(const This &other, double tol=1e-9) const
double error(const VectorValues &x) const
std::shared_ptr< This > shared_ptr
bool equals(const This &other, double tol=1e-9) const
EIGEN_DEVICE_FUNC const ExpReturnType exp() const
double error(const VectorValues &x) const
#define gttic(label)
Definition: timing.h:295
Factor Graph Values.
VectorValues optimize() const
void DepthFirstForestParallel(FOREST &forest, DATA &rootData, VISITOR_PRE &visitorPre, VISITOR_POST &visitorPost, int problemSizeThreshold=10)
VectorValues optimizeGradientSearch() const
Templated algorithms that are used in multiple places in linear.
VectorValues gradient(const VectorValues &x0) const
VectorValues optimizeBayesTree(const BAYESTREE &bayesTree)
Bayes Tree is a tree of cliques of a Bayes Chain.
traits
Definition: chartTesting.h:28
static Symbol x0('x', 0)
VectorValues gradientAtZero() const
Chordal Bayes Net, the result of eliminating a factor graph.
VectorValues gradient(const VectorValues &x0) const
const G double tol
Definition: Group.h:86
LogDeterminantData & logDeterminant(const GaussianBayesTreeClique::shared_ptr &clique, LogDeterminantData &parentSum)
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
virtual VectorValues gradientAtZero() const
sharedConditional marginalFactor(Key j, const Eliminate &function=EliminationTraitsType::DefaultEliminate) const
Gaussian Bayes Tree, the result of eliminating a GaussianJunctionTree.
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:102


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