libDAI
|
InfAlg is an abstract base class, defining the common interface of all inference algorithms in libDAI. More...
#include <dai/daialg.h>
Public Member Functions | |
Constructors/destructors | |
virtual | ~InfAlg () |
Virtual destructor (needed because this class contains virtual functions) More... | |
virtual InfAlg * | clone () const =0 |
Returns a pointer to a new, cloned copy of *this (i.e., virtual copy constructor) More... | |
virtual InfAlg * | construct (const FactorGraph &fg, const PropertySet &opts) const =0 |
Returns a pointer to a newly constructed inference algorithm. More... | |
Queries | |
virtual std::string | name () const =0 |
Returns the name of the algorithm. More... | |
virtual std::string | identify () const |
Identifies itself for logging purposes. More... | |
virtual FactorGraph & | fg ()=0 |
Returns reference to underlying FactorGraph. More... | |
virtual const FactorGraph & | fg () const =0 |
Returns constant reference to underlying FactorGraph. More... | |
Inference interface | |
virtual void | init ()=0 |
Initializes all data structures of the approximate inference algorithm. More... | |
virtual void | init (const VarSet &vs)=0 |
Initializes all data structures corresponding to some set of variables. More... | |
virtual Real | run ()=0 |
Runs the approximate inference algorithm. More... | |
virtual Factor | belief (const Var &v) const |
Returns the (approximate) marginal probability distribution of a variable. More... | |
virtual Factor | belief (const VarSet &vs) const =0 |
Returns the (approximate) marginal probability distribution of a set of variables. More... | |
virtual Factor | beliefV (size_t i) const |
Returns the (approximate) marginal probability distribution of the variable with index i. More... | |
virtual Factor | beliefF (size_t I) const |
Returns the (approximate) marginal probability distribution of the variables on which factor I depends. More... | |
virtual std::vector< Factor > | beliefs () const =0 |
Returns all beliefs (approximate marginal probability distributions) calculated by the algorithm. More... | |
virtual Real | logZ () const =0 |
Returns the logarithm of the (approximated) partition sum (normalizing constant of the factor graph). More... | |
virtual std::vector< size_t > | findMaximum () const |
Calculates the joint state of all variables that has maximum probability. More... | |
virtual Real | maxDiff () const |
Returns maximum difference between single variable beliefs in the last iteration. More... | |
virtual size_t | Iterations () const |
Returns number of iterations done (one iteration passes over the complete factorgraph). More... | |
virtual void | setMaxIter (size_t) |
Sets maximum number of iterations (one iteration passes over the complete factorgraph). More... | |
Changing the factor graph | |
virtual void | clamp (size_t i, size_t x, bool backup=false)=0 |
Clamp variable with index i to value x (i.e. multiply with a Kronecker delta ) More... | |
virtual void | makeCavity (size_t i, bool backup=false)=0 |
Sets all factors interacting with variable with index i to one. More... | |
virtual void | makeRegionCavity (std::vector< size_t > facInds, bool backup=false)=0 |
Sets all factors indicated by facInds to one. More... | |
Backup/restore mechanism for factors | |
virtual void | backupFactor (size_t I)=0 |
Make a backup copy of factor I. More... | |
virtual void | backupFactors (const VarSet &vs)=0 |
Make backup copies of all factors involving the variables in vs. More... | |
virtual void | restoreFactor (size_t I)=0 |
Restore factor I from its backup copy. More... | |
virtual void | restoreFactors (const VarSet &vs)=0 |
Restore the factors involving the variables in vs from their backup copies. More... | |
Managing parameters | |
virtual void | setProperties (const PropertySet &opts)=0 |
Set parameters of this inference algorithm. More... | |
virtual PropertySet | getProperties () const =0 |
Returns parameters of this inference algorithm converted into a PropertySet. More... | |
virtual std::string | printProperties () const =0 |
Returns parameters of this inference algorithm formatted as a string in the format "[key1=val1,key2=val2,...,keyn=valn]". More... | |
InfAlg is an abstract base class, defining the common interface of all inference algorithms in libDAI.
General marginalization functions like calcMarginal() now copy a complete InfAlg object. Instead, it would make more sense that they construct a new object without copying the FactorGraph or RegionGraph. Or they can simply be made methods of the general InfAlg class.
Use a PropertySet as output of an InfAlg, instead of functions like maxDiff() and Iterations().
|
inlinevirtual |
Virtual destructor (needed because this class contains virtual functions)
|
pure virtual |
Returns a pointer to a new, cloned copy of *this
(i.e., virtual copy constructor)
Implemented in dai::BP, dai::TreeEP, dai::JTree, dai::MR, dai::HAK, dai::LC, dai::MF, dai::TRWBP, dai::FBP, dai::CBP, and dai::ExactInf.
|
pure virtual |
Returns a pointer to a newly constructed inference algorithm.
fg | Factor graph on which to perform the inference algorithm; |
opts | Parameters passed to constructor of inference algorithm; |
Implemented in dai::BP, dai::TreeEP, dai::JTree, dai::MR, dai::HAK, dai::LC, dai::MF, dai::TRWBP, dai::FBP, dai::CBP, and dai::ExactInf.
|
pure virtual |
Returns the name of the algorithm.
Implemented in dai::BP, dai::TreeEP, dai::JTree, dai::MR, dai::HAK, dai::LC, dai::MF, dai::TRWBP, dai::FBP, dai::CBP, and dai::ExactInf.
|
inlinevirtual |
Identifies itself for logging purposes.
|
pure virtual |
Returns reference to underlying FactorGraph.
Implemented in dai::DAIAlg< GRM >.
|
pure virtual |
Returns constant reference to underlying FactorGraph.
Implemented in dai::DAIAlg< GRM >.
|
pure virtual |
Initializes all data structures of the approximate inference algorithm.
Implemented in dai::BP, dai::TreeEP, dai::JTree, dai::MR, dai::HAK, dai::LC, dai::MF, dai::CBP, and dai::ExactInf.
|
pure virtual |
Initializes all data structures corresponding to some set of variables.
This method can be used to do a partial initialization after a part of the factor graph has changed. Instead of initializing all data structures, it only initializes those involving the variables in vs.
NOT_IMPLEMENTED | if not implemented/supported |
Implemented in dai::BP, dai::TreeEP, dai::JTree, dai::MR, dai::HAK, dai::LC, dai::MF, dai::CBP, and dai::ExactInf.
|
pure virtual |
Runs the approximate inference algorithm.
Implemented in dai::BP, dai::TreeEP, dai::JTree, dai::MR, dai::HAK, dai::LC, dai::MF, dai::CBP, and dai::ExactInf.
Returns the (approximate) marginal probability distribution of a set of variables.
NOT_IMPLEMENTED | if not implemented/supported. |
BELIEF_NOT_AVAILABLE | if the requested belief cannot be calculated with this algorithm. |
Implemented in dai::BP, dai::JTree, dai::MR, dai::HAK, dai::LC, dai::MF, dai::CBP, and dai::ExactInf.
|
inlinevirtual |
Returns the (approximate) marginal probability distribution of the variable with index i.
For some approximate inference algorithms, using beliefV() is preferred to belief() for performance reasons.
Reimplemented in dai::BP, dai::MR, dai::LC, dai::MF, dai::CBP, and dai::ExactInf.
|
inlinevirtual |
Returns the (approximate) marginal probability distribution of the variables on which factor I depends.
For some approximate inference algorithms, using beliefF() is preferred to belief() for performance reasons.
Reimplemented in dai::BP, dai::CBP, and dai::ExactInf.
|
pure virtual |
Returns all beliefs (approximate marginal probability distributions) calculated by the algorithm.
Implemented in dai::BP, dai::JTree, dai::MR, dai::HAK, dai::LC, dai::MF, dai::CBP, and dai::ExactInf.
|
pure virtual |
Returns the logarithm of the (approximated) partition sum (normalizing constant of the factor graph).
NOT_IMPLEMENTED | if not implemented/supported |
Implemented in dai::BP, dai::TreeEP, dai::JTree, dai::MR, dai::HAK, dai::LC, dai::MF, dai::TRWBP, dai::CBP, dai::FBP, and dai::ExactInf.
|
inlinevirtual |
Calculates the joint state of all variables that has maximum probability.
NOT_IMPLEMENTED | if not implemented/supported |
Reimplemented in dai::BP, dai::JTree, and dai::ExactInf.
|
inlinevirtual |
Returns maximum difference between single variable beliefs in the last iteration.
NOT_IMPLEMENTED | if not implemented/supported |
Reimplemented in dai::BP, dai::TreeEP, dai::JTree, dai::MR, dai::HAK, dai::LC, dai::MF, dai::CBP, and dai::ExactInf.
|
inlinevirtual |
Returns number of iterations done (one iteration passes over the complete factorgraph).
NOT_IMPLEMENTED | if not implemented/supported |
Reimplemented in dai::BP, dai::TreeEP, dai::JTree, dai::MR, dai::HAK, dai::LC, dai::MF, dai::CBP, and dai::ExactInf.
|
inlinevirtual |
Sets maximum number of iterations (one iteration passes over the complete factorgraph).
NOT_IMPLEMENTED | if not implemented/supported |
Reimplemented in dai::BP, dai::TreeEP, dai::HAK, dai::LC, dai::MF, and dai::CBP.
|
pure virtual |
Clamp variable with index i to value x (i.e. multiply with a Kronecker delta )
If backup == true
, make a backup of all factors that are changed.
Implemented in dai::DAIAlg< GRM >.
|
pure virtual |
Sets all factors interacting with variable with index i to one.
If backup == true
, make a backup of all factors that are changed.
Implemented in dai::DAIAlg< GRM >.
|
pure virtual |
Sets all factors indicated by facInds to one.
If backup == true
, make a backup of all factors that are changed.
Implemented in dai::DAIAlg< GRM >.
|
pure virtual |
Make a backup copy of factor I.
MULTIPLE_UNDO | if a backup already exists |
Implemented in dai::DAIAlg< GRM >.
|
pure virtual |
Make backup copies of all factors involving the variables in vs.
MULTIPLE_UNDO | if a backup already exists |
Implemented in dai::DAIAlg< GRM >.
|
pure virtual |
Restore factor I from its backup copy.
Implemented in dai::DAIAlg< GRM >.
|
pure virtual |
Restore the factors involving the variables in vs from their backup copies.
Implemented in dai::DAIAlg< GRM >.
|
pure virtual |
Set parameters of this inference algorithm.
The parameters are set according to the PropertySet opts. The values can be stored either as std::string or as the type of the corresponding MF::props member.
Implemented in dai::BP, dai::TreeEP, dai::JTree, dai::MR, dai::HAK, dai::LC, dai::MF, dai::CBP, dai::TRWBP, and dai::ExactInf.
|
pure virtual |
Returns parameters of this inference algorithm converted into a PropertySet.
Implemented in dai::BP, dai::TreeEP, dai::JTree, dai::MR, dai::HAK, dai::LC, dai::MF, dai::CBP, dai::TRWBP, and dai::ExactInf.
|
pure virtual |
Returns parameters of this inference algorithm formatted as a string in the format "[key1=val1,key2=val2,...,keyn=valn]".
Implemented in dai::BP, dai::TreeEP, dai::JTree, dai::MR, dai::HAK, dai::LC, dai::MF, dai::CBP, dai::TRWBP, and dai::ExactInf.