#include <dai/mf.h>
Public Member Functions | |
Constructors/destructors | |
MF () | |
Default constructor. | |
MF (const FactorGraph &fg, const PropertySet &opts) | |
Construct from FactorGraph fg and PropertySet opts. | |
General InfAlg interface | |
virtual MF * | clone () const |
Returns a pointer to a new, cloned copy of *this (i.e., virtual copy constructor). | |
virtual std::string | identify () const |
Identifies itself for logging purposes. | |
virtual Factor | belief (const Var &v) const |
Returns the (approximate) marginal probability distribution of a variable. | |
virtual Factor | belief (const VarSet &vs) 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 std::vector< Factor > | beliefs () 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 void | init () |
Initializes all data structures of the approximate inference algorithm. | |
virtual void | init (const VarSet &ns) |
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 | setMaxIter (size_t maxiter) |
Sets maximum number of iterations (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 Attributes | |
struct dai::MF::Properties | props |
Static Public Attributes | |
static const char * | Name = "MF" |
Name of this inference algorithm. | |
Private Member Functions | |
void | construct () |
Helper function for constructors. | |
Factor | calcNewBelief (size_t i) |
Calculates an updated belief of variable i. | |
Private Attributes | |
std::vector< Factor > | _beliefs |
Current approximations of single variable marginals. | |
Real | _maxdiff |
Maximum difference encountered so far. | |
size_t | _iters |
Number of iterations needed. | |
Classes | |
struct | Properties |
Parameters for MF. More... |
The Mean Field algorithm iteratively calculates approximations of single variable marginals (beliefs). The update equation for a single belief is given by:
for naive mean field and by
for hard-spin mean field. These update equations are performed for all variables until convergence.
dai::MF::MF | ( | ) | [inline] |
Default constructor.
dai::MF::MF | ( | const FactorGraph & | fg, | |
const PropertySet & | opts | |||
) | [inline] |
Construct from FactorGraph fg and PropertySet opts.
fg | Factor graph. | |
opts | Parameters |
virtual MF* dai::MF::clone | ( | ) | const [inline, virtual] |
Returns a pointer to a new, cloned copy of *this
(i.e., virtual copy constructor).
Implements dai::InfAlg.
string dai::MF::identify | ( | ) | const [virtual] |
Returns the (approximate) marginal probability distribution of a variable.
Reimplemented from dai::InfAlg.
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. |
Implements dai::InfAlg.
Factor dai::MF::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.
Reimplemented from dai::InfAlg.
vector< Factor > dai::MF::beliefs | ( | ) | const [virtual] |
Returns all beliefs (approximate marginal probability distributions) calculated by the algorithm.
Implements dai::InfAlg.
Real dai::MF::logZ | ( | ) | const [virtual] |
Returns the logarithm of the (approximated) partition sum (normalizing constant of the factor graph).
NOT_IMPLEMENTED | if not implemented/supported |
Implements dai::InfAlg.
void dai::MF::init | ( | ) | [virtual] |
Initializes all data structures of the approximate inference algorithm.
Implements dai::InfAlg.
void dai::MF::init | ( | const VarSet & | vs | ) | [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 |
Implements dai::InfAlg.
Real dai::MF::run | ( | ) | [virtual] |
virtual Real dai::MF::maxDiff | ( | ) | const [inline, virtual] |
Returns maximum difference between single variable beliefs in the last iteration.
NOT_IMPLEMENTED | if not implemented/supported |
Reimplemented from dai::InfAlg.
virtual size_t dai::MF::Iterations | ( | ) | const [inline, virtual] |
Returns number of iterations done (one iteration passes over the complete factorgraph).
NOT_IMPLEMENTED | if not implemented/supported |
Reimplemented from dai::InfAlg.
virtual void dai::MF::setMaxIter | ( | size_t | ) | [inline, virtual] |
Sets maximum number of iterations (one iteration passes over the complete factorgraph).
NOT_IMPLEMENTED | if not implemented/supported |
Reimplemented from dai::InfAlg.
void dai::MF::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::MF::getProperties | ( | ) | const [virtual] |
Returns parameters of this inference algorithm converted into a PropertySet.
Implements dai::InfAlg.
string dai::MF::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.
void dai::MF::construct | ( | ) | [private] |
Helper function for constructors.
Factor dai::MF::calcNewBelief | ( | size_t | i | ) | [private] |
Calculates an updated belief of variable i.
std::vector<Factor> dai::MF::_beliefs [private] |
Current approximations of single variable marginals.
Real dai::MF::_maxdiff [private] |
Maximum difference encountered so far.
size_t dai::MF::_iters [private] |
Number of iterations needed.
const char * dai::MF::Name = "MF" [static] |
Name of this inference algorithm.