libDAI
List of all members
dai::InfAlg Class Referenceabstract

InfAlg is an abstract base class, defining the common interface of all inference algorithms in libDAI. More...

#include <dai/daialg.h>

Inheritance diagram for dai::InfAlg:
dai::DAIAlg< GRM > dai::BP dai::CBP dai::ExactInf dai::HAK dai::JTree dai::LC dai::MF dai::MR

Public Member Functions

Constructors/destructors
virtual ~InfAlg ()
 Virtual destructor (needed because this class contains virtual functions) More...
 
virtual InfAlgclone () const =0
 Returns a pointer to a new, cloned copy of *this (i.e., virtual copy constructor) More...
 
virtual InfAlgconstruct (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 FactorGraphfg ()=0
 Returns reference to underlying FactorGraph. More...
 
virtual const FactorGraphfg () 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< Factorbeliefs () 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 $\delta_{x_i, x}$) 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...
 

Detailed Description

InfAlg is an abstract base class, defining the common interface of all inference algorithms in libDAI.

Idea:

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().

Examples:
example_imagesegmentation.cpp, example_sprinkler_em.cpp, and uai2010-aie-solver.cpp.

Constructor & Destructor Documentation

virtual dai::InfAlg::~InfAlg ( )
inlinevirtual

Virtual destructor (needed because this class contains virtual functions)

Member Function Documentation

virtual InfAlg* dai::InfAlg::clone ( ) const
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.

virtual InfAlg* dai::InfAlg::construct ( const FactorGraph fg,
const PropertySet opts 
) const
pure virtual

Returns a pointer to a newly constructed inference algorithm.

Parameters
fgFactor graph on which to perform the inference algorithm;
optsParameters 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.

virtual std::string dai::InfAlg::name ( ) const
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.

virtual std::string dai::InfAlg::identify ( ) const
inlinevirtual

Identifies itself for logging purposes.

virtual FactorGraph& dai::InfAlg::fg ( )
pure virtual

Returns reference to underlying FactorGraph.

Implemented in dai::DAIAlg< GRM >.

Examples:
example_sprinkler_em.cpp.
virtual const FactorGraph& dai::InfAlg::fg ( ) const
pure virtual

Returns constant reference to underlying FactorGraph.

Implemented in dai::DAIAlg< GRM >.

virtual void dai::InfAlg::init ( )
pure virtual

Initializes all data structures of the approximate inference algorithm.

Note
This method should be called at least once before run() is called.

Implemented in dai::BP, dai::TreeEP, dai::JTree, dai::MR, dai::HAK, dai::LC, dai::MF, dai::CBP, and dai::ExactInf.

Examples:
example_imagesegmentation.cpp, example_sprinkler_em.cpp, and uai2010-aie-solver.cpp.
virtual void dai::InfAlg::init ( const VarSet vs)
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.

Exceptions
NOT_IMPLEMENTEDif not implemented/supported

Implemented in dai::BP, dai::TreeEP, dai::JTree, dai::MR, dai::HAK, dai::LC, dai::MF, dai::CBP, and dai::ExactInf.

virtual Real dai::InfAlg::run ( )
pure virtual

Runs the approximate inference algorithm.

Note
Before run() is called the first time, init() should have been called.

Implemented in dai::BP, dai::TreeEP, dai::JTree, dai::MR, dai::HAK, dai::LC, dai::MF, dai::CBP, and dai::ExactInf.

Examples:
example_imagesegmentation.cpp, and uai2010-aie-solver.cpp.
virtual Factor dai::InfAlg::belief ( const Var v) const
inlinevirtual

Returns the (approximate) marginal probability distribution of a variable.

Note
Before this method is called, run() should have been called.

Reimplemented in dai::BP, dai::MR, dai::LC, dai::MF, dai::CBP, and dai::ExactInf.

virtual Factor dai::InfAlg::belief ( const VarSet vs) const
pure virtual

Returns the (approximate) marginal probability distribution of a set of variables.

Note
Before this method is called, run() should have been called.
Exceptions
NOT_IMPLEMENTEDif not implemented/supported.
BELIEF_NOT_AVAILABLEif 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.

virtual Factor dai::InfAlg::beliefV ( size_t  i) const
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.

Note
Before this method is called, run() should have been called.

Reimplemented in dai::BP, dai::MR, dai::LC, dai::MF, dai::CBP, and dai::ExactInf.

Examples:
example_imagesegmentation.cpp, and uai2010-aie-solver.cpp.
virtual Factor dai::InfAlg::beliefF ( size_t  I) const
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.

Note
Before this method is called, run() should have been called.

Reimplemented in dai::BP, dai::CBP, and dai::ExactInf.

Examples:
example.cpp.
virtual std::vector<Factor> dai::InfAlg::beliefs ( ) const
pure virtual

Returns all beliefs (approximate marginal probability distributions) calculated by the algorithm.

Note
Before this method is called, run() should have been called.

Implemented in dai::BP, dai::JTree, dai::MR, dai::HAK, dai::LC, dai::MF, dai::CBP, and dai::ExactInf.

virtual Real dai::InfAlg::logZ ( ) const
pure virtual

Returns the logarithm of the (approximated) partition sum (normalizing constant of the factor graph).

Note
Before this method is called, run() should have been called.
Exceptions
NOT_IMPLEMENTEDif 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.

Examples:
uai2010-aie-solver.cpp.
virtual std::vector<size_t> dai::InfAlg::findMaximum ( ) const
inlinevirtual

Calculates the joint state of all variables that has maximum probability.

Note
Before this method is called, run() should have been called.
Exceptions
NOT_IMPLEMENTEDif not implemented/supported

Reimplemented in dai::BP, dai::JTree, and dai::ExactInf.

Examples:
uai2010-aie-solver.cpp.
virtual Real dai::InfAlg::maxDiff ( ) const
inlinevirtual

Returns maximum difference between single variable beliefs in the last iteration.

Exceptions
NOT_IMPLEMENTEDif not implemented/supported

Reimplemented in dai::BP, dai::TreeEP, dai::JTree, dai::MR, dai::HAK, dai::LC, dai::MF, dai::CBP, and dai::ExactInf.

Examples:
uai2010-aie-solver.cpp.
virtual size_t dai::InfAlg::Iterations ( ) const
inlinevirtual

Returns number of iterations done (one iteration passes over the complete factorgraph).

Exceptions
NOT_IMPLEMENTEDif not implemented/supported

Reimplemented in dai::BP, dai::TreeEP, dai::JTree, dai::MR, dai::HAK, dai::LC, dai::MF, dai::CBP, and dai::ExactInf.

Examples:
uai2010-aie-solver.cpp.
virtual void dai::InfAlg::setMaxIter ( size_t  )
inlinevirtual

Sets maximum number of iterations (one iteration passes over the complete factorgraph).

Exceptions
NOT_IMPLEMENTEDif not implemented/supported

Reimplemented in dai::BP, dai::TreeEP, dai::HAK, dai::LC, dai::MF, and dai::CBP.

Examples:
example_imagesegmentation.cpp.
virtual void dai::InfAlg::clamp ( size_t  i,
size_t  x,
bool  backup = false 
)
pure virtual

Clamp variable with index i to value x (i.e. multiply with a Kronecker delta $\delta_{x_i, x}$)

If backup == true, make a backup of all factors that are changed.

Implemented in dai::DAIAlg< GRM >.

virtual void dai::InfAlg::makeCavity ( size_t  i,
bool  backup = false 
)
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 >.

virtual void dai::InfAlg::makeRegionCavity ( std::vector< size_t >  facInds,
bool  backup = false 
)
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 >.

virtual void dai::InfAlg::backupFactor ( size_t  I)
pure virtual

Make a backup copy of factor I.

Exceptions
MULTIPLE_UNDOif a backup already exists

Implemented in dai::DAIAlg< GRM >.

virtual void dai::InfAlg::backupFactors ( const VarSet vs)
pure virtual

Make backup copies of all factors involving the variables in vs.

Exceptions
MULTIPLE_UNDOif a backup already exists

Implemented in dai::DAIAlg< GRM >.

virtual void dai::InfAlg::restoreFactor ( size_t  I)
pure virtual

Restore factor I from its backup copy.

Implemented in dai::DAIAlg< GRM >.

virtual void dai::InfAlg::restoreFactors ( const VarSet vs)
pure virtual

Restore the factors involving the variables in vs from their backup copies.

Implemented in dai::DAIAlg< GRM >.

virtual void dai::InfAlg::setProperties ( const PropertySet opts)
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.

virtual PropertySet dai::InfAlg::getProperties ( ) const
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.

virtual std::string dai::InfAlg::printProperties ( ) const
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.


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