dai::InfAlg Class Reference

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::DAIAlg< dai::FactorGraph > dai::DAIAlg< dai::RegionGraph > dai::BP dai::CBP dai::DecMAP dai::ExactInf dai::Gibbs dai::HAK dai::JTree dai::LC dai::MF dai::MR

List of all members.

Public Member Functions

Constructors/destructors
virtual ~InfAlg ()
 Virtual destructor (needed because this class contains virtual functions).
virtual InfAlgclone () const =0
 Returns a pointer to a new, cloned copy of *this (i.e., virtual copy constructor).
Queries
virtual std::string identify () const =0
 Identifies itself for logging purposes.
virtual FactorGraphfg ()=0
 Returns reference to underlying FactorGraph.
virtual const FactorGraphfg () const =0
 Returns constant reference to underlying FactorGraph.
Inference interface
virtual void init ()=0
 Initializes all data structures of the approximate inference algorithm.
virtual void init (const VarSet &vs)=0
 Initializes all data structures corresponding to some set of variables.
virtual Real run ()=0
 Runs the approximate inference algorithm.
virtual Factor belief (const Var &v) const
 Returns the (approximate) marginal probability distribution of a variable.
virtual Factor belief (const VarSet &vs) const =0
 Returns the (approximate) marginal probability distribution of a set of variables.
virtual Factor beliefV (size_t i) const
 Returns the (approximate) marginal probability distribution of the variable with index i.
virtual Factor beliefF (size_t I) const
 Returns the (approximate) marginal probability distribution of the variables on which factor I depends.
virtual std::vector< Factorbeliefs () const =0
 Returns all beliefs (approximate marginal probability distributions) calculated by the algorithm.
virtual Real logZ () const =0
 Returns the logarithm of the (approximated) partition sum (normalizing constant of the factor graph).
virtual std::vector< std::size_t > findMaximum () const
 Calculates the joint state of all variables that has maximum probability.
virtual Real maxDiff () const
 Returns maximum difference between single variable beliefs in the last iteration.
virtual size_t Iterations () const
 Returns number of iterations done (one iteration passes over the complete factorgraph).
virtual void setMaxIter (size_t)
 Sets maximum number of iterations (one iteration passes over the complete factorgraph).
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}$).
virtual void makeCavity (size_t i, bool backup=false)=0
 Sets all factors interacting with variable with index i to one.
Backup/restore mechanism for factors
virtual void backupFactor (size_t I)=0
 Make a backup copy of factor I.
virtual void backupFactors (const VarSet &vs)=0
 Make backup copies of all factors involving the variables in vs.
virtual void restoreFactor (size_t I)=0
 Restore factor I from its backup copy.
virtual void restoreFactors (const VarSet &vs)=0
 Restore the factors involving the variables in vs from their backup copies.
Managing parameters
virtual void setProperties (const PropertySet &opts)=0
 Set parameters of this inference algorithm.
virtual PropertySet getProperties () const =0
 Returns parameters of this inference algorithm converted into a PropertySet.
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]".


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.
Idea:
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 (  )  [inline, virtual]

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::CBP, dai::DecMAP, dai::ExactInf, dai::FBP, dai::Gibbs, dai::HAK, dai::JTree, dai::LC, dai::MF, dai::MR, dai::TreeEP, and dai::TRWBP.

virtual std::string dai::InfAlg::identify (  )  const [pure virtual]

Identifies itself for logging purposes.

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

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

virtual const FactorGraph& dai::InfAlg::fg (  )  const [pure virtual]

Returns constant reference to underlying FactorGraph.

Implemented in dai::DAIAlg< GRM >, dai::DAIAlg< dai::RegionGraph >, and dai::DAIAlg< dai::FactorGraph >.

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::CBP, dai::DecMAP, dai::ExactInf, dai::Gibbs, dai::HAK, dai::JTree, dai::LC, dai::MF, dai::MR, and dai::TreeEP.

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_IMPLEMENTED if not implemented/supported

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

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::CBP, dai::DecMAP, dai::ExactInf, dai::Gibbs, dai::HAK, dai::JTree, dai::LC, dai::MF, dai::MR, and dai::TreeEP.

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

virtual Factor dai::InfAlg::belief ( const Var v  )  const [inline, virtual]

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::CBP, dai::DecMAP, dai::ExactInf, dai::Gibbs, dai::LC, dai::MF, and dai::MR.

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_IMPLEMENTED if not implemented/supported.
BELIEF_NOT_AVAILABLE if the requested belief cannot be calculated with this algorithm.

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

virtual Factor dai::InfAlg::beliefV ( size_t  i  )  const [inline, virtual]

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::CBP, dai::DecMAP, dai::ExactInf, dai::Gibbs, dai::LC, dai::MF, and dai::MR.

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

virtual Factor dai::InfAlg::beliefF ( size_t  I  )  const [inline, virtual]

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, dai::DecMAP, dai::ExactInf, and dai::Gibbs.

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::CBP, dai::DecMAP, dai::ExactInf, dai::Gibbs, dai::HAK, dai::JTree, dai::LC, dai::MF, and dai::MR.

Examples:
uai2010-aie-solver.cpp.

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_IMPLEMENTED if not implemented/supported

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

Examples:
uai2010-aie-solver.cpp.

virtual std::vector<std::size_t> dai::InfAlg::findMaximum (  )  const [inline, virtual]

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

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

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

Examples:
uai2010-aie-solver.cpp.

virtual Real dai::InfAlg::maxDiff (  )  const [inline, virtual]

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

Exceptions:
NOT_IMPLEMENTED if not implemented/supported

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

Examples:
uai2010-aie-solver.cpp.

virtual size_t dai::InfAlg::Iterations (  )  const [inline, virtual]

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

Exceptions:
NOT_IMPLEMENTED if not implemented/supported

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

Examples:
uai2010-aie-solver.cpp.

virtual void dai::InfAlg::setMaxIter ( size_t   )  [inline, virtual]

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

Exceptions:
NOT_IMPLEMENTED if not implemented/supported

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

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 >, dai::DAIAlg< dai::RegionGraph >, and dai::DAIAlg< dai::FactorGraph >.

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 >, dai::DAIAlg< dai::RegionGraph >, and dai::DAIAlg< dai::FactorGraph >.

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

Make a backup copy of factor I.

Exceptions:
MULTIPLE_UNDO if a backup already exists

Implemented in dai::DAIAlg< GRM >, dai::DAIAlg< dai::RegionGraph >, and dai::DAIAlg< dai::FactorGraph >.

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

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

Exceptions:
MULTIPLE_UNDO if a backup already exists

Implemented in dai::DAIAlg< GRM >, dai::DAIAlg< dai::RegionGraph >, and dai::DAIAlg< dai::FactorGraph >.

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

Restore factor I from its backup copy.

Implemented in dai::DAIAlg< GRM >, dai::DAIAlg< dai::RegionGraph >, and dai::DAIAlg< dai::FactorGraph >.

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 >, dai::DAIAlg< dai::RegionGraph >, and dai::DAIAlg< dai::FactorGraph >.

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::CBP, dai::DecMAP, dai::ExactInf, dai::Gibbs, dai::HAK, dai::JTree, dai::LC, dai::MF, dai::MR, dai::TreeEP, and dai::TRWBP.

virtual PropertySet dai::InfAlg::getProperties (  )  const [pure virtual]

Returns parameters of this inference algorithm converted into a PropertySet.

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

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::CBP, dai::DecMAP, dai::ExactInf, dai::Gibbs, dai::HAK, dai::JTree, dai::LC, dai::MF, dai::MR, dai::TreeEP, and dai::TRWBP.


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

Generated on Thu Aug 5 19:04:04 2010 for libDAI by  doxygen 1.5.5