gtsam  4.0.0
gtsam
gtsam::DiscreteConditional Class Reference

Detailed Description

Discrete Conditional Density Derives from DecisionTreeFactor.

+ Inheritance diagram for gtsam::DiscreteConditional:

Standard Constructors

 DiscreteConditional ()
 default constructor needed for serialization
 
 DiscreteConditional (size_t nFrontals, const DecisionTreeFactor &f)
 constructor from factor
 
 DiscreteConditional (const Signature &signature)
 Construct from signature.
 
 DiscreteConditional (const DecisionTreeFactor &joint, const DecisionTreeFactor &marginal, const boost::optional< Ordering > &orderedKeys=boost::none)
 construct P(X|Y)=P(X,Y)/P(Y) from P(X,Y) and P(Y)
 
template<typename ITERATOR >
static shared_ptr Combine (ITERATOR firstConditional, ITERATOR lastConditional)
 Combine several conditional into a single one. More...
 

Public Member Functions

Testable
void print (const std::string &s="Discrete Conditional: ", const KeyFormatter &formatter=DefaultKeyFormatter) const
 GTSAM-style print.
 
bool equals (const DiscreteFactor &other, double tol=1e-9) const
 GTSAM-style equals.
 
Standard Interface
virtual double operator() (const Values &values) const
 Evaluate, just look up in AlgebraicDecisonTree.
 
DecisionTreeFactor::shared_ptr toFactor () const
 Convert to a factor.
 
ADT choose (const Assignment< Key > &parentsValues) const
 Restrict to given parent values, returns AlgebraicDecisionDiagram.
 
size_t solve (const Values &parentsValues) const
 solve a conditional More...
 
size_t sample (const Values &parentsValues) const
 sample More...
 
Advanced Interface
void solveInPlace (Values &parentsValues) const
 solve a conditional, in place
 
void sampleInPlace (Values &parentsValues) const
 sample in place, stores result in partial solution
 
- Public Member Functions inherited from gtsam::DecisionTreeFactor
 DecisionTreeFactor ()
 Default constructor for I/O.
 
 DecisionTreeFactor (const DiscreteKeys &keys, const ADT &potentials)
 Constructor from Indices, Ordering, and AlgebraicDecisionDiagram.
 
template<class SOURCE >
 DecisionTreeFactor (const DiscreteKeys &keys, SOURCE table)
 Constructor from Indices and (string or doubles)
 
 DecisionTreeFactor (const DiscreteConditional &c)
 Construct from a DiscreteConditional type.
 
DecisionTreeFactor operator * (const DecisionTreeFactor &f) const
 multiply two factors
 
DecisionTreeFactor operator/ (const DecisionTreeFactor &f) const
 divide by factor f (safely)
 
virtual DecisionTreeFactor toDecisionTreeFactor () const
 Convert into a decisiontree.
 
shared_ptr sum (size_t nrFrontals) const
 Create new factor by summing all values with the same separator values.
 
shared_ptr sum (const Ordering &keys) const
 Create new factor by summing all values with the same separator values.
 
shared_ptr max (size_t nrFrontals) const
 Create new factor by maximizing over all values with the same separator values.
 
DecisionTreeFactor apply (const DecisionTreeFactor &f, ADT::Binary op) const
 Apply binary operator (*this) "op" f. More...
 
shared_ptr combine (size_t nrFrontals, ADT::Binary op) const
 Combine frontal variables using binary operator "op". More...
 
shared_ptr combine (const Ordering &keys, ADT::Binary op) const
 Combine frontal variables in an Ordering using binary operator "op". More...
 
- Public Member Functions inherited from gtsam::DiscreteFactor
 DiscreteFactor ()
 Default constructor creates empty factor.
 
template<typename CONTAINER >
 DiscreteFactor (const CONTAINER &keys)
 Construct from container of keys. More...
 
virtual ~DiscreteFactor ()
 Virtual destructor.
 
virtual bool empty () const
 Test whether the factor is empty.
 
- Public Member Functions inherited from gtsam::Factor
KeyVectorkeys ()
 
iterator begin ()
 Iterator at beginning of involved variable keys.
 
iterator end ()
 Iterator at end of involved variable keys.
 
void print (const std::string &s="Factor", const KeyFormatter &formatter=DefaultKeyFormatter) const
 print
 
void printKeys (const std::string &s="Factor", const KeyFormatter &formatter=DefaultKeyFormatter) const
 print only keys
 
Key front () const
 First key.
 
Key back () const
 Last key.
 
const_iterator find (Key key) const
 find
 
const KeyVectorkeys () const
 Access the factor's involved variable keys.
 
const_iterator begin () const
 Iterator at beginning of involved variable keys.
 
const_iterator end () const
 Iterator at end of involved variable keys.
 
size_t size () const
 
- Public Member Functions inherited from gtsam::Potentials
GTSAM_EXPORT Potentials ()
 Default constructor for I/O.
 
GTSAM_EXPORT Potentials (const DiscreteKeys &keys, const ADT &decisionTree)
 Constructor from Indices and ADT.
 
template<class SOURCE >
 Potentials (const DiscreteKeys &keys, SOURCE table)
 Constructor from Indices and (string or doubles)
 
GTSAM_EXPORT bool equals (const Potentials &other, double tol=1e-9) const
 
GTSAM_EXPORT void print (const std::string &s="Potentials: ", const KeyFormatter &formatter=DefaultKeyFormatter) const
 
size_t cardinality (Key j) const
 
- Public Member Functions inherited from gtsam::AlgebraicDecisionTree< Key >
 AlgebraicDecisionTree (const Super &add)
 
 AlgebraicDecisionTree (const Key &label, double y1, double y2)
 Create a new leaf function splitting on a variable.
 
 AlgebraicDecisionTree (const typename Super::LabelC &labelC, double y1, double y2)
 Create a new leaf function splitting on a variable.
 
 AlgebraicDecisionTree (const std::vector< typename Super::LabelC > &labelCs, const std::vector< double > &ys)
 Create from keys and vector table.
 
 AlgebraicDecisionTree (const std::vector< typename Super::LabelC > &labelCs, const std::string &table)
 Create from keys and string table.
 
 AlgebraicDecisionTree (Iterator begin, Iterator end, const Key &label)
 Create a new function splitting on a variable.
 
 AlgebraicDecisionTree (const AlgebraicDecisionTree< M > &other, const std::map< M, Key > &map)
 Convert.
 
AlgebraicDecisionTree operator+ (const AlgebraicDecisionTree &g) const
 sum
 
AlgebraicDecisionTree operator * (const AlgebraicDecisionTree &g) const
 product
 
AlgebraicDecisionTree operator/ (const AlgebraicDecisionTree &g) const
 division
 
AlgebraicDecisionTree sum (const Key &label, size_t cardinality) const
 sum out variable
 
AlgebraicDecisionTree sum (const typename Super::LabelC &labelC) const
 sum out variable
 
- Public Member Functions inherited from gtsam::DecisionTree< Key, double >
 DecisionTree (const double &y)
 Create a constant.
 
 DecisionTree (const Key &label, const double &y1, const double &y2)
 Create a new leaf function splitting on a variable.
 
 DecisionTree (const LabelC &label, const double &y1, const double &y2)
 Allow Label+Cardinality for convenience.
 
 DecisionTree (const std::vector< LabelC > &labelCs, const std::vector< double > &ys)
 Create from keys and a corresponding vector of values.
 
 DecisionTree (const std::vector< LabelC > &labelCs, const std::string &table)
 Create from keys and string table.
 
 DecisionTree (Iterator begin, Iterator end, const Key &label)
 Create DecisionTree from others.
 
 DecisionTree (const Key &label, const DecisionTree &f0, const DecisionTree &f1)
 Create DecisionTree from two others.
 
 DecisionTree (const DecisionTree< M, X > &other, const std::map< M, Key > &map, boost::function< double(const X &)> op)
 Convert from a different type.
 
 DecisionTree (const NodePtr &root)
 
NodePtr compose (Iterator begin, Iterator end, const Key &label) const
 
void print (const std::string &s="DecisionTree") const
 GTSAM-style print.
 
bool equals (const DecisionTree &other, double tol=1e-9) const
 
virtual ~DecisionTree ()
 Make virtual.
 
bool operator== (const DecisionTree &q) const
 equality
 
const double & operator() (const Assignment< Key > &x) const
 evaluate
 
DecisionTree apply (const Unary &op) const
 apply Unary operation "op" to f
 
DecisionTree apply (const DecisionTree &g, const Binary &op) const
 apply binary operation "op" to f and g
 
DecisionTree choose (const Key &label, size_t index) const
 create a new function where value(label)==index It's like "restrict" in Darwiche09book pg329, 330?
 
DecisionTree combine (const Key &label, size_t cardinality, const Binary &op) const
 combine subtrees on key with binary operation "op"
 
DecisionTree combine (const LabelC &labelC, const Binary &op) const
 combine with LabelC for convenience
 
void dot (std::ostream &os, bool showZero=true) const
 output to graphviz format, stream version
 
void dot (const std::string &name, bool showZero=true) const
 output to graphviz format, open a file
 
- Public Member Functions inherited from gtsam::Conditional< DecisionTreeFactor, DiscreteConditional >
size_t nrFrontals () const
 return the number of frontals
 
size_t nrParents () const
 return the number of parents
 
Key firstFrontalKey () const
 Convenience function to get the first frontal key.
 
Frontals frontals () const
 return a view of the frontal keys
 
Parents parents () const
 return a view of the parent keys
 
DecisionTreeFactor ::const_iterator beginFrontals () const
 Iterator pointing to first frontal key. More...
 
DecisionTreeFactor ::const_iterator endFrontals () const
 Iterator pointing past the last frontal key. More...
 
DecisionTreeFactor ::const_iterator beginParents () const
 Iterator pointing to the first parent key. More...
 
DecisionTreeFactor ::const_iterator endParents () const
 Iterator pointing past the last parent key. More...
 
size_t & nrFrontals ()
 Mutable version of nrFrontals.
 
DecisionTreeFactor ::iterator beginFrontals ()
 Mutable iterator pointing to first frontal key. More...
 
DecisionTreeFactor ::iterator endFrontals ()
 Mutable iterator pointing past the last frontal key. More...
 
DecisionTreeFactor ::iterator beginParents ()
 Mutable iterator pointing to the first parent key. More...
 
DecisionTreeFactor ::iterator endParents ()
 Mutable iterator pointing past the last parent key. More...
 

Public Types

typedef DiscreteConditional This
 Typedef to this class.
 
typedef boost::shared_ptr< Thisshared_ptr
 shared_ptr to this class
 
typedef DecisionTreeFactor BaseFactor
 Typedef to our factor base class.
 
typedef Conditional< BaseFactor, ThisBaseConditional
 Typedef to our conditional base class.
 
typedef Assignment< KeyValues
 A map from keys to values. More...
 
typedef boost::shared_ptr< ValuessharedValues
 
- Public Types inherited from gtsam::DecisionTreeFactor
typedef DecisionTreeFactor This
 
typedef DiscreteFactor Base
 Typedef to base class.
 
typedef boost::shared_ptr< DecisionTreeFactorshared_ptr
 
- Public Types inherited from gtsam::DiscreteFactor
typedef DiscreteFactor This
 This class.
 
typedef boost::shared_ptr< DiscreteFactorshared_ptr
 shared_ptr to this class
 
typedef Factor Base
 Our base class.
 
typedef Assignment< KeyValues
 A map from keys to values TODO: Do we need this? Should we just use gtsam::Values? We just need another special DiscreteValue to represent labels, However, all other Lie's operators are undefined in this class. More...
 
typedef boost::shared_ptr< ValuessharedValues
 
- Public Types inherited from gtsam::Factor
typedef KeyVector::iterator iterator
 Iterator over keys.
 
typedef KeyVector::const_iterator const_iterator
 Const iterator over keys.
 
- Public Types inherited from gtsam::Potentials
typedef AlgebraicDecisionTree< KeyADT
 
- Public Types inherited from gtsam::AlgebraicDecisionTree< Key >
typedef DecisionTree< Key, double > Super
 
- Public Types inherited from gtsam::DecisionTree< Key, double >
typedef boost::function< double(const double &)> Unary
 Handy typedefs for unary and binary function types.
 
typedef boost::function< double(const double &, const double &)> Binary
 
typedef std::pair< Key, size_t > LabelC
 A label annotated with cardinality.
 
typedef Node::Ptr NodePtr
 ---------------------— Node base class ------------------------— More...
 
- Public Types inherited from gtsam::Conditional< DecisionTreeFactor, DiscreteConditional >
typedef boost::iterator_range< typename DecisionTreeFactor ::const_iterator > Frontals
 View of the frontal keys (call frontals())
 
typedef boost::iterator_range< typename DecisionTreeFactor ::const_iterator > Parents
 View of the separator keys (call parents())
 

Additional Inherited Members

- Public Attributes inherited from gtsam::DecisionTree< Key, double >
NodePtr root_
 
- Protected Member Functions inherited from gtsam::Factor
 Factor ()
 Default constructor for I/O.
 
template<typename CONTAINER >
 Factor (const CONTAINER &keys)
 Construct factor from container of keys. More...
 
template<typename ITERATOR >
 Factor (ITERATOR first, ITERATOR last)
 Construct factor from iterator keys. More...
 
bool equals (const This &other, double tol=1e-9) const
 check equality
 
- Protected Member Functions inherited from gtsam::Potentials
 Potentials (const ADT &potentials)
 Constructor from ColumnIndex, and ADT.
 
- Protected Member Functions inherited from gtsam::DecisionTree< Key, double >
NodePtr create (It begin, It end, ValueIt beginY, ValueIt endY) const
 Internal recursive function to create from keys, cardinalities, and Y values.
 
NodePtr convert (const typename DecisionTree< M, X >::NodePtr &f, const std::map< M, Key > &map, boost::function< double(const X &)> op)
 Convert to a different type.
 
 DecisionTree ()
 Default constructor.
 
- Protected Member Functions inherited from gtsam::Conditional< DecisionTreeFactor, DiscreteConditional >
 Conditional ()
 Empty Constructor to make serialization possible.
 
 Conditional (size_t nrFrontals)
 Constructor.
 
void print (const std::string &s="Conditional", const KeyFormatter &formatter=DefaultKeyFormatter) const
 print with optional formatter
 
bool equals (const This &c, double tol=1e-9) const
 check equality
 
- Static Protected Member Functions inherited from gtsam::Factor
template<typename CONTAINER >
static Factor FromKeys (const CONTAINER &keys)
 Construct factor from container of keys. More...
 
template<typename ITERATOR >
static Factor FromIterators (ITERATOR first, ITERATOR last)
 Construct factor from iterator keys. More...
 
- Static Protected Member Functions inherited from gtsam::Potentials
static GTSAM_EXPORT double safe_div (const double &a, const double &b)
 
- Protected Attributes inherited from gtsam::Factor
KeyVector keys_
 The keys involved in this factor.
 
- Protected Attributes inherited from gtsam::Potentials
std::map< Key, size_t > cardinalities_
 Cardinality for each key, used in combine.
 
- Protected Attributes inherited from gtsam::Conditional< DecisionTreeFactor, DiscreteConditional >
size_t nrFrontals_
 The first nrFrontal variables are frontal and the rest are parents. More...
 

Member Typedef Documentation

◆ Values

A map from keys to values.

TODO: Again, do we need this???

Member Function Documentation

◆ Combine()

template<typename ITERATOR >
DiscreteConditional::shared_ptr gtsam::DiscreteConditional::Combine ( ITERATOR  firstConditional,
ITERATOR  lastConditional 
)
static

Combine several conditional into a single one.

The conditionals must be given in increasing order, meaning that the parents of any conditional may not include a conditional coming before it.

Parameters
firstConditionalIterator to the first conditional to combine, must dereference to a shared_ptr<DiscreteConditional>.
lastConditionalIterator to after the last conditional to combine, must dereference to a shared_ptr<DiscreteConditional>.

◆ sample()

size_t gtsam::DiscreteConditional::sample ( const Values parentsValues) const

sample

Parameters
parentsValuesKnown values of the parents
Returns
sample from conditional

◆ solve()

size_t gtsam::DiscreteConditional::solve ( const Values parentsValues) const

solve a conditional

Parameters
parentsValuesKnown values of the parents
Returns
MPE value of the child (1 frontal variable).

The documentation for this class was generated from the following files: