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  const {
64  throw std::runtime_error(
65  "Conditional::logNormalizationConstant is not implemented");
66 }
67 
68 /* ************************************************************************* */
69 template <class FACTOR, class DERIVEDCONDITIONAL>
71  return std::exp(logNormalizationConstant());
72 }
73 
74 /* ************************************************************************* */
75 template <class FACTOR, class DERIVEDCONDITIONAL>
76 template <class VALUES>
78  const DERIVEDCONDITIONAL& conditional, const VALUES& values) {
79  const double prob_or_density = conditional.evaluate(values);
80  if (prob_or_density < 0.0) return false; // prob_or_density is negative.
81  if (std::abs(prob_or_density - conditional(values)) > 1e-9)
82  return false; // operator and evaluate differ
83  const double logProb = conditional.logProbability(values);
84  if (std::abs(prob_or_density - std::exp(logProb)) > 1e-9)
85  return false; // logProb is not consistent with prob_or_density
86  if (std::abs(conditional.logNormalizationConstant() -
87  std::log(conditional.normalizationConstant())) > 1e-9)
88  return false; // log normalization constant is not consistent with
89  // normalization constant
90  const double error = conditional.error(values);
91  if (error < 0.0) return false; // prob_or_density is negative.
92  const double expected = conditional.logNormalizationConstant() - error;
93  if (std::abs(logProb - expected) > 1e-9)
94  return false; // logProb is not consistent with error
95  return true;
96 }
97 
98 } // namespace gtsam
const gtsam::Symbol key('X', 0)
Base class for conditional densities.
virtual double logProbability(const HybridValues &c) const
Matrix expected
Definition: testMatrix.cpp:971
static bool CheckInvariants(const DERIVEDCONDITIONAL &conditional, const VALUES &x)
Scalar Scalar * c
Definition: benchVecAdd.cpp:17
leaf::MyValues values
virtual double evaluate(const HybridValues &c) const
EIGEN_DEVICE_FUNC const LogReturnType log() const
double normalizationConstant() const
const KeyFormatter & formatter
EIGEN_DEVICE_FUNC const ExpReturnType exp() const
Array< double, 1, 3 > e(1./3., 0.5, 2.)
RealScalar s
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
traits
Definition: chartTesting.h:28
static double error
Definition: testRot3.cpp:37
void print(const std::string &s="Conditional", const KeyFormatter &formatter=DefaultKeyFormatter) const
const G double tol
Definition: Group.h:86
#define abs(x)
Definition: datatypes.h:17
virtual double logNormalizationConstant() const
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:102
bool equals(const This &c, double tol=1e-9) const


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