Conditional-inst.h
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 
18 // \callgraph
19 #pragma once
20 
22 
23 #include <cmath>
24 #include <iostream>
25 
26 namespace gtsam {
27 
28 /* ************************************************************************* */
29 template <class FACTOR, class DERIVEDCONDITIONAL>
31  const std::string& s, const KeyFormatter& formatter) const {
32  std::cout << s << " P(";
33  for (Key key : frontals()) std::cout << " " << formatter(key);
34  if (nrParents() > 0) std::cout << " |";
35  for (Key parent : parents()) std::cout << " " << formatter(parent);
36  std::cout << ")" << std::endl;
37 }
38 
39 /* ************************************************************************* */
40 template <class FACTOR, class DERIVEDCONDITIONAL>
42  double tol) const {
43  return nrFrontals_ == c.nrFrontals_;
44 }
45 
46 /* ************************************************************************* */
47 template <class FACTOR, class DERIVEDCONDITIONAL>
49  const HybridValues& c) const {
50  throw std::runtime_error("Conditional::logProbability is not implemented");
51 }
52 
53 /* ************************************************************************* */
54 template <class FACTOR, class DERIVEDCONDITIONAL>
56  const HybridValues& c) const {
57  throw std::runtime_error("Conditional::evaluate is not implemented");
58 }
59 
60 /* ************************************************************************* */
61 template <class FACTOR, class DERIVEDCONDITIONAL>
63  throw std::runtime_error("Conditional::negLogConstant is not implemented");
64 }
65 
66 /* ************************************************************************* */
67 template <class FACTOR, class DERIVEDCONDITIONAL>
68 template <class VALUES>
70  const DERIVEDCONDITIONAL& conditional, const VALUES& values) {
71  const double prob_or_density = conditional.evaluate(values);
72  if (prob_or_density < 0.0) return false; // prob_or_density is negative.
73  if (std::abs(prob_or_density - conditional(values)) > 1e-9)
74  return false; // operator and evaluate differ
75  const double logProb = conditional.logProbability(values);
76  if (std::abs(prob_or_density - std::exp(logProb)) > 1e-9)
77  return false; // logProb is not consistent with prob_or_density
78  const double error = conditional.error(values);
79  if (error < 0.0) return false; // prob_or_density is negative.
80  const double expected = -(conditional.negLogConstant() + error);
81  if (std::abs(logProb - expected) > 1e-9)
82  return false; // logProb is not consistent with error
83  return true;
84 }
85 
86 } // namespace gtsam
gtsam::Conditional::print
void print(const std::string &s="Conditional", const KeyFormatter &formatter=DefaultKeyFormatter) const
Definition: Conditional-inst.h:30
gtsam::HybridValues
Definition: HybridValues.h:37
s
RealScalar s
Definition: level1_cplx_impl.h:126
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
gtsam::Conditional::equals
bool equals(const This &c, double tol=1e-9) const
Definition: Conditional-inst.h:41
c
Scalar Scalar * c
Definition: benchVecAdd.cpp:17
formatter
const KeyFormatter & formatter
Definition: treeTraversal-inst.h:204
different_sigmas::values
HybridValues values
Definition: testHybridBayesNet.cpp:245
gtsam::Conditional::evaluate
virtual double evaluate(const HybridValues &c) const
Definition: Conditional-inst.h:55
exp
const EIGEN_DEVICE_FUNC ExpReturnType exp() const
Definition: ArrayCwiseUnaryOps.h:97
gtsam::Conditional::logProbability
virtual double logProbability(const HybridValues &c) const
Definition: Conditional-inst.h:48
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::Conditional::CheckInvariants
static bool CheckInvariants(const DERIVEDCONDITIONAL &conditional, const VALUES &x)
Definition: Conditional-inst.h:69
cholesky::expected
Matrix expected
Definition: testMatrix.cpp:971
gtsam::Conditional< HybridFactor, HybridConditional >
key
const gtsam::Symbol key('X', 0)
gtsam
traits
Definition: SFMdata.h:40
error
static double error
Definition: testRot3.cpp:37
gtsam::tol
const G double tol
Definition: Group.h:79
abs
#define abs(x)
Definition: datatypes.h:17
Conditional.h
Base class for conditional densities.
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:97
gtsam::Conditional::negLogConstant
virtual double negLogConstant() const
All conditional types need to implement this as the negative log of the normalization constant to mak...
Definition: Conditional-inst.h:62


gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:11:17