libDAI
Classes | Public Member Functions | Public Attributes | Private Attributes | List of all members
dai::DecMAP Class Reference

Approximate inference algorithm DecMAP, which constructs a MAP state by decimation. More...

#include <dai/decmap.h>

Inheritance diagram for dai::DecMAP:
dai::DAIAlg< GRM > dai::InfAlg

Classes

struct  Properties
 Parameters for DecMAP. More...

Public Member Functions

 DecMAP ()
 Default constructor.
 DecMAP (const FactorGraph &fg, const PropertySet &opts)
 Construct from FactorGraph fg and PropertySet opts.
General InfAlg interface
virtual DecMAPclone () const
 Returns a pointer to a new, cloned copy of *this (i.e., virtual copy constructor)
virtual DecMAPconstruct (const FactorGraph &fg, const PropertySet &opts) const
 Returns a pointer to a newly constructed inference algorithm.
virtual std::string name () const
 Returns the name of the algorithm.
virtual Factor belief (const Var &v) const
 Returns the (approximate) marginal probability distribution of a variable.
virtual Factor belief (const VarSet &) const
 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
 Returns all beliefs (approximate marginal probability distributions) calculated by the algorithm.
virtual Real logZ () const
 Returns the logarithm of the (approximated) partition sum (normalizing constant of the factor graph).
virtual std::vector< size_t > findMaximum () const
 Calculates the joint state of all variables that has maximum probability.
virtual void init ()
 Initializes all data structures of the approximate inference algorithm.
virtual void init (const VarSet &)
 Initializes all data structures corresponding to some set of variables.
virtual Real run ()
 Runs the approximate inference algorithm.
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 setProperties (const PropertySet &opts)
 Set parameters of this inference algorithm.
virtual PropertySet getProperties () const
 Returns parameters of this inference algorithm converted into a PropertySet.
virtual std::string printProperties () const
 Returns parameters of this inference algorithm formatted as a string in the format "[key1=val1,key2=val2,...,keyn=valn]".
- Public Member Functions inherited from dai::DAIAlg< GRM >
 DAIAlg ()
 Default constructor.
 DAIAlg (const GRM &grm)
 Construct from GRM.
FactorGraphfg ()
 Returns reference to underlying FactorGraph.
const FactorGraphfg () const
 Returns constant reference to underlying FactorGraph.
void clamp (size_t i, size_t x, bool backup=false)
 Clamp variable with index i to value x (i.e. multiply with a Kronecker delta $\delta_{x_i, x}$)
void makeCavity (size_t i, bool backup=false)
 Sets all factors interacting with variable with index i to one.
void backupFactor (size_t I)
 Make a backup copy of factor I.
void backupFactors (const VarSet &vs)
 Make backup copies of all factors involving the variables in vs.
void restoreFactor (size_t I)
 Restore factor I from its backup copy.
void restoreFactors (const VarSet &vs)
 Restore the factors involving the variables in vs from their backup copies.
- Public Member Functions inherited from dai::InfAlg
virtual ~InfAlg ()
 Virtual destructor (needed because this class contains virtual functions)
virtual std::string identify () const
 Identifies itself for logging purposes.
virtual void setMaxIter (size_t)
 Sets maximum number of iterations (one iteration passes over the complete factorgraph).

Public Attributes

struct dai::DecMAP::Properties props

Private Attributes

std::vector< size_t > _state
 Stores the final MAP state.
Real _logp
 Stores the log probability of the MAP state.
Real _maxdiff
 Maximum difference encountered so far.
size_t _iters
 Number of iterations needed.

Detailed Description

Approximate inference algorithm DecMAP, which constructs a MAP state by decimation.

Decimation involves repeating the following two steps until no free variables remain:

Examples:
example.cpp.

Constructor & Destructor Documentation

dai::DecMAP::DecMAP ( )
inline

Default constructor.

dai::DecMAP::DecMAP ( const FactorGraph fg,
const PropertySet opts 
)

Construct from FactorGraph fg and PropertySet opts.

Parameters
fgFactor graph.
optsParameters
See Also
Properties

Member Function Documentation

virtual DecMAP* dai::DecMAP::clone ( ) const
inlinevirtual

Returns a pointer to a new, cloned copy of *this (i.e., virtual copy constructor)

Implements dai::InfAlg.

virtual DecMAP* dai::DecMAP::construct ( const FactorGraph fg,
const PropertySet opts 
) const
inlinevirtual

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;

Implements dai::InfAlg.

virtual std::string dai::DecMAP::name ( ) const
inlinevirtual

Returns the name of the algorithm.

Implements dai::InfAlg.

virtual Factor dai::DecMAP::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 from dai::InfAlg.

Factor dai::DecMAP::belief ( const VarSet vs) const
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.

Implements dai::InfAlg.

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

virtual Factor dai::DecMAP::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 from dai::InfAlg.

vector< Factor > dai::DecMAP::beliefs ( ) const
virtual

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

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

Implements dai::InfAlg.

virtual Real dai::DecMAP::logZ ( ) const
inlinevirtual

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

Implements dai::InfAlg.

virtual std::vector<size_t> dai::DecMAP::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 from dai::InfAlg.

Examples:
example.cpp.
virtual void dai::DecMAP::init ( )
inlinevirtual

Initializes all data structures of the approximate inference algorithm.

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

Implements dai::InfAlg.

Examples:
example.cpp.
virtual void dai::DecMAP::init ( const VarSet vs)
inlinevirtual

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

Implements dai::InfAlg.

Real dai::DecMAP::run ( )
virtual

Runs the approximate inference algorithm.

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

Implements dai::InfAlg.

Examples:
example.cpp.
virtual Real dai::DecMAP::maxDiff ( ) const
inlinevirtual

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

Exceptions
NOT_IMPLEMENTEDif not implemented/supported

Reimplemented from dai::InfAlg.

virtual size_t dai::DecMAP::Iterations ( ) const
inlinevirtual

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

Exceptions
NOT_IMPLEMENTEDif not implemented/supported

Reimplemented from dai::InfAlg.

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

Implements dai::InfAlg.

PropertySet dai::DecMAP::getProperties ( ) const
virtual

Returns parameters of this inference algorithm converted into a PropertySet.

Implements dai::InfAlg.

string dai::DecMAP::printProperties ( ) const
virtual

Returns parameters of this inference algorithm formatted as a string in the format "[key1=val1,key2=val2,...,keyn=valn]".

Implements dai::InfAlg.

Member Data Documentation

std::vector<size_t> dai::DecMAP::_state
private

Stores the final MAP state.

Real dai::DecMAP::_logp
private

Stores the log probability of the MAP state.

Real dai::DecMAP::_maxdiff
private

Maximum difference encountered so far.

size_t dai::DecMAP::_iters
private

Number of iterations needed.


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