Public Types | Protected Attributes | List of all members
gtsam::DiscreteFactor Class Referenceabstract

#include <DiscreteFactor.h>

Inheritance diagram for gtsam::DiscreteFactor:
Inheritance graph
[legend]

Public Types

typedef Factor Base
 Our base class. More...
 
using Binary = std::function< double(const double, const double)>
 
typedef std::shared_ptr< DiscreteFactorshared_ptr
 shared_ptr to this class More...
 
typedef DiscreteFactor This
 This class. More...
 
using Unary = std::function< double(const double &)>
 
using UnaryAssignment = std::function< double(const Assignment< Key > &, const double &)>
 
using Values = DiscreteValues
 backwards compatibility More...
 
- Public Types inherited from gtsam::Factor
typedef KeyVector::const_iterator const_iterator
 Const iterator over keys. More...
 
typedef KeyVector::iterator iterator
 Iterator over keys. More...
 

Public Member Functions

Standard Constructors
 DiscreteFactor ()
 
template<typename CONTAINER >
 DiscreteFactor (const CONTAINER &keys, const std::map< Key, size_t > cardinalities={})
 
Testable
virtual bool equals (const DiscreteFactor &lf, double tol=1e-9) const
 equals More...
 
void print (const std::string &s="DiscreteFactor\n", const KeyFormatter &formatter=DefaultKeyFormatter) const override
 print More...
 
Standard Interface
DiscreteKeys discreteKeys () const
 Return all the discrete keys associated with this factor. More...
 
std::map< Key, size_tcardinalities () const
 
size_t cardinality (Key j) const
 
virtual double evaluate (const Assignment< Key > &values) const =0
 Calculate probability for given values. Calls specialized evaluation under the hood. More...
 
double operator() (const DiscreteValues &values) const
 Find value for given assignment of values to variables. More...
 
virtual double error (const DiscreteValues &values) const
 Error is just -log(value) More...
 
double error (const HybridValues &c) const override
 
virtual AlgebraicDecisionTree< KeyerrorTree () const
 Compute error for each assignment and return as a tree. More...
 
virtual DecisionTreeFactor operator* (const DecisionTreeFactor &) const =0
 
virtual DecisionTreeFactor toDecisionTreeFactor () const =0
 
- Public Member Functions inherited from gtsam::Factor
virtual ~Factor ()=default
 Default destructor. More...
 
bool empty () const
 Whether the factor is empty (involves zero variables). More...
 
Key front () const
 First key. More...
 
Key back () const
 Last key. More...
 
const_iterator find (Key key) const
 find More...
 
const KeyVectorkeys () const
 Access the factor's involved variable keys. More...
 
const_iterator begin () const
 
const_iterator end () const
 
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 More...
 
KeyVectorkeys ()
 
iterator begin ()
 
iterator end ()
 

Protected Attributes

std::map< Key, size_tcardinalities_
 Map of Keys and their cardinalities. More...
 
- Protected Attributes inherited from gtsam::Factor
KeyVector keys_
 The keys involved in this factor. More...
 

Wrapper support

using Names = DiscreteValues::Names
 Translation table from values to strings. More...
 
virtual std::string markdown (const KeyFormatter &keyFormatter=DefaultKeyFormatter, const Names &names={}) const =0
 Render as markdown table. More...
 
virtual std::string html (const KeyFormatter &keyFormatter=DefaultKeyFormatter, const Names &names={}) const =0
 Render as html table. More...
 

Additional Inherited Members

- Protected Member Functions inherited from gtsam::Factor
 Factor ()
 
template<typename CONTAINER >
 Factor (const CONTAINER &keys)
 
template<typename ITERATOR >
 Factor (ITERATOR first, ITERATOR last)
 
- Static Protected Member Functions inherited from gtsam::Factor
template<typename CONTAINER >
static Factor FromKeys (const CONTAINER &keys)
 
template<typename ITERATOR >
static Factor FromIterators (ITERATOR first, ITERATOR last)
 

Detailed Description

Base class for discrete probabilistic factors The most general one is the derived DecisionTreeFactor

DecisionTreeFactor, which represent a discrete distribution over a set of variables.

Definition at line 39 of file DiscreteFactor.h.

Member Typedef Documentation

◆ Base

Our base class.

Definition at line 45 of file DiscreteFactor.h.

◆ Binary

using gtsam::DiscreteFactor::Binary = std::function<double(const double, const double)>

Definition at line 52 of file DiscreteFactor.h.

◆ Names

Translation table from values to strings.

Definition at line 139 of file DiscreteFactor.h.

◆ shared_ptr

shared_ptr to this class

Definition at line 44 of file DiscreteFactor.h.

◆ This

This class.

Definition at line 42 of file DiscreteFactor.h.

◆ Unary

using gtsam::DiscreteFactor::Unary = std::function<double(const double&)>

Definition at line 49 of file DiscreteFactor.h.

◆ UnaryAssignment

using gtsam::DiscreteFactor::UnaryAssignment = std::function<double(const Assignment<Key>&, const double&)>

Definition at line 51 of file DiscreteFactor.h.

◆ Values

backwards compatibility

Definition at line 47 of file DiscreteFactor.h.

Constructor & Destructor Documentation

◆ DiscreteFactor() [1/2]

gtsam::DiscreteFactor::DiscreteFactor ( )
inline

Default constructor creates empty factor

Definition at line 63 of file DiscreteFactor.h.

◆ DiscreteFactor() [2/2]

template<typename CONTAINER >
gtsam::DiscreteFactor::DiscreteFactor ( const CONTAINER &  keys,
const std::map< Key, size_t cardinalities = {} 
)
inline

Construct from container of keys and map of cardinalities. This constructor is used internally from derived factor constructors, either from a container of keys or from a boost::assign::list_of.

Definition at line 71 of file DiscreteFactor.h.

Member Function Documentation

◆ cardinalities()

std::map<Key, size_t> gtsam::DiscreteFactor::cardinalities ( ) const
inline

Definition at line 96 of file DiscreteFactor.h.

◆ cardinality()

size_t gtsam::DiscreteFactor::cardinality ( Key  j) const
inline

Definition at line 98 of file DiscreteFactor.h.

◆ discreteKeys()

DiscreteKeys DiscreteFactor::discreteKeys ( ) const

Return all the discrete keys associated with this factor.

Definition at line 37 of file DiscreteFactor.cpp.

◆ equals()

bool DiscreteFactor::equals ( const DiscreteFactor lf,
double  tol = 1e-9 
) const
virtual

◆ error() [1/2]

double DiscreteFactor::error ( const DiscreteValues values) const
virtual

Error is just -log(value)

Reimplemented in gtsam::TableFactor, and gtsam::DecisionTreeFactor.

Definition at line 49 of file DiscreteFactor.cpp.

◆ error() [2/2]

double DiscreteFactor::error ( const HybridValues c) const
overridevirtual

All factor types need to implement an error function. In factor graphs, this is the negative log-likelihood.

Reimplemented from gtsam::Factor.

Reimplemented in gtsam::TableFactor.

Definition at line 54 of file DiscreteFactor.cpp.

◆ errorTree()

AlgebraicDecisionTree< Key > DiscreteFactor::errorTree ( ) const
virtual

Compute error for each assignment and return as a tree.

Reimplemented in gtsam::BinaryAllDiff, gtsam::Domain, gtsam::AllDiff, and gtsam::SingleValue.

Definition at line 59 of file DiscreteFactor.cpp.

◆ evaluate()

virtual double gtsam::DiscreteFactor::evaluate ( const Assignment< Key > &  values) const
pure virtual

Calculate probability for given values. Calls specialized evaluation under the hood.

Note: Uses Assignment<Key> as it is the base class of DiscreteValues.

Parameters
valuesDiscrete assignment.
Returns
double

Implemented in gtsam::TableFactor, gtsam::DecisionTreeFactor, gtsam::Domain, gtsam::SingleValue, gtsam::BinaryAllDiff, and gtsam::AllDiff.

◆ html()

virtual std::string gtsam::DiscreteFactor::html ( const KeyFormatter keyFormatter = DefaultKeyFormatter,
const Names names = {} 
) const
pure virtual

Render as html table.

Parameters
keyFormatterGTSAM-style Key formatter.
namesoptional, category names corresponding to choices.
Returns
std::string a html string.

Implemented in gtsam::TableFactor, gtsam::DecisionTreeFactor, gtsam::DiscreteConditional, and gtsam::Constraint.

◆ markdown()

virtual std::string gtsam::DiscreteFactor::markdown ( const KeyFormatter keyFormatter = DefaultKeyFormatter,
const Names names = {} 
) const
pure virtual

Render as markdown table.

Parameters
keyFormatterGTSAM-style Key formatter.
namesoptional, category names corresponding to choices.
Returns
std::string a markdown string.

Implemented in gtsam::TableFactor, gtsam::DecisionTreeFactor, gtsam::DiscreteConditional, and gtsam::Constraint.

◆ operator()()

double gtsam::DiscreteFactor::operator() ( const DiscreteValues values) const
inline

Find value for given assignment of values to variables.

Definition at line 112 of file DiscreteFactor.h.

◆ operator*()

virtual DecisionTreeFactor gtsam::DiscreteFactor::operator* ( const DecisionTreeFactor ) const
pure virtual

◆ print()

void gtsam::DiscreteFactor::print ( const std::string &  s = "DiscreteFactor\n",
const KeyFormatter formatter = DefaultKeyFormatter 
) const
inlineoverridevirtual

◆ toDecisionTreeFactor()

virtual DecisionTreeFactor gtsam::DiscreteFactor::toDecisionTreeFactor ( ) const
pure virtual

Member Data Documentation

◆ cardinalities_

std::map<Key, size_t> gtsam::DiscreteFactor::cardinalities_
protected

Map of Keys and their cardinalities.

Definition at line 56 of file DiscreteFactor.h.


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


gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:23:42