DiscreteFactor.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 
20 #include <gtsam/base/Vector.h>
23 
24 #include <cmath>
25 #include <sstream>
26 
27 using namespace std;
28 
29 namespace gtsam {
30 
31 /* ************************************************************************* */
32 bool DiscreteFactor::equals(const DiscreteFactor& lf, double tol) const {
33  return Base::equals(lf, tol) && cardinalities_ == lf.cardinalities_;
34 }
35 
36 /* ************************************************************************ */
37 DiscreteKeys DiscreteFactor::discreteKeys() const {
39  for (auto&& key : keys()) {
40  DiscreteKey dkey(key, cardinality(key));
41  if (std::find(result.begin(), result.end(), dkey) == result.end()) {
42  result.push_back(dkey);
43  }
44  }
45  return result;
46 }
47 
48 /* ************************************************************************* */
50  return -std::log((*this)(values));
51 }
52 
53 /* ************************************************************************* */
54 double DiscreteFactor::error(const HybridValues& c) const {
55  return this->error(c.discrete());
56 }
57 
58 /* ************************************************************************ */
59 AlgebraicDecisionTree<Key> DiscreteFactor::errorTree() const {
60  // Get all possible assignments
61  DiscreteKeys dkeys = discreteKeys();
62  // Reverse to make cartesian product output a more natural ordering.
63  DiscreteKeys rdkeys(dkeys.rbegin(), dkeys.rend());
64  const auto assignments = DiscreteValues::CartesianProduct(rdkeys);
65 
66  // Construct vector with error values
67  std::vector<double> errors;
68  for (const auto& assignment : assignments) {
69  errors.push_back(error(assignment));
70  }
71  return AlgebraicDecisionTree<Key>(dkeys, errors);
72 }
73 
74 /* ************************************************************************ */
76  return this->operator*(1.0 / max());
77 }
78 
79 } // namespace gtsam
gtsam::HybridValues
Definition: HybridValues.h:37
Vector.h
typedef and functions to augment Eigen's VectorXd
keys
const KeyVector keys
Definition: testRegularImplicitSchurFactor.cpp:40
c
Scalar Scalar * c
Definition: benchVecAdd.cpp:17
gtsam::DiscreteFactor::cardinalities_
std::map< Key, size_t > cardinalities_
Map of Keys and their cardinalities.
Definition: DiscreteFactor.h:57
different_sigmas::values
HybridValues values
Definition: testHybridBayesNet.cpp:247
log
const EIGEN_DEVICE_FUNC LogReturnType log() const
Definition: ArrayCwiseUnaryOps.h:128
gtsam::DiscreteKeys
DiscreteKeys is a set of keys that can be assembled using the & operator.
Definition: DiscreteKey.h:41
result
Values result
Definition: OdometryOptimize.cpp:8
gtsam::AlgebraicDecisionTree< Key >
scale
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 y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set set set set surface set nocontour set clabel set mapping cartesian set nohidden3d set cntrparam order set cntrparam linear set cntrparam levels auto set cntrparam points set size set set xzeroaxis lt lw set x2zeroaxis lt lw set yzeroaxis lt lw set y2zeroaxis lt lw set tics in set ticslevel set tics scale
Definition: gnuplot_common_settings.hh:54
DiscreteFactor.h
key
const gtsam::Symbol key('X', 0)
gtsam
traits
Definition: SFMdata.h:40
gtsam::DiscreteFactor::shared_ptr
std::shared_ptr< DiscreteFactor > shared_ptr
shared_ptr to this class
Definition: DiscreteFactor.h:45
error
static double error
Definition: testRot3.cpp:37
gtsam::DiscreteValues
Definition: DiscreteValues.h:34
gtsam::DiscreteKey
std::pair< Key, size_t > DiscreteKey
Definition: DiscreteKey.h:38
std
Definition: BFloat16.h:88
gtsam::HybridValues::discrete
const DiscreteValues & discrete() const
Return the discrete values.
Definition: HybridValues.cpp:57
gtsam::tol
const G double tol
Definition: Group.h:79
gtsam::DiscreteFactor
Definition: DiscreteFactor.h:40
max
#define max(a, b)
Definition: datatypes.h:20
HybridValues.h
operator*
Vector3_ operator*(const Double_ &s, const Vector3_ &v)
Definition: InverseKinematicsExampleExpressions.cpp:42


gtsam
Author(s):
autogenerated on Wed Mar 19 2025 03:01:36