Conditional.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 
21 #include <gtsam/inference/Key.h>
22 
23 namespace gtsam {
24 
25  class HybridValues; // forward declaration.
26 
62  template<class FACTOR, class DERIVEDCONDITIONAL>
64  {
65  protected:
67  size_t nrFrontals_;
68 
69  private:
72 
73 
74  public:
77  typedef std::pair<typename FACTOR::const_iterator, typename FACTOR::const_iterator> ConstFactorRange;
80  // Delete default constructor
81  ConstFactorRangeIterator() = delete;
83  // Implement begin and end for iteration
84  typename FACTOR::const_iterator begin() const { return range_.first; }
85  typename FACTOR::const_iterator end() const { return range_.second; }
86  size_t size() const { return std::distance(range_.first, range_.second); }
87  const auto& front() const { return *begin(); }
88  // == operator overload for comparison with another iterator
89  template<class OTHER>
90  bool operator==(const OTHER& rhs) const {
91  return std::equal(begin(), end(), rhs.begin());
92  }
93  };
94 
96  typedef ConstFactorRangeIterator Frontals;
97 
99  typedef ConstFactorRangeIterator Parents;
100 
101  protected:
104 
107 
110 
112 
113  public:
116 
118  void print(const std::string& s = "Conditional", const KeyFormatter& formatter = DefaultKeyFormatter) const;
119 
121  bool equals(const This& c, double tol = 1e-9) const;
122 
124 
127 
128  virtual ~Conditional() {}
129 
131  size_t nrFrontals() const { return nrFrontals_; }
132 
134  size_t nrParents() const { return asFactor().size() - nrFrontals_; }
135 
138  if(nrFrontals_ > 0)
139  return asFactor().front();
140  else
141  throw std::invalid_argument("Requested Conditional::firstFrontalKey from a conditional with zero frontal keys");
142  }
143 
145  Frontals frontals() const { return ConstFactorRangeIterator({beginFrontals(), endFrontals()});}
146 
148  Parents parents() const { return ConstFactorRangeIterator({beginParents(), endParents()}); }
149 
154  virtual double logProbability(const HybridValues& c) const;
155 
160  virtual double evaluate(const HybridValues& c) const;
161 
163  double operator()(const HybridValues& x) const {
164  return evaluate(x);
165  }
166 
173  virtual double negLogConstant() const;
174 
178 
180  typename FACTOR::const_iterator beginFrontals() const { return asFactor().begin(); }
181 
183  typename FACTOR::const_iterator endFrontals() const { return asFactor().begin() + nrFrontals_; }
184 
186  typename FACTOR::const_iterator beginParents() const { return endFrontals(); }
187 
189  typename FACTOR::const_iterator endParents() const { return asFactor().end(); }
190 
192  size_t& nrFrontals() { return nrFrontals_; }
193 
195  typename FACTOR::iterator beginFrontals() { return asFactor().begin(); }
196 
198  typename FACTOR::iterator endFrontals() { return asFactor().begin() + nrFrontals_; }
199 
201  typename FACTOR::iterator beginParents() { return asFactor().begin() + nrFrontals_; }
202 
204  typename FACTOR::iterator endParents() { return asFactor().end(); }
205 
219  template <class VALUES>
220  static bool CheckInvariants(const DERIVEDCONDITIONAL& conditional,
221  const VALUES& x);
222 
224 
225  private:
226 
229 
230  // Cast to factor type (non-const) (casts down to derived conditional type, then up to factor type)
231  FACTOR& asFactor() { return static_cast<FACTOR&>(static_cast<DERIVEDCONDITIONAL&>(*this)); }
232 
233  // Cast to derived type (const) (casts down to derived conditional type, then up to factor type)
234  const FACTOR& asFactor() const { return static_cast<const FACTOR&>(static_cast<const DERIVEDCONDITIONAL&>(*this)); }
235 
236 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
237 
238  friend class boost::serialization::access;
239  template<class ARCHIVE>
240  void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
241  ar & BOOST_SERIALIZATION_NVP(nrFrontals_);
242  }
243 #endif
244 
246 
247  };
248 
249 } // gtsam
gtsam::Conditional::~Conditional
virtual ~Conditional()
Definition: Conditional.h:128
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
gtsam::Conditional::ConstFactorRangeIterator::operator==
bool operator==(const OTHER &rhs) const
Definition: Conditional.h:90
gtsam::Conditional::asFactor
const FACTOR & asFactor() const
Definition: Conditional.h:234
c
Scalar Scalar * c
Definition: benchVecAdd.cpp:17
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::Conditional::ConstFactorRangeIterator::ConstFactorRangeIterator
ConstFactorRangeIterator(ConstFactorRange const &x)
Definition: Conditional.h:82
formatter
const KeyFormatter & formatter
Definition: treeTraversal-inst.h:204
gtsam::Conditional::ConstFactorRangeIterator::front
const auto & front() const
Definition: Conditional.h:87
gtsam::Conditional::ConstFactorRangeIterator
Definition: Conditional.h:78
gtsam::Conditional::Conditional
Conditional(size_t nrFrontals)
Definition: Conditional.h:109
gtsam::Conditional::evaluate
virtual double evaluate(const HybridValues &c) const
Definition: Conditional-inst.h:55
HybridValues
gtsam::Conditional::ConstFactorRangeIterator::begin
FACTOR::const_iterator begin() const
Definition: Conditional.h:84
gtsam::Conditional::ConstFactorRangeIterator::size
size_t size() const
Definition: Conditional.h:86
gtsam::Conditional::ConstFactorRangeIterator::range_
ConstFactorRange range_
Definition: Conditional.h:79
gtsam::Conditional::operator()
double operator()(const HybridValues &x) const
Evaluate probability density, sugar.
Definition: Conditional.h:163
gtsam::DefaultKeyFormatter
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition: Key.cpp:30
gtsam::Conditional::logProbability
virtual double logProbability(const HybridValues &c) const
Definition: Conditional-inst.h:48
gtsam::Conditional::This
Conditional< FACTOR, DERIVEDCONDITIONAL > This
Typedef to this class.
Definition: Conditional.h:71
gtsam::Conditional::asFactor
FACTOR & asFactor()
Definition: Conditional.h:231
gtsam::Conditional::endParents
FACTOR::const_iterator endParents() const
Definition: Conditional.h:189
Key.h
gtsam::Conditional::ConstFactorRangeIterator::ConstFactorRangeIterator
ConstFactorRangeIterator()=delete
gtsam::Conditional::Conditional
Conditional()
Definition: Conditional.h:106
gtsam::Conditional::endFrontals
FACTOR::const_iterator endFrontals() const
Definition: Conditional.h:183
gtsam::Conditional::ConstFactorRange
std::pair< typename FACTOR::const_iterator, typename FACTOR::const_iterator > ConstFactorRange
Definition: Conditional.h:77
gtsam::Conditional::Frontals
ConstFactorRangeIterator Frontals
Definition: Conditional.h:96
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::beginParents
FACTOR::iterator beginParents()
Definition: Conditional.h:201
gtsam::Conditional::CheckInvariants
static bool CheckInvariants(const DERIVEDCONDITIONAL &conditional, const VALUES &x)
Definition: Conditional-inst.h:69
gtsam::Conditional::nrFrontals_
size_t nrFrontals_
Definition: Conditional.h:67
gtsam::Conditional::endFrontals
FACTOR::iterator endFrontals()
Definition: Conditional.h:198
gtsam::Conditional::beginFrontals
FACTOR::const_iterator beginFrontals() const
Definition: Conditional.h:180
gtsam::Conditional
Definition: Conditional.h:63
gtsam::Conditional::parents
Parents parents() const
Definition: Conditional.h:148
gtsam::Conditional::nrFrontals
size_t nrFrontals() const
Definition: Conditional.h:131
gtsam::Conditional::ConstFactorRangeIterator::end
FACTOR::const_iterator end() const
Definition: Conditional.h:85
gtsam::Conditional::beginParents
FACTOR::const_iterator beginParents() const
Definition: Conditional.h:186
gtsam::Conditional::nrFrontals
size_t & nrFrontals()
Definition: Conditional.h:192
gtsam::Conditional::firstFrontalKey
Key firstFrontalKey() const
Definition: Conditional.h:137
gtsam
traits
Definition: SFMdata.h:40
gtsam::Conditional::beginFrontals
FACTOR::iterator beginFrontals()
Definition: Conditional.h:195
gtsam::tol
const G double tol
Definition: Group.h:79
gtsam::distance
Double_ distance(const OrientedPlane3_ &p)
Definition: slam/expressions.h:117
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::Conditional::frontals
Frontals frontals() const
Definition: Conditional.h:145
gtsam::Conditional::endParents
FACTOR::iterator endParents()
Definition: Conditional.h:204
gtsam::equal
bool equal(const T &obj1, const T &obj2, double tol)
Definition: Testable.h:85
gtsam::Conditional::nrParents
size_t nrParents() const
Definition: Conditional.h:134
gtsam::Conditional::Parents
ConstFactorRangeIterator Parents
Definition: Conditional.h:99


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