GTSAM  4.0.2
C++ library for smoothing and mapping (SAM)
Public Types | Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
gtsam::DiscreteDistribution Class Reference

#include <DiscreteDistribution.h>

Inheritance diagram for gtsam::DiscreteDistribution:
Inheritance graph
[legend]
Collaboration diagram for gtsam::DiscreteDistribution:
Collaboration graph
[legend]

Public Types

using Base = DiscreteConditional
 
typedef DiscreteConditional This
 Typedef to this class.
 
typedef std::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.
 
using Values = DiscreteValues
 backwards compatibility
 
typedef AlgebraicDecisionTree< KeyADT
 
typedef KeyVector::iterator iterator
 Iterator over keys.
 
typedef KeyVector::const_iterator const_iterator
 Const iterator over keys.
 
using LabelFormatter = std::function< std::string(Key)>
 
using ValueFormatter = std::function< std::string(double)>
 
using CompareFunc = std::function< bool(const double &, const double &)>
 
using Unary = std::function< double(const double &)>
 
using UnaryAssignment = std::function< double(const Assignment< Key > &, const double &)>
 
using Binary = std::function< double(const double &, const double &)>
 
using LabelC = std::pair< Key, size_t >
 
using NodePtr = typename Node::Ptr
 
typedef std::pair< typename DecisionTreeFactor ::const_iterator, typename DecisionTreeFactor ::const_iteratorConstFactorRange
 
typedef ConstFactorRangeIterator Frontals
 
typedef ConstFactorRangeIterator Parents
 
Wrapper support
using Names = DiscreteValues::Names
 Translation table from values to strings.
 

Public Member Functions

AlgebraicDecisionTree operator* (const AlgebraicDecisionTree &g) const
 
void print (const std::string &s="", const typename Base::LabelFormatter &labelFormatter=&DefaultFormatter) const
 print method customized to value type double.
 
bool equals (const AlgebraicDecisionTree &other, double tol=1e-9) const
 Equality method customized to value type double.
 
AlgebraicDecisionTree operator/ (const AlgebraicDecisionTree &g) const
 
AlgebraicDecisionTree sum (const Key &label, size_t cardinality) const
 
AlgebraicDecisionTree sum (const typename Base::LabelC &labelC) const
 
AlgebraicDecisionTree operator+ (const AlgebraicDecisionTree &g) const
 
Standard Constructors
 DiscreteDistribution ()
 Default constructor needed for serialization.
 
 DiscreteDistribution (const DecisionTreeFactor &f)
 Constructor from factor.
 
 DiscreteDistribution (const Signature &s)
 
 DiscreteDistribution (const DiscreteKey &key, const std::vector< double > &spec)
 
 DiscreteDistribution (const DiscreteKey &key, const std::string &spec)
 
Testable
void print (const std::string &s="Discrete Prior: ", const KeyFormatter &formatter=DefaultKeyFormatter) const override
 GTSAM-style print.
 
Standard interface
double operator() (size_t value) const
 Evaluate given a single value.
 
std::vector< double > pmf () const
 We also want to keep the Base version, taking DiscreteValues: More...
 
Standard Constructors
DiscreteConditional operator* (const DiscreteConditional &other) const
 Combine two conditionals, yielding a new conditional with the union of the frontal keys, ordered by gtsam::Key. More...
 
DiscreteConditional marginal (Key key) const
 
Testable
void print (const std::string &s, const LabelFormatter &labelFormatter, const ValueFormatter &valueFormatter) const
 GTSAM-style print. More...
 
bool equals (const DecisionTree &other, const CompareFunc &compare=&DefaultCompare) const
 
Testable
bool equals (const DiscreteFactor &other, double tol=1e-9) const override
 GTSAM-style equals.
 
Testable
bool equals (const This &other, double tol=1e-9) const
 check equality
 
virtual void printKeys (const std::string &s="Factor", const KeyFormatter &formatter=DefaultKeyFormatter) const
 print only keys
 
Testable
bool equals (const This &c, double tol=1e-9) const
 
Standard Interface
double logProbability (const DiscreteValues &x) const
 Log-probability is just -error(x).
 
void printSignature (const std::string &s="Discrete Conditional: ", const KeyFormatter &formatter=DefaultKeyFormatter) const
 print index signature only
 
double evaluate (const DiscreteValues &values) const
 Evaluate, just look up in AlgebraicDecisonTree.
 
shared_ptr choose (const DiscreteValues &given) const
 < DiscreteValues version More...
 
DecisionTreeFactor::shared_ptr likelihood (const DiscreteValues &frontalValues) const
 
DecisionTreeFactor::shared_ptr likelihood (size_t frontal) const
 
size_t sample (const DiscreteValues &parentsValues) const
 
size_t sample (size_t parent_value) const
 Single parent version.
 
size_t sample () const
 Zero parent version.
 
size_t argmax () const
 Return assignment that maximizes distribution. More...
 
HybridValues methods.
double logProbability (const HybridValues &x) const override
 < HybridValues version More...
 
double evaluate (const HybridValues &x) const override
 
double logNormalizationConstant () const override
 
Standard Interface
DecisionTree choose (const Key &label, size_t index) const
 
const double & operator() (const Assignment< Key > &x) const
 
DecisionTree apply (const Unary &op) const
 
DecisionTree apply (const UnaryAssignment &op) const
 Apply Unary operation "op" to f while also providing the corresponding assignment. More...
 
DecisionTree apply (const DecisionTree &g, const Binary &op) const
 
DecisionTree combine (const Key &label, size_t cardinality, const Binary &op) const
 
DecisionTree combine (const LabelC &labelC, const Binary &op) const
 
void dot (std::ostream &os, const LabelFormatter &labelFormatter, const ValueFormatter &valueFormatter, bool showZero=true) const
 
void dot (const std::string &name, const LabelFormatter &labelFormatter, const ValueFormatter &valueFormatter, bool showZero=true) const
 
std::string dot (const LabelFormatter &labelFormatter, const ValueFormatter &valueFormatter, bool showZero=true) const
 
bool empty () const
 Check if tree is empty.
 
bool operator== (const DecisionTree &q) const
 
void visit (Func f) const
 Visit all leaves in depth-first fashion. More...
 
void visitLeaf (Func f) const
 Visit all leaves in depth-first fashion. More...
 
void visitWith (Func f) const
 Visit all leaves in depth-first fashion. More...
 
size_t nrLeaves () const
 Return the number of leaves in the tree.
 
fold (Func f, X x0) const
 Fold a binary function over the tree, returning accumulator. More...
 
std::set< Keylabels () const
 
Advanced Interface
void sampleInPlace (DiscreteValues *parentsValues) const
 sample in place, stores result in partial solution
 
std::vector< DiscreteValuesfrontalAssignments () const
 Return all assignments for frontal variables.
 
std::vector< DiscreteValuesallAssignments () const
 Return all assignments for frontal and parent variables.
 
Wrapper support
std::string markdown (const KeyFormatter &keyFormatter=DefaultKeyFormatter, const Names &names={}) const override
 Render as markdown table.
 
std::string html (const KeyFormatter &keyFormatter=DefaultKeyFormatter, const Names &names={}) const override
 Render as html table.
 
Standard Interface
double operator() (const HybridValues &x) const
 Evaluate probability density, sugar.
 
size_t nrFrontals () const
 
size_t nrParents () const
 
Key firstFrontalKey () const
 
Frontals frontals () const
 
Parents parents () const
 
double normalizationConstant () const
 
HybridValues methods.
double error (const HybridValues &values) const override
 
Advanced Interface
DecisionTreeFactor apply (const DecisionTreeFactor &f, ADT::Binary op) const
 
shared_ptr combine (size_t nrFrontals, ADT::Binary op) const
 
shared_ptr combine (const Ordering &keys, ADT::Binary op) const
 
std::vector< std::pair< DiscreteValues, double > > enumerate () const
 Enumerate all values into a map from values to double.
 
DiscreteKeys discreteKeys () const
 Return all the discrete keys associated with this factor.
 
DecisionTreeFactor prune (size_t maxNrAssignments) const
 Prune the decision tree of discrete variables. More...
 
Wrapper support
void dot (std::ostream &os, const KeyFormatter &keyFormatter=DefaultKeyFormatter, bool showZero=true) const
 
void dot (const std::string &name, const KeyFormatter &keyFormatter=DefaultKeyFormatter, bool showZero=true) const
 
std::string dot (const KeyFormatter &keyFormatter=DefaultKeyFormatter, bool showZero=true) const
 
Standard Interface
bool empty () const
 Whether the factor is empty (involves zero variables).
 
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
 
const_iterator end () const
 
size_t size () const
 
Advanced Interface
KeyVectorkeys ()
 
iterator begin ()
 
iterator end ()
 
Advanced Interface
NodePtr compose (Iterator begin, Iterator end, const Key &label) const
 

Public Attributes

NodePtr root_
 A DecisionTree just contains the root. TODO(dellaert): make protected.
 

Protected Member Functions

DiscreteConditional::ADT choose (const DiscreteValues &given, bool forceComplete) const
 Internal version of choose.
 
NodePtr create (It begin, It end, ValueIt beginY, ValueIt endY) const
 
NodePtr convertFrom (const typename DecisionTree< M, X >::NodePtr &f, std::function< Key(const M &)> L_of_M, std::function< double(const X &)> Y_of_X) const
 Convert from a DecisionTree<M, X> to DecisionTree<L, Y>. More...
 

Static Protected Member Functions

static bool DefaultCompare (const double &a, const double &b)
 Default method for comparison of two objects of type Y.
 
Standard Constructors
template<typename CONTAINER >
static Factor FromKeys (const CONTAINER &keys)
 
template<typename ITERATOR >
static Factor FromIterators (ITERATOR first, ITERATOR last)
 

Protected Attributes

std::map< Key, size_t > cardinalities_
 
KeyVector keys_
 The keys involved in this factor.
 
size_t nrFrontals_
 

Standard Interface

DecisionTreeFactor operator* (const DecisionTreeFactor &f) const override
 multiply two factors
 
double operator() (const DiscreteValues &values) const override
 Evaluate probability distribution, sugar.
 
double error (const DiscreteValues &values) const
 Calculate error for DiscreteValues x, is -log(probability).
 
size_t cardinality (Key j) const
 
DecisionTreeFactor operator/ (const DecisionTreeFactor &f) const
 divide by factor f (safely)
 
DecisionTreeFactor toDecisionTreeFactor () const override
 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.
 
shared_ptr max (const Ordering &keys) const
 Create new factor by maximizing over all values with the same separator.
 
static double safe_div (const double &a, const double &b)
 

Advanced Interface

size_t & nrFrontals ()
 
DecisionTreeFactor ::const_iterator beginFrontals () const
 
DecisionTreeFactor ::iterator beginFrontals ()
 
DecisionTreeFactor ::const_iterator endFrontals () const
 
DecisionTreeFactor ::iterator endFrontals ()
 
DecisionTreeFactor ::const_iterator beginParents () const
 
DecisionTreeFactor ::iterator beginParents ()
 
DecisionTreeFactor ::const_iterator endParents () const
 
DecisionTreeFactor ::iterator endParents ()
 
static bool CheckInvariants (const DiscreteConditional &conditional, const VALUES &x)
 

Detailed Description

A prior probability on a set of discrete variables. Derives from DiscreteConditional

Member Typedef Documentation

◆ ConstFactorRange

A mini implementation of an iterator range, to share const views of frontals and parents.

◆ Frontals

typedef ConstFactorRangeIterator gtsam::Conditional< DecisionTreeFactor , DiscreteConditional >::Frontals
inherited

View of the frontal keys (call frontals())

◆ LabelC

using gtsam::DecisionTree< Key , double >::LabelC = std::pair<Key , size_t>
inherited

A label annotated with cardinality

◆ NodePtr

using gtsam::DecisionTree< Key , double >::NodePtr = typename Node::Ptr
inherited

------------------—— Node base class ---------------------—— A function is a shared pointer to the root of a DT

◆ Parents

typedef ConstFactorRangeIterator gtsam::Conditional< DecisionTreeFactor , DiscreteConditional >::Parents
inherited

View of the separator keys (call parents())

◆ Unary

using gtsam::DecisionTree< Key , double >::Unary = std::function<double (const double &)>
inherited

Handy typedefs for unary and binary function types

Constructor & Destructor Documentation

◆ DiscreteDistribution() [1/3]

gtsam::DiscreteDistribution::DiscreteDistribution ( const Signature s)
inlineexplicit

Construct from a Signature.

Example: DiscreteDistribution P(D % "3/2");

◆ DiscreteDistribution() [2/3]

gtsam::DiscreteDistribution::DiscreteDistribution ( const DiscreteKey key,
const std::vector< double > &  spec 
)
inline

Construct from key and a vector of floats specifying the probability mass function (PMF).

Example: DiscreteDistribution P(D, {0.4, 0.6});

◆ DiscreteDistribution() [3/3]

gtsam::DiscreteDistribution::DiscreteDistribution ( const DiscreteKey key,
const std::string &  spec 
)
inline

Construct from key and a string specifying the probability mass function (PMF).

Example: DiscreteDistribution P(D, "9/1 2/8 3/7 1/9");

Member Function Documentation

◆ apply() [1/4]

DecisionTreeFactor gtsam::DecisionTreeFactor::apply ( const DecisionTreeFactor f,
ADT::Binary  op 
) const
inherited

Apply binary operator (*this) "op" f

Parameters
fthe second argument for op
opa binary operator that operates on AlgebraicDecisionTree

◆ apply() [2/4]

DecisionTree< Key , double > gtsam::DecisionTree< Key , double >::apply ( const Unary op) const
inherited

apply Unary operation "op" to f

◆ apply() [3/4]

DecisionTree< Key , double > gtsam::DecisionTree< Key , double >::apply ( const UnaryAssignment &  op) const
inherited

Apply Unary operation "op" to f while also providing the corresponding assignment.

Apply unary operator with assignment.

Parameters
opFunction which takes Assignment<L> and Y as input and returns object of type Y.
Returns
DecisionTree

◆ apply() [4/4]

DecisionTree< Key , double > gtsam::DecisionTree< Key , double >::apply ( const DecisionTree< Key, double > &  g,
const Binary &  op 
) const
inherited

apply binary operation "op" to f and g

◆ argmax()

size_t gtsam::DiscreteConditional::argmax ( ) const
inherited

Return assignment that maximizes distribution.

Returns
Optimal assignment (1 frontal variable).

◆ begin() [1/2]

const_iterator gtsam::Factor::begin ( ) const
inlineinherited

Iterator at beginning of involved variable keys

◆ begin() [2/2]

iterator gtsam::Factor::begin ( )
inlineinherited

Iterator at beginning of involved variable keys

◆ beginFrontals() [1/2]

Iterator pointing to first frontal key.

◆ beginFrontals() [2/2]

Mutable iterator pointing to first frontal key.

◆ beginParents() [1/2]

Iterator pointing to the first parent key.

◆ beginParents() [2/2]

Mutable iterator pointing to the first parent key.

◆ CheckInvariants()

bool gtsam::Conditional< DecisionTreeFactor , DiscreteConditional >::CheckInvariants ( const DiscreteConditional< DecisionTreeFactor, DiscreteConditional > &  conditional,
const VALUES &  x 
)
staticinherited

Check invariants of this conditional, given the values x. It tests:

Parameters
conditionalThe conditional to test, as a reference to the derived type.
Template Parameters
VALUESHybridValues, or a more narrow type like DiscreteValues.

◆ choose() [1/2]

shared_ptr gtsam::DiscreteConditional::choose ( const DiscreteValues given) const
inherited

< DiscreteValues version

restrict to given parent values.

Note: does not need be complete set. Examples:

P(C|D,E) + . -> P(C|D,E) P(C|D,E) + E -> P(C|D) P(C|D,E) + D -> P(C|E) P(C|D,E) + D,E -> P(C) P(C|D,E) + C -> error!

Returns
a shared_ptr to a new DiscreteConditional

◆ choose() [2/2]

DecisionTree gtsam::DecisionTree< Key , double >::choose ( const Key label,
size_t  index 
) const
inlineinherited

create a new function where value(label)==index It's like "restrict" in Darwiche09book pg329, 330?

◆ combine() [1/4]

shared_ptr gtsam::DecisionTreeFactor::combine ( size_t  nrFrontals,
ADT::Binary  op 
) const
inherited

Combine frontal variables using binary operator "op"

Parameters
nrFrontalsnr. of frontal to combine variables in this factor
opa binary operator that operates on AlgebraicDecisionTree
Returns
shared pointer to newly created DecisionTreeFactor

◆ combine() [2/4]

shared_ptr gtsam::DecisionTreeFactor::combine ( const Ordering keys,
ADT::Binary  op 
) const
inherited

Combine frontal variables in an Ordering using binary operator "op"

Parameters
nrFrontalsnr. of frontal to combine variables in this factor
opa binary operator that operates on AlgebraicDecisionTree
Returns
shared pointer to newly created DecisionTreeFactor

◆ combine() [3/4]

DecisionTree< Key , double > gtsam::DecisionTree< Key , double >::combine ( const Key label,
size_t  cardinality,
const Binary &  op 
) const
inherited

combine subtrees on key with binary operation "op"

◆ combine() [4/4]

DecisionTree gtsam::DecisionTree< Key , double >::combine ( const LabelC labelC,
const Binary &  op 
) const
inlineinherited

combine with LabelC for convenience

◆ convertFrom()

DecisionTree< Key , double >::NodePtr gtsam::DecisionTree< Key , double >::convertFrom ( const typename DecisionTree< M, X >::NodePtr f,
std::function< Key (const M &)>  L_of_M,
std::function< double (const X &)>  Y_of_X 
) const
protectedinherited

Convert from a DecisionTree<M, X> to DecisionTree<L, Y>.

Template Parameters
MThe previous label type.
XThe previous value type.
Parameters
fThe node pointer to the root of the previous DecisionTree.
L_of_MFunctor to convert from label type M to type L.
Y_of_XFunctor to convert from value type X to type Y.
Returns
NodePtr

◆ create()

DecisionTree< Key , double >::NodePtr gtsam::DecisionTree< Key , double >::create ( It  begin,
It  end,
ValueIt  beginY,
ValueIt  endY 
) const
protectedinherited

Internal recursive function to create from keys, cardinalities, and Y values

◆ dot() [1/6]

void gtsam::DecisionTreeFactor::dot ( std::ostream &  os,
const KeyFormatter keyFormatter = DefaultKeyFormatter,
bool  showZero = true 
) const
inherited

output to graphviz format, stream version

◆ dot() [2/6]

void gtsam::DecisionTreeFactor::dot ( const std::string &  name,
const KeyFormatter keyFormatter = DefaultKeyFormatter,
bool  showZero = true 
) const
inherited

output to graphviz format, open a file

◆ dot() [3/6]

std::string gtsam::DecisionTreeFactor::dot ( const KeyFormatter keyFormatter = DefaultKeyFormatter,
bool  showZero = true 
) const
inherited

output to graphviz format string

◆ dot() [4/6]

void gtsam::DecisionTree< Key , double >::dot ( std::ostream &  os,
const LabelFormatter &  labelFormatter,
const ValueFormatter &  valueFormatter,
bool  showZero = true 
) const
inherited

output to graphviz format, stream version

◆ dot() [5/6]

void gtsam::DecisionTree< Key , double >::dot ( const std::string &  name,
const LabelFormatter &  labelFormatter,
const ValueFormatter &  valueFormatter,
bool  showZero = true 
) const
inherited

output to graphviz format, open a file

◆ dot() [6/6]

std::string gtsam::DecisionTree< Key , double >::dot ( const LabelFormatter &  labelFormatter,
const ValueFormatter &  valueFormatter,
bool  showZero = true 
) const
inherited

output to graphviz format string

◆ end() [1/2]

const_iterator gtsam::Factor::end ( ) const
inlineinherited

Iterator at end of involved variable keys

◆ end() [2/2]

iterator gtsam::Factor::end ( )
inlineinherited

Iterator at end of involved variable keys

◆ endFrontals() [1/2]

Iterator pointing past the last frontal key.

◆ endFrontals() [2/2]

Mutable iterator pointing past the last frontal key.

◆ endParents() [1/2]

Iterator pointing past the last parent key.

◆ endParents() [2/2]

Mutable iterator pointing past the last parent key.

◆ equals()

bool gtsam::Conditional< DecisionTreeFactor , DiscreteConditional >::equals ( const This c,
double  tol = 1e-9 
) const
inherited

check equality

◆ error()

double gtsam::DecisionTreeFactor::error ( const HybridValues values) const
overridevirtualinherited

Calculate error for HybridValues x, is -log(probability) Simply dispatches to DiscreteValues version.

Reimplemented from gtsam::Factor.

◆ evaluate()

double gtsam::DiscreteConditional::evaluate ( const HybridValues x) const
overridevirtualinherited

Calculate probability for HybridValues x. Dispatches to DiscreteValues version.

Reimplemented from gtsam::Conditional< DecisionTreeFactor, DiscreteConditional >.

◆ firstFrontalKey()

Key gtsam::Conditional< DecisionTreeFactor , DiscreteConditional >::firstFrontalKey ( ) const
inlineinherited

Convenience function to get the first frontal key

◆ fold()

X gtsam::DecisionTree< Key , double >::fold ( Func  f,
x0 
) const
inherited

Fold a binary function over the tree, returning accumulator.

Template Parameters
Xtype for accumulator.
Parameters
fbinary function: Y * X -> X returning an updated accumulator.
x0initial value for accumulator.
Returns
X final value for accumulator.
Note
X is always passed by value.
Due to pruning, leaves might not exhaust choices.

Example: auto add = [](const double& y, double x) { return y + x; }; double sum = tree.fold(add, 0.0);

◆ FromIterators()

template<typename ITERATOR >
static Factor gtsam::Factor::FromIterators ( ITERATOR  first,
ITERATOR  last 
)
inlinestaticprotectedinherited

Construct factor from iterator keys. This is called internally from derived factor static factor methods, as a workaround for not being able to call the protected constructors above.

◆ FromKeys()

template<typename CONTAINER >
static Factor gtsam::Factor::FromKeys ( const CONTAINER &  keys)
inlinestaticprotectedinherited

Construct factor from container of keys. This is called internally from derived factor static factor methods, as a workaround for not being able to call the protected constructors above.

◆ frontals()

Frontals gtsam::Conditional< DecisionTreeFactor , DiscreteConditional >::frontals ( ) const
inlineinherited

return a view of the frontal keys

◆ keys()

KeyVector& gtsam::Factor::keys ( )
inlineinherited
Returns
keys involved in this factor

◆ labels()

std::set< Key > gtsam::DecisionTree< Key , double >::labels ( ) const
inherited

Retrieve all unique labels as a set.

Get (partial) labels by performing a visit.

This method performs a depth-first search to go to every leaf and records the keys assignment which leads to that leaf. Since the tree can be pruned, there might be a leaf at a lower depth which results in a partial assignment (i.e. not all keys are specified).

E.g. given a tree with 3 keys, there may be a branch where the 3rd key has the same values for all the leaves. This leads to the branch being pruned so we get a leaf which is arrived at by just the first 2 keys and their assignments.

◆ likelihood() [1/2]

DecisionTreeFactor::shared_ptr gtsam::DiscreteConditional::likelihood ( const DiscreteValues frontalValues) const
inherited

Convert to a likelihood factor by providing value before bar.

◆ likelihood() [2/2]

DecisionTreeFactor::shared_ptr gtsam::DiscreteConditional::likelihood ( size_t  frontal) const
inherited

Single variable version of likelihood.

◆ logNormalizationConstant()

double gtsam::DiscreteConditional::logNormalizationConstant ( ) const
inlineoverridevirtualinherited

logNormalizationConstant K is just zero, such that logProbability(x) = log(evaluate(x)) = - error(x) and hence error(x) = - log(evaluate(x)) > 0 for all x.

Reimplemented from gtsam::Conditional< DecisionTreeFactor, DiscreteConditional >.

◆ logProbability()

double gtsam::DiscreteConditional::logProbability ( const HybridValues x) const
inlineoverridevirtualinherited

< HybridValues version

Calculate log-probability log(evaluate(x)) for HybridValues x. This is actually just -error(x).

Reimplemented from gtsam::Conditional< DecisionTreeFactor, DiscreteConditional >.

◆ marginal()

DiscreteConditional gtsam::DiscreteConditional::marginal ( Key  key) const
inherited

Calculate marginal on given key, no parent case.

◆ normalizationConstant()

double gtsam::Conditional< DecisionTreeFactor , DiscreteConditional >::normalizationConstant ( ) const
inherited

Non-virtual, exponentiate logNormalizationConstant.

◆ nrFrontals() [1/2]

size_t gtsam::Conditional< DecisionTreeFactor , DiscreteConditional >::nrFrontals ( ) const
inlineinherited

return the number of frontals

◆ nrFrontals() [2/2]

size_t& gtsam::Conditional< DecisionTreeFactor , DiscreteConditional >::nrFrontals ( )
inlineinherited

Mutable version of nrFrontals

◆ nrParents()

size_t gtsam::Conditional< DecisionTreeFactor , DiscreteConditional >::nrParents ( ) const
inlineinherited

return the number of parents

◆ operator()()

const double & gtsam::DecisionTree< Key , double >::operator() ( const Assignment< Key > &  x) const
inherited

evaluate

◆ operator*() [1/2]

DiscreteConditional gtsam::DiscreteConditional::operator* ( const DiscreteConditional other) const
inherited

Combine two conditionals, yielding a new conditional with the union of the frontal keys, ordered by gtsam::Key.

The two conditionals must make a valid Bayes net fragment, i.e., the frontal variables cannot overlap, and must be acyclic: Example of correct use: P(A,B) = P(A|B) * P(B) P(A,B|C) = P(A|B) * P(B|C) P(A,B,C) = P(A,B|C) * P(C) Example of incorrect use: P(A|B) * P(A|C) = ? P(A|B) * P(B|A) = ? We check for overlapping frontals, but do not check for cyclic.

◆ operator*() [2/2]

AlgebraicDecisionTree gtsam::AlgebraicDecisionTree< Key >::operator* ( const AlgebraicDecisionTree< Key > &  g) const
inlineinherited

product

◆ operator+()

AlgebraicDecisionTree gtsam::AlgebraicDecisionTree< Key >::operator+ ( const AlgebraicDecisionTree< Key > &  g) const
inlineinherited

sum

◆ operator/()

AlgebraicDecisionTree gtsam::AlgebraicDecisionTree< Key >::operator/ ( const AlgebraicDecisionTree< Key > &  g) const
inlineinherited

division

◆ operator==()

bool gtsam::DecisionTree< Key , double >::operator== ( const DecisionTree< Key, double > &  q) const
inherited

equality

◆ parents()

Parents gtsam::Conditional< DecisionTreeFactor , DiscreteConditional >::parents ( ) const
inlineinherited

return a view of the parent keys

◆ pmf()

std::vector<double> gtsam::DiscreteDistribution::pmf ( ) const

We also want to keep the Base version, taking DiscreteValues:

Return entire probability mass function.

◆ print()

void gtsam::DecisionTree< Key , double >::print ( const std::string &  s,
const LabelFormatter &  labelFormatter,
const ValueFormatter &  valueFormatter 
) const
inherited

GTSAM-style print.

Parameters
sPrefix string.
labelFormatterFunctor to format the node label.
valueFormatterFunctor to format the node value.

◆ prune()

DecisionTreeFactor gtsam::DecisionTreeFactor::prune ( size_t  maxNrAssignments) const
inherited

Prune the decision tree of discrete variables.

Pruning will set the leaves to be "pruned" to 0 indicating a 0 probability. An assignment is pruned if it is not in the top maxNrAssignments values.

A violation can occur if there are more duplicate values than maxNrAssignments. A violation here is the need to un-prune the decision tree (e.g. all assignment values are 1.0). We could have another case where some subset of duplicates exist (e.g. for a tree with 8 assignments we have 1, 1, 1, 1, 0.8, 0.7, 0.6, 0.5), but this is not a violation since the for maxNrAssignments=5 the top values are (1, 0.8).

Parameters
maxNrAssignmentsThe maximum number of assignments to keep.
Returns
DecisionTreeFactor

◆ sample()

size_t gtsam::DiscreteConditional::sample ( const DiscreteValues parentsValues) const
inherited

sample

Parameters
parentsValuesKnown values of the parents
Returns
sample from conditional

◆ size()

size_t gtsam::Factor::size ( ) const
inlineinherited
Returns
the number of variables involved in this factor

◆ sum() [1/2]

AlgebraicDecisionTree gtsam::AlgebraicDecisionTree< Key >::sum ( const Key label,
size_t  cardinality 
) const
inlineinherited

sum out variable

◆ sum() [2/2]

AlgebraicDecisionTree gtsam::AlgebraicDecisionTree< Key >::sum ( const typename Base::LabelC labelC) const
inlineinherited

sum out variable

◆ visit()

void gtsam::DecisionTree< Key , double >::visit ( Func  f) const
inherited

Visit all leaves in depth-first fashion.

Parameters
f(side-effect) Function taking the value of the leaf node.
Note
Due to pruning, the number of leaves may not be the same as the number of assignments. E.g. if we have a tree on 2 binary variables with all values being 1, then there are 2^2=4 assignments, but only 1 leaf.

Example: int sum = 0; auto visitor = [&](int y) { sum += y; }; tree.visit(visitor);

◆ visitLeaf()

void gtsam::DecisionTree< Key , double >::visitLeaf ( Func  f) const
inherited

Visit all leaves in depth-first fashion.

Parameters
f(side-effect) Function taking the leaf node pointer.
Note
Due to pruning, the number of leaves may not be the same as the number of assignments. E.g. if we have a tree on 2 binary variables with all values being 1, then there are 2^2=4 assignments, but only 1 leaf.

Example: int sum = 0; auto visitor = [&](const Leaf& leaf) { sum += leaf.constant(); }; tree.visitLeaf(visitor);

◆ visitWith()

void gtsam::DecisionTree< Key , double >::visitWith ( Func  f) const
inherited

Visit all leaves in depth-first fashion.

Parameters
f(side-effect) Function taking an assignment and a value.
Note
Due to pruning, the number of leaves may not be the same as the number of assignments. E.g. if we have a tree on 2 binary variables with all values being 1, then there are 2^2=4 assignments, but only 1 leaf.

Example: int sum = 0; auto visitor = [&](const Assignment<L>& assignment, int y) { sum += y; }; tree.visitWith(visitor);

Member Data Documentation

◆ nrFrontals_

size_t gtsam::Conditional< DecisionTreeFactor , DiscreteConditional >::nrFrontals_
protectedinherited

The first nrFrontal variables are frontal and the rest are parents.


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