gtsam 4.2.0
gtsam
|
A prior probability on a set of discrete variables.
Derives from DiscreteConditional
Public Member Functions | |
Standard Constructors | |
DiscreteDistribution () | |
Default constructor needed for serialization. | |
DiscreteDistribution (const DecisionTreeFactor &f) | |
Constructor from factor. | |
DiscreteDistribution (const Signature &s) | |
Construct from a Signature. More... | |
DiscreteDistribution (const DiscreteKey &key, const std::vector< double > &spec) | |
Construct from key and a vector of floats specifying the probability mass function (PMF). More... | |
DiscreteDistribution (const DiscreteKey &key, const std::string &spec) | |
Construct from key and a string specifying the probability mass function (PMF). More... | |
Testable | |
void | print (const std::string &s="Discrete Prior: ", const KeyFormatter &formatter=DefaultKeyFormatter) const override |
GTSAM-style print. More... | |
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... | |
![]() | |
DiscreteConditional () | |
Default constructor needed for serialization. | |
DiscreteConditional (size_t nFrontals, const DecisionTreeFactor &f) | |
Construct from factor, taking the first nFrontals keys as frontals. | |
DiscreteConditional (size_t nFrontals, const DiscreteKeys &keys, const ADT &potentials) | |
Construct from DiscreteKeys and AlgebraicDecisionTree, taking the first nFrontals keys as frontals, in the order given. | |
DiscreteConditional (const Signature &signature) | |
Construct from signature. | |
DiscreteConditional (const DiscreteKey &key, const DiscreteKeys &parents, const Signature::Table &table) | |
Construct from key, parents, and a Signature::Table specifying the conditional probability table (CPT) in 00 01 10 11 order. More... | |
DiscreteConditional (const DiscreteKey &key, const DiscreteKeys &parents, const std::string &spec) | |
Construct from key, parents, and a string specifying the conditional probability table (CPT) in 00 01 10 11 order. More... | |
DiscreteConditional (const DiscreteKey &key, const std::string &spec) | |
No-parent specialization; can also use DiscreteDistribution. | |
DiscreteConditional (const DecisionTreeFactor &joint, const DecisionTreeFactor &marginal) | |
construct P(X|Y) = f(X,Y)/f(Y) from f(X,Y) and f(Y) Assumes but does not check that f(Y)=sum_X f(X,Y). | |
DiscreteConditional (const DecisionTreeFactor &joint, const DecisionTreeFactor &marginal, const Ordering &orderedKeys) | |
construct P(X|Y) = f(X,Y)/f(Y) from f(X,Y) and f(Y) Assumes but does not check that f(Y)=sum_X f(X,Y). More... | |
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 |
Calculate marginal on given key, no parent case. | |
bool | equals (const DiscreteFactor &other, double tol=1e-9) const override |
GTSAM-style equals. More... | |
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 |
Convert to a likelihood factor by providing value before bar. | |
DecisionTreeFactor::shared_ptr | likelihood (size_t frontal) const |
Single variable version of likelihood. | |
size_t | sample (const DiscreteValues &parentsValues) const |
sample More... | |
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... | |
double | error (const DiscreteValues &values) const |
Calculate error for DiscreteValues x , is -log(probability). | |
double | error (const HybridValues &values) const override |
Calculate error for HybridValues x , is -log(probability) Simply dispatches to DiscreteValues version. More... | |
void | sampleInPlace (DiscreteValues *parentsValues) const |
sample in place, stores result in partial solution | |
std::vector< DiscreteValues > | frontalAssignments () const |
Return all assignments for frontal variables. | |
std::vector< DiscreteValues > | allAssignments () const |
Return all assignments for frontal and parent variables. | |
std::string | markdown (const KeyFormatter &keyFormatter=DefaultKeyFormatter, const Names &names={}) const override |
Render as markdown table. More... | |
std::string | html (const KeyFormatter &keyFormatter=DefaultKeyFormatter, const Names &names={}) const override |
Render as html table. More... | |
double | evaluate (const HybridValues &x) const override |
Calculate probability for HybridValues x . More... | |
double | logProbability (const HybridValues &x) const override |
< HybridValues version More... | |
double | logNormalizationConstant () const override |
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. More... | |
![]() | |
DecisionTreeFactor () | |
Default constructor for I/O. | |
DecisionTreeFactor (const DiscreteKeys &keys, const ADT &potentials) | |
Constructor from DiscreteKeys and AlgebraicDecisionTree. | |
DecisionTreeFactor (const DiscreteKeys &keys, const std::vector< double > &table) | |
Constructor from doubles. | |
DecisionTreeFactor (const DiscreteKeys &keys, const std::string &table) | |
Constructor from string. | |
template<class SOURCE > | |
DecisionTreeFactor (const DiscreteKey &key, SOURCE table) | |
Single-key specialization. | |
DecisionTreeFactor (const DiscreteKey &key, const std::vector< double > &row) | |
Single-key specialization, with vector of doubles. | |
DecisionTreeFactor (const DiscreteConditional &c) | |
Construct from a DiscreteConditional type. | |
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... | |
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... | |
void | dot (std::ostream &os, const KeyFormatter &keyFormatter=DefaultKeyFormatter, bool showZero=true) const |
output to graphviz format, stream version | |
void | dot (const std::string &name, const KeyFormatter &keyFormatter=DefaultKeyFormatter, bool showZero=true) const |
output to graphviz format, open a file | |
std::string | dot (const KeyFormatter &keyFormatter=DefaultKeyFormatter, bool showZero=true) const |
output to graphviz format string | |
double | evaluate (const DiscreteValues &values) const |
Calculate probability for given values x , is just look up in AlgebraicDecisionTree. | |
double | operator() (const DiscreteValues &values) const override |
Evaluate probability density, sugar. More... | |
double | error (const DiscreteValues &values) const |
Calculate error for DiscreteValues x , is -log(probability). | |
DecisionTreeFactor | operator* (const DecisionTreeFactor &f) const override |
multiply two factors More... | |
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. More... | |
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. | |
![]() | |
DiscreteFactor () | |
Default constructor creates empty factor. | |
template<typename CONTAINER > | |
DiscreteFactor (const CONTAINER &keys) | |
Construct from container of keys. More... | |
virtual | ~DiscreteFactor () |
Virtual destructor. | |
void | print (const std::string &s="DiscreteFactor\n", const KeyFormatter &formatter=DefaultKeyFormatter) const override |
print More... | |
double | error (const DiscreteValues &values) const |
Error is just -log(value) | |
![]() | |
virtual | ~Factor ()=default |
Default destructor. | |
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 KeyVector & | keys () 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 |
virtual void | printKeys (const std::string &s="Factor", const KeyFormatter &formatter=DefaultKeyFormatter) const |
print only keys More... | |
bool | equals (const This &other, double tol=1e-9) const |
check equality | |
KeyVector & | keys () |
iterator | begin () |
Iterator at beginning of involved variable keys. | |
iterator | end () |
Iterator at end of involved variable keys. | |
![]() | |
AlgebraicDecisionTree (double leaf=1.0) | |
AlgebraicDecisionTree (const Base &add) | |
AlgebraicDecisionTree (const Key &label, double y1, double y2) | |
Create a new leaf function splitting on a variable. | |
AlgebraicDecisionTree (const typename Base::LabelC &labelC, double y1, double y2) | |
Create a new leaf function splitting on a variable. | |
AlgebraicDecisionTree (const std::vector< typename Base::LabelC > &labelCs, const std::vector< double > &ys) | |
Create from keys and vector table. | |
AlgebraicDecisionTree (const std::vector< typename Base::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 labels from type M to type L. More... | |
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 Base::LabelC &labelC) const |
sum out variable | |
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 . | |
![]() | |
DecisionTree () | |
Default constructor (for serialization) | |
DecisionTree (const double &y) | |
Create a constant. | |
DecisionTree (const Key &label, const double &y1, const double &y2) | |
Create tree with 2 assignments y1 , y2 , splitting on variable label | |
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< Key, X > &other, Func Y_of_X) | |
Convert from a different value type. More... | |
DecisionTree (const DecisionTree< M, X > &other, const std::map< M, Key > &map, Func Y_of_X) | |
Convert from a different value type X to value type Y, also transate labels via map from type M to L. More... | |
DecisionTree (const NodePtr &root) | |
NodePtr | compose (Iterator begin, Iterator end, const Key &label) const |
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 |
virtual | ~DecisionTree ()=default |
Make virtual. | |
bool | empty () const |
Check if tree is empty. | |
bool | operator== (const DecisionTree &q) const |
equality | |
const double & | operator() (const Assignment< Key > &x) const |
evaluate | |
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. | |
X | fold (Func f, X x0) const |
Fold a binary function over the tree, returning accumulator. More... | |
std::set< Key > | labels () const |
Retrieve all unique labels as a set. More... | |
DecisionTree | apply (const Unary &op) const |
apply Unary operation "op" to f | |
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 |
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, const LabelFormatter &labelFormatter, const ValueFormatter &valueFormatter, bool showZero=true) const |
output to graphviz format, stream version | |
void | dot (const std::string &name, const LabelFormatter &labelFormatter, const ValueFormatter &valueFormatter, bool showZero=true) const |
output to graphviz format, open a file | |
std::string | dot (const LabelFormatter &labelFormatter, const ValueFormatter &valueFormatter, bool showZero=true) const |
output to graphviz format string | |
![]() | |
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 | |
virtual | ~Conditional () |
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 | |
double | operator() (const HybridValues &x) const |
Evaluate probability density, sugar. | |
double | normalizationConstant () const |
Non-virtual, exponentiate logNormalizationConstant. | |
size_t & | nrFrontals () |
Mutable version of nrFrontals. | |
FACTOR::const_iterator | beginFrontals () const |
Iterator pointing to first frontal key. | |
FACTOR::iterator | beginFrontals () |
Mutable iterator pointing to first frontal key. | |
FACTOR::const_iterator | endFrontals () const |
Iterator pointing past the last frontal key. | |
FACTOR::iterator | endFrontals () |
Mutable iterator pointing past the last frontal key. | |
FACTOR::const_iterator | beginParents () const |
Iterator pointing to the first parent key. | |
FACTOR::iterator | beginParents () |
Mutable iterator pointing to the first parent key. | |
FACTOR::const_iterator | endParents () const |
Iterator pointing past the last parent key. | |
FACTOR::iterator | endParents () |
Mutable iterator pointing past the last parent key. | |
Public Types | |
using | Base = DiscreteConditional |
![]() | |
typedef DiscreteConditional | This |
Typedef to this class. | |
typedef boost::shared_ptr< This > | shared_ptr |
shared_ptr to this class | |
typedef DecisionTreeFactor | BaseFactor |
Typedef to our factor base class. | |
typedef Conditional< BaseFactor, This > | BaseConditional |
Typedef to our conditional base class. | |
using | Values = DiscreteValues |
backwards compatibility | |
![]() | |
typedef DecisionTreeFactor | This |
typedef DiscreteFactor | Base |
Typedef to base class. | |
typedef boost::shared_ptr< DecisionTreeFactor > | shared_ptr |
typedef AlgebraicDecisionTree< Key > | ADT |
![]() | |
typedef DiscreteFactor | This |
This class. | |
typedef boost::shared_ptr< DiscreteFactor > | shared_ptr |
shared_ptr to this class | |
typedef Factor | Base |
Our base class. | |
using | Values = DiscreteValues |
backwards compatibility | |
using | Names = DiscreteValues::Names |
Translation table from values to strings. | |
![]() | |
typedef KeyVector::iterator | iterator |
Iterator over keys. | |
typedef KeyVector::const_iterator | const_iterator |
Const iterator over keys. | |
![]() | |
using | Base = DecisionTree< Key, double > |
![]() | |
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 &)> |
Handy typedefs for unary and binary function types. | |
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 > |
A label annotated with cardinality. | |
using | NodePtr = typename Node::Ptr |
---------------------— Node base class ------------------------— More... | |
![]() | |
typedef boost::iterator_range< typename FACTOR::const_iterator > | Frontals |
View of the frontal keys (call frontals()) | |
typedef boost::iterator_range< typename FACTOR::const_iterator > | Parents |
View of the separator keys (call parents()) | |
Additional Inherited Members | |
![]() | |
static double | safe_div (const double &a, const double &b) |
![]() | |
static bool | CheckInvariants (const DiscreteConditional &conditional, const VALUES &x) |
Check invariants of this conditional, given the values x . More... | |
![]() | |
NodePtr | root_ |
A DecisionTree just contains the root. TODO(dellaert): make protected. | |
![]() | |
DiscreteConditional::ADT | choose (const DiscreteValues &given, bool forceComplete) const |
Internal version of choose. | |
![]() | |
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... | |
![]() | |
NodePtr | create (It begin, It end, ValueIt beginY, ValueIt endY) const |
Internal recursive function to create from keys, cardinalities, and Y values. | |
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... | |
![]() | |
Conditional () | |
Empty Constructor to make serialization possible. | |
Conditional (size_t nrFrontals) | |
Constructor. | |
![]() | |
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 bool | DefaultCompare (const double &a, const double &b) |
Default method for comparison of two objects of type Y. | |
![]() | |
std::map< Key, size_t > | cardinalities_ |
![]() | |
KeyVector | keys_ |
The keys involved in this factor. | |
![]() | |
size_t | nrFrontals_ |
The first nrFrontal variables are frontal and the rest are parents. | |
|
inlineexplicit |
Construct from a Signature.
Example: DiscreteDistribution P(D % "3/2");
|
inline |
Construct from key and a vector of floats specifying the probability mass function (PMF).
Example: DiscreteDistribution P(D, {0.4, 0.6});
|
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");
std::vector< double > gtsam::DiscreteDistribution::pmf | ( | ) | const |
We also want to keep the Base version, taking DiscreteValues:
Return entire probability mass function.
|
overridevirtual |
GTSAM-style print.
Reimplemented from gtsam::DiscreteConditional.