Loading...
Searching...
No Matches
Conditional.h
Go to the documentation of this file.
/* ----------------------------------------------------------------------------
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
* Atlanta, Georgia 30332-0415
* All Rights Reserved
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
* See LICENSE for the license information
* -------------------------------------------------------------------------- */
// \callgraph
#pragma once
#include <boost/range.hpp>
#include <gtsam/inference/Key.h>
namespace gtsam {
class HybridValues; // forward declaration.
template<class FACTOR, class DERIVEDCONDITIONAL>
class Conditional
{
protected:
size_t nrFrontals_;
private:
typedef Conditional<FACTOR,DERIVEDCONDITIONAL> This;
public:
typedef boost::iterator_range<typename FACTOR::const_iterator> Frontals;
typedef boost::iterator_range<typename FACTOR::const_iterator> Parents;
protected:
Conditional() : nrFrontals_(0) {}
Conditional(size_t nrFrontals) : nrFrontals_(nrFrontals) {}
public:
void print(const std::string& s = "Conditional", const KeyFormatter& formatter = DefaultKeyFormatter) const;
bool equals(const This& c, double tol = 1e-9) const;
virtual ~Conditional() {}
size_t nrFrontals() const { return nrFrontals_; }
size_t nrParents() const { return asFactor().size() - nrFrontals_; }
Key firstFrontalKey() const {
if(nrFrontals_ > 0)
return asFactor().front();
else
throw std::invalid_argument("Requested Conditional::firstFrontalKey from a conditional with zero frontal keys");
}
Frontals frontals() const { return boost::make_iterator_range(beginFrontals(), endFrontals()); }
Parents parents() const { return boost::make_iterator_range(beginParents(), endParents()); }
virtual double logProbability(const HybridValues& c) const;
virtual double evaluate(const HybridValues& c) const;
double operator()(const HybridValues& x) const {
return evaluate(x);
}
virtual double logNormalizationConstant() const;
double normalizationConstant() const;
typename FACTOR::const_iterator beginFrontals() const { return asFactor().begin(); }
typename FACTOR::const_iterator endFrontals() const { return asFactor().begin() + nrFrontals_; }
typename FACTOR::const_iterator beginParents() const { return endFrontals(); }
typename FACTOR::const_iterator endParents() const { return asFactor().end(); }
size_t& nrFrontals() { return nrFrontals_; }
typename FACTOR::iterator beginFrontals() { return asFactor().begin(); }
typename FACTOR::iterator endFrontals() { return asFactor().begin() + nrFrontals_; }
typename FACTOR::iterator beginParents() { return asFactor().begin() + nrFrontals_; }
typename FACTOR::iterator endParents() { return asFactor().end(); }
template <class VALUES>
static bool CheckInvariants(const DERIVEDCONDITIONAL& conditional,
const VALUES& x);
private:
// Cast to factor type (non-const) (casts down to derived conditional type, then up to factor type)
FACTOR& asFactor() { return static_cast<FACTOR&>(static_cast<DERIVEDCONDITIONAL&>(*this)); }
// Cast to derived type (const) (casts down to derived conditional type, then up to factor type)
const FACTOR& asFactor() const { return static_cast<const FACTOR&>(static_cast<const DERIVEDCONDITIONAL&>(*this)); }
friend class boost::serialization::access;
template<class ARCHIVE>
void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
ar & BOOST_SERIALIZATION_NVP(nrFrontals_);
}
};
} // gtsam
Key.h
gtsam
Global functions in a separate testing namespace.
Definition chartTesting.h:28
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::Key
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:100
gtsam::HybridValues
HybridValues represents a collection of DiscreteValues and VectorValues.
Definition HybridValues.h:38
gtsam::Conditional::CheckInvariants
static bool CheckInvariants(const DERIVEDCONDITIONAL &conditional, const VALUES &x)
Check invariants of this conditional, given the values x.
Definition Conditional-inst.h:77
gtsam::Conditional< BaseFactor, This >::nrFrontals_
size_t nrFrontals_
Definition Conditional.h:67
gtsam::Conditional::logNormalizationConstant
virtual double logNormalizationConstant() const
All conditional types need to implement a log normalization constant to make it such that error>=0.
Definition Conditional-inst.h:62
gtsam::Conditional::firstFrontalKey
Key firstFrontalKey() const
Convenience function to get the first frontal key.
Definition Conditional.h:116
gtsam::Conditional::endFrontals
FACTOR::const_iterator endFrontals() const
Iterator pointing past the last frontal key.
Definition Conditional.h:163
gtsam::Conditional::endParents
FACTOR::iterator endParents()
Mutable iterator pointing past the last parent key.
Definition Conditional.h:184
gtsam::Conditional::endFrontals
FACTOR::iterator endFrontals()
Mutable iterator pointing past the last frontal key.
Definition Conditional.h:178
gtsam::Conditional::evaluate
virtual double evaluate(const HybridValues &c) const
All conditional types need to implement an evaluate function, that yields a true probability.
Definition Conditional-inst.h:55
gtsam::Conditional::parents
Parents parents() const
return a view of the parent keys
Definition Conditional.h:127
gtsam::Conditional::equals
bool equals(const This &c, double tol=1e-9) const
check equality
Definition Conditional-inst.h:41
gtsam::Conditional::operator()
double operator()(const HybridValues &x) const
Evaluate probability density, sugar.
Definition Conditional.h:142
gtsam::Conditional< BaseFactor, This >::Parents
boost::iterator_range< typename BaseFactor::const_iterator > Parents
Definition Conditional.h:78
gtsam::Conditional::logProbability
virtual double logProbability(const HybridValues &c) const
All conditional types need to implement a logProbability function, for which exp(logProbability(x)) =...
Definition Conditional-inst.h:48
gtsam::Conditional< BaseFactor, This >::nrFrontals
size_t nrFrontals() const
Definition Conditional.h:110
gtsam::Conditional::Conditional
Conditional()
Empty Constructor to make serialization possible.
Definition Conditional.h:85
gtsam::Conditional::Conditional
Conditional(size_t nrFrontals)
Constructor.
Definition Conditional.h:88
gtsam::Conditional::beginParents
FACTOR::iterator beginParents()
Mutable iterator pointing to the first parent key.
Definition Conditional.h:181
gtsam::Conditional::nrFrontals
size_t & nrFrontals()
Mutable version of nrFrontals.
Definition Conditional.h:172
gtsam::Conditional::beginFrontals
FACTOR::iterator beginFrontals()
Mutable iterator pointing to first frontal key.
Definition Conditional.h:175
gtsam::Conditional< BaseFactor, This >::Frontals
boost::iterator_range< typename BaseFactor::const_iterator > Frontals
Definition Conditional.h:75
gtsam::Conditional::frontals
Frontals frontals() const
return a view of the frontal keys
Definition Conditional.h:124
gtsam::Conditional::beginFrontals
FACTOR::const_iterator beginFrontals() const
Iterator pointing to first frontal key.
Definition Conditional.h:160
gtsam::Conditional::normalizationConstant
double normalizationConstant() const
Non-virtual, exponentiate logNormalizationConstant.
Definition Conditional-inst.h:70
gtsam::Conditional::nrParents
size_t nrParents() const
return the number of parents
Definition Conditional.h:113
gtsam::Conditional::print
void print(const std::string &s="Conditional", const KeyFormatter &formatter=DefaultKeyFormatter) const
print with optional formatter
Definition Conditional-inst.h:30
gtsam::Conditional::endParents
FACTOR::const_iterator endParents() const
Iterator pointing past the last parent key.
Definition Conditional.h:169
gtsam::Conditional::beginParents
FACTOR::const_iterator beginParents() const
Iterator pointing to the first parent key.
Definition Conditional.h:166