|
gtsam
|
A discrete probabilistic factor optimized for sparsity.
Uses sparse_table_ to store only the nonzero probabilities. Computes the assigned value for the key using the ordering which the nonzero probabilties are stored in. (lazy cartesian product)
Testable | |
| static double | safe_div (const double &a, const double &b) |
| bool | equals (const DiscreteFactor &other, double tol=1e-9) const override |
| equality | |
| void | print (const std::string &s="TableFactor:\n", const KeyFormatter &formatter=DefaultKeyFormatter) const override |
| print | |
| Eigen::SparseVector< double > | sparseTable () const |
| Getter for the underlying sparse vector. | |
| double | evaluate (const Assignment< Key > &values) const override |
| Evaluate probability distribution, is just look up in TableFactor. | |
| double | error (const DiscreteValues &values) const override |
| Calculate error for DiscreteValues x, is -log(probability). | |
| DiscreteFactor::shared_ptr | operator* (double s) const override |
| multiply with a scalar | |
| TableFactor | operator* (const TableFactor &f) const |
| multiply two TableFactors | |
| DecisionTreeFactor | operator* (const DecisionTreeFactor &f) const override |
| multiply with DecisionTreeFactor | |
| virtual DiscreteFactor::shared_ptr | multiply (const DiscreteFactor::shared_ptr &f) const override |
| Multiply factors, DiscreteFactor::shared_ptr edition. | |
| TableFactor | operator/ (const TableFactor &f) const |
| divide by factor f (safely) | |
| DiscreteFactor::shared_ptr | operator/ (const DiscreteFactor::shared_ptr &f) const override |
| divide by DiscreteFactor::shared_ptr f (safely) | |
| DecisionTreeFactor | toDecisionTreeFactor () const override |
| Convert into a decisiontree. | |
| TableFactor | toTableFactor () const override |
| Return this sparse table representation. | |
| TableFactor | choose (const DiscreteValues parentAssignments, DiscreteKeys parent_keys) const |
| Create a TableFactor that is a subset of this TableFactor. | |
| DiscreteFactor::shared_ptr | sum (size_t nrFrontals) const override |
| Create new factor by summing all values with the same separator values. | |
| DiscreteFactor::shared_ptr | sum (const Ordering &keys) const override |
| Create new factor by summing all values with the same separator values. | |
| double | max () const override |
| Find the maximum value in the factor. | |
| DiscreteFactor::shared_ptr | max (size_t nrFrontals) const override |
| Create new factor by maximizing over all values with the same separator. | |
| DiscreteFactor::shared_ptr | max (const Ordering &keys) const override |
| Create new factor by maximizing over all values with the same separator. | |
Public Member Functions | |
Standard Constructors | |
| TableFactor () | |
| Default constructor for I/O. | |
| TableFactor (const DiscreteKeys &keys, const TableFactor &potentials) | |
| Constructor from DiscreteKeys and TableFactor. | |
| TableFactor (const DiscreteKeys &keys, const Eigen::SparseVector< double > &table) | |
| Constructor from sparse_table. | |
| TableFactor (const DiscreteKeys &keys, const std::vector< double > &table) | |
| Constructor from doubles. | |
| TableFactor (const DiscreteKeys &keys, const std::string &table) | |
| Constructor from string. | |
| template<class SOURCE> | |
| TableFactor (const DiscreteKey &key, SOURCE table) | |
| Single-key specialization. | |
| TableFactor (const DiscreteKey &key, const std::vector< double > &row) | |
| Single-key specialization, with vector of doubles. | |
| TableFactor (const DiscreteKeys &keys, const DecisionTreeFactor &dtf) | |
| Constructor from DecisionTreeFactor. | |
| TableFactor (const DecisionTreeFactor &dtf) | |
| TableFactor (const DiscreteKeys &keys, const DecisionTree< Key, double > &dtree) | |
| Constructor from DecisionTree<Key, double>/AlgebraicDecisionTree. | |
| TableFactor (const DiscreteConditional &c) | |
| Construct from a DiscreteConditional type. | |
Advanced Interface | |
| TableFactor | apply (Unary op) const |
| Apply unary operator op(*this) where op accepts the discrete value. | |
| TableFactor | apply (UnaryAssignment op) const |
| Apply unary operator op(*this) where op accepts the discrete assignment and the value at that assignment. | |
| TableFactor | apply (const TableFactor &f, Binary op) const |
| Apply binary operator (*this) "op" f. | |
| uint64_t | unionRep (const DiscreteKeys &keys, const DiscreteValues &assign, const uint64_t idx) const |
| Create unique representation of union modes. | |
| std::unordered_map< uint64_t, AssignValList > | createMap (const DiscreteKeys &contract, const DiscreteKeys &free) const |
| Create a hash map of input factor with assignment of contract modes as keys and vector of hashed assignment of free modes and value as values. | |
| uint64_t | uniqueRep (const DiscreteKeys &keys, const uint64_t idx) const |
| Create unique representation. | |
| uint64_t | uniqueRep (const DiscreteValues &assignments) const |
| Create unique representation with DiscreteValues. | |
| DiscreteValues | findAssignments (const uint64_t idx) const |
| Find DiscreteValues for corresponding index. | |
| double | findValue (const DiscreteValues &values) const |
| Find value for corresponding DiscreteValues. | |
| shared_ptr | combine (size_t nrFrontals, Binary op) const |
| Combine frontal variables using binary operator "op". | |
| shared_ptr | combine (const Ordering &keys, Binary op) const |
| Combine frontal variables in an Ordering using binary operator "op". | |
| std::vector< std::pair< DiscreteValues, double > > | enumerate () const |
| Enumerate all values into a map from values to double. | |
| TableFactor | prune (size_t maxNrAssignments) const |
| Prune the decision tree of discrete variables. | |
| uint64_t | nrValues () const override |
| Get the number of non-zero values contained in this factor. | |
| DiscreteFactor::shared_ptr | restrict (const DiscreteValues &assignment) const override |
| Restrict the factor to the given assignment. | |
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. | |
HybridValues methods. | |
| double | error (const HybridValues &values) const override |
| Calculate error for HybridValues x, is -log(probability) Simply dispatches to DiscreteValues version. | |
| Public Member Functions inherited from gtsam::DiscreteFactor | |
| DiscreteFactor () | |
| Default constructor creates empty factor. | |
| template<typename CONTAINER> | |
| DiscreteFactor (const CONTAINER &keys, const std::map< Key, size_t > cardinalities={}) | |
| Construct from container of keys and map of cardinalities. | |
| DiscreteKeys | discreteKeys () const |
| Return all the discrete keys associated with this factor. | |
| std::map< Key, size_t > | cardinalities () const |
| size_t | cardinality (Key j) const |
| double | operator() (const DiscreteValues &values) const |
| Find value for given assignment of values to variables. | |
| virtual AlgebraicDecisionTree< Key > | errorTree () const |
| Compute error for each assignment and return as a tree. | |
| DiscreteFactor::shared_ptr | scale () const |
| Scale the factor values by the maximum to prevent underflow/overflow. | |
| Public Member Functions inherited from gtsam::Factor | |
| 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 | |
| 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. | |
Static Public Member Functions | |
| static Eigen::SparseVector< double > | Convert (const DiscreteKeys &keys, const std::vector< double > &table) |
| Convert probability table given as doubles to SparseVector. | |
| static Eigen::SparseVector< double > | Convert (const DiscreteKeys &keys, const std::string &table) |
| Convert probability table given as string to SparseVector. | |
Public Types | |
| typedef TableFactor | This |
| typedef DiscreteFactor | Base |
| Typedef to base class. | |
| typedef std::shared_ptr< TableFactor > | shared_ptr |
| typedef Eigen::SparseVector< double >::InnerIterator | SparseIt |
| typedef std::vector< std::pair< DiscreteValues, double > > | AssignValList |
| Public Types inherited from gtsam::DiscreteFactor | |
| typedef DiscreteFactor | This |
| This class. | |
| typedef std::shared_ptr< DiscreteFactor > | shared_ptr |
| shared_ptr to this class | |
| typedef Factor | Base |
| Our base class. | |
| using | Values = DiscreteValues |
| backwards compatibility | |
| using | Unary = std::function<double(const double&)> |
| using | UnaryAssignment |
| using | Binary = std::function<double(const double, const double)> |
| using | Names = DiscreteValues::Names |
| Translation table from values to strings. | |
| Public Types inherited from gtsam::Factor | |
| typedef KeyVector::iterator | iterator |
| Iterator over keys. | |
| typedef KeyVector::const_iterator | const_iterator |
| Const iterator over keys. | |
Protected Attributes | |
| Eigen::SparseVector< double > | sparse_table_ |
| SparseVector of nonzero probabilities. | |
| Protected Attributes inherited from gtsam::DiscreteFactor | |
| std::map< Key, size_t > | cardinalities_ |
| Map of Keys and their cardinalities. | |
| Protected Attributes inherited from gtsam::Factor | |
| KeyVector | keys_ |
| The keys involved in this factor. | |
Additional Inherited Members | |
| Factor () | |
| Default constructor for I/O. | |
| template<typename CONTAINER> | |
| Factor (const CONTAINER &keys) | |
| Construct factor from container of keys. | |
| template<typename ITERATOR> | |
| Factor (ITERATOR first, ITERATOR last) | |
| Construct factor from iterator keys. | |
| template<typename CONTAINER> | |
| static Factor | FromKeys (const CONTAINER &keys) |
| Construct factor from container of keys. | |
| template<typename ITERATOR> | |
| static Factor | FromIterators (ITERATOR first, ITERATOR last) |
| Construct factor from iterator keys. | |
| TableFactor gtsam::TableFactor::apply | ( | const TableFactor & | f, |
| Binary | op ) const |
Apply binary operator (*this) "op" f.
| f | the second argument for op |
| op | a binary operator that operates on TableFactor |
| TableFactor gtsam::TableFactor::apply | ( | Unary | op | ) | const |
Apply unary operator op(*this) where op accepts the discrete value.
| op | a unary operator that operates on TableFactor |
| TableFactor gtsam::TableFactor::apply | ( | UnaryAssignment | op | ) | const |
Apply unary operator op(*this) where op accepts the discrete assignment and the value at that assignment.
| op | a unary operator that operates on TableFactor |
| TableFactor::shared_ptr gtsam::TableFactor::combine | ( | const Ordering & | keys, |
| Binary | op ) const |
Combine frontal variables in an Ordering using binary operator "op".
| nrFrontals | nr. of frontal to combine variables in this factor |
| op | a binary operator that operates on TableFactor |
| TableFactor::shared_ptr gtsam::TableFactor::combine | ( | size_t | nrFrontals, |
| Binary | op ) const |
Combine frontal variables using binary operator "op".
| nrFrontals | nr. of frontal to combine variables in this factor |
| op | a binary operator that operates on TableFactor |
|
static |
Convert probability table given as doubles to SparseVector.
Example: {0, 1, 1, 0, 0, 1, 0} -> values: {1, 1, 1}, indices: {1, 2, 5}
|
overridevirtual |
equality
Reimplemented from gtsam::DiscreteFactor.
|
overridevirtual |
Calculate error for DiscreteValues x, is -log(probability).
Reimplemented from gtsam::DiscreteFactor.
|
overridevirtual |
Calculate error for HybridValues x, is -log(probability) Simply dispatches to DiscreteValues version.
Reimplemented from gtsam::DiscreteFactor.
|
overridevirtual |
Evaluate probability distribution, is just look up in TableFactor.
Implements gtsam::DiscreteFactor.
|
overridevirtual |
Render as html table.
| keyFormatter | GTSAM-style Key formatter. |
| names | optional, category names corresponding to choices. |
Implements gtsam::DiscreteFactor.
|
overridevirtual |
Render as markdown table.
| keyFormatter | GTSAM-style Key formatter. |
| names | optional, category names corresponding to choices. |
Implements gtsam::DiscreteFactor.
|
overridevirtual |
Find the maximum value in the factor.
Implements gtsam::DiscreteFactor.
|
overridevirtual |
Create new factor by maximizing over all values with the same separator.
Implements gtsam::DiscreteFactor.
|
overridevirtual |
Create new factor by maximizing over all values with the same separator.
Implements gtsam::DiscreteFactor.
|
overridevirtual |
Multiply factors, DiscreteFactor::shared_ptr edition.
This method accepts DiscreteFactor::shared_ptr and uses dynamic dispatch and specializations to perform the most efficient multiplication.
While converting a DecisionTreeFactor to a TableFactor is efficient, the reverse is not. Hence we specialize the code to return a TableFactor always.
| f | The factor to multiply with. |
Reimplemented from gtsam::DiscreteFactor.
|
inlineoverridevirtual |
Get the number of non-zero values contained in this factor.
It could be much smaller than prod_{key}(cardinality(key)).
Implements gtsam::DiscreteFactor.
|
overridevirtual |
multiply with DecisionTreeFactor
Implements gtsam::DiscreteFactor.
|
inlineoverridevirtual |
multiply with a scalar
Implements gtsam::DiscreteFactor.
|
overridevirtual |
divide by DiscreteFactor::shared_ptr f (safely)
Implements gtsam::DiscreteFactor.
|
overridevirtual |
Reimplemented from gtsam::DiscreteFactor.
| TableFactor gtsam::TableFactor::prune | ( | size_t | maxNrAssignments | ) | const |
Prune the decision tree of discrete variables.
Pruning will set the values 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).
| maxNrAssignments | The maximum number of assignments to keep. |
|
overridevirtual |
Restrict the factor to the given assignment.
Implements gtsam::DiscreteFactor.
|
overridevirtual |
Create new factor by summing all values with the same separator values.
Implements gtsam::DiscreteFactor.
|
overridevirtual |
Create new factor by summing all values with the same separator values.
Implements gtsam::DiscreteFactor.
|
overridevirtual |
Convert into a decisiontree.
Implements gtsam::DiscreteFactor.
|
inlineoverridevirtual |
Return this sparse table representation.
Reimplemented from gtsam::DiscreteFactor.