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

Approximate inference algorithm "Loop Corrected Belief Propagation" [MoK07]. More...

#include <dai/lc.h>

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

Classes

struct  Properties
 Parameters for LC. More...
 

Public Member Functions

 LC ()
 Default constructor. More...
 
 LC (const FactorGraph &fg, const PropertySet &opts)
 Construct from FactorGraph fg and PropertySet opts. More...
 
General InfAlg interface
virtual LCclone () const
 Returns a pointer to a new, cloned copy of *this (i.e., virtual copy constructor) More...
 
virtual LCconstruct (const FactorGraph &fg, const PropertySet &opts) const
 Returns a pointer to a newly constructed inference algorithm. More...
 
virtual std::string name () const
 Returns the name of the algorithm. More...
 
virtual Factor belief (const Var &v) const
 Returns the (approximate) marginal probability distribution of a variable. More...
 
virtual Factor belief (const VarSet &) const
 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 std::vector< Factorbeliefs () const
 Returns all beliefs (approximate marginal probability distributions) calculated by the algorithm. More...
 
virtual Real logZ () const
 Returns the logarithm of the (approximated) partition sum (normalizing constant of the factor graph). More...
 
virtual void init ()
 Initializes all data structures of the approximate inference algorithm. More...
 
virtual void init (const VarSet &)
 Initializes all data structures corresponding to some set of variables. More...
 
virtual Real run ()
 Runs the approximate inference algorithm. 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 maxiter)
 Sets maximum number of iterations (one iteration passes over the complete factorgraph). More...
 
virtual void setProperties (const PropertySet &opts)
 Set parameters of this inference algorithm. More...
 
virtual PropertySet getProperties () const
 Returns parameters of this inference algorithm converted into a PropertySet. More...
 
virtual std::string printProperties () const
 Returns parameters of this inference algorithm formatted as a string in the format "[key1=val1,key2=val2,...,keyn=valn]". More...
 
Additional interface specific for LC
Real CalcCavityDist (size_t i, const std::string &name, const PropertySet &opts)
 Approximates the cavity distribution of variable i, using the inference algorithm name with parameters opts. More...
 
Real InitCavityDists (const std::string &name, const PropertySet &opts)
 Approximates all cavity distributions using inference algorithm name with parameters opts. More...
 
long SetCavityDists (std::vector< Factor > &Q)
 Sets approximate cavity distributions to Q. More...
 
Factor NewPancake (size_t i, size_t _I, bool &hasNaNs)
 Updates the belief of the Markov blanket of variable i based upon the information from its _I 'th neighboring factor. More...
 
void CalcBelief (size_t i)
 Calculates the belief of variable i. More...
 
const Factorpancake (size_t i) const
 Returns the belief of the Markov blanket of variable i (including the variable itself) More...
 
const Factorcavitydist (size_t i) const
 Returns the approximate cavity distribution for variable i. More...
 
- Public Member Functions inherited from dai::DAIAlg< GRM >
 DAIAlg ()
 Default constructor. More...
 
 DAIAlg (const GRM &grm)
 Construct from GRM. More...
 
FactorGraphfg ()
 Returns reference to underlying FactorGraph. More...
 
const FactorGraphfg () const
 Returns constant reference to underlying FactorGraph. More...
 
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}$) More...
 
void makeCavity (size_t i, bool backup=false)
 Sets all factors interacting with variable with index i to one. More...
 
void makeRegionCavity (std::vector< size_t > facInds, bool backup)
 Sets all factors indicated by facInds to one. More...
 
void backupFactor (size_t I)
 Make a backup copy of factor I. More...
 
void backupFactors (const VarSet &vs)
 Make backup copies of all factors involving the variables in vs. More...
 
void restoreFactor (size_t I)
 Restore factor I from its backup copy. More...
 
void restoreFactors (const VarSet &vs)
 Restore the factors involving the variables in vs from their backup copies. More...
 
void restoreFactors ()
 Restore all factors from their backup copies. More...
 
- Public Member Functions inherited from dai::InfAlg
virtual ~InfAlg ()
 Virtual destructor (needed because this class contains virtual functions) More...
 
virtual std::string identify () const
 Identifies itself for logging purposes. 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< size_t > findMaximum () const
 Calculates the joint state of all variables that has maximum probability. More...
 

Public Attributes

struct dai::LC::Properties props
 

Private Attributes

std::vector< Factor_pancakes
 Stores for each variable the approximate cavity distribution multiplied with the omitted factors. More...
 
std::vector< Factor_cavitydists
 Stores for each variable the approximate cavity distribution. More...
 
std::vector< std::vector< Factor > > _phis
 _phis[i][_I] corresponds to $ \phi^{\setminus i}_I(x_{I \setminus i}) $ in the paper More...
 
std::vector< Factor_beliefs
 Single variable beliefs. More...
 
Real _maxdiff
 Maximum difference encountered so far. More...
 
size_t _iters
 Number of iterations needed. More...
 

Detailed Description

Approximate inference algorithm "Loop Corrected Belief Propagation" [MoK07].

Constructor & Destructor Documentation

dai::LC::LC ( )
inline

Default constructor.

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

Construct from FactorGraph fg and PropertySet opts.

Parameters
fgFactor graph.
optsParameters
See also
Properties

Member Function Documentation

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

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

Implements dai::InfAlg.

virtual LC* dai::LC::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::LC::name ( ) const
inlinevirtual

Returns the name of the algorithm.

Implements dai::InfAlg.

virtual Factor dai::LC::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::LC::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.

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

virtual std::vector<Factor> dai::LC::beliefs ( ) const
inlinevirtual

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::LC::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.

void dai::LC::init ( )
virtual

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.

virtual void dai::LC::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::LC::run ( )
virtual

Runs the approximate inference algorithm.

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

Implements dai::InfAlg.

virtual Real dai::LC::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::LC::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.

virtual void dai::LC::setMaxIter ( size_t  )
inlinevirtual

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

Exceptions
NOT_IMPLEMENTEDif not implemented/supported

Reimplemented from dai::InfAlg.

void dai::LC::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::LC::getProperties ( ) const
virtual

Returns parameters of this inference algorithm converted into a PropertySet.

Implements dai::InfAlg.

string dai::LC::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.

Real dai::LC::CalcCavityDist ( size_t  i,
const std::string &  name,
const PropertySet opts 
)

Approximates the cavity distribution of variable i, using the inference algorithm name with parameters opts.

Real dai::LC::InitCavityDists ( const std::string &  name,
const PropertySet opts 
)

Approximates all cavity distributions using inference algorithm name with parameters opts.

long dai::LC::SetCavityDists ( std::vector< Factor > &  Q)

Sets approximate cavity distributions to Q.

Factor dai::LC::NewPancake ( size_t  i,
size_t  _I,
bool &  hasNaNs 
)

Updates the belief of the Markov blanket of variable i based upon the information from its _I 'th neighboring factor.

void dai::LC::CalcBelief ( size_t  i)

Calculates the belief of variable i.

const Factor& dai::LC::pancake ( size_t  i) const
inline

Returns the belief of the Markov blanket of variable i (including the variable itself)

const Factor& dai::LC::cavitydist ( size_t  i) const
inline

Returns the approximate cavity distribution for variable i.

Member Data Documentation

std::vector<Factor> dai::LC::_pancakes
private

Stores for each variable the approximate cavity distribution multiplied with the omitted factors.

std::vector<Factor> dai::LC::_cavitydists
private

Stores for each variable the approximate cavity distribution.

std::vector<std::vector<Factor> > dai::LC::_phis
private

_phis[i][_I] corresponds to $ \phi^{\setminus i}_I(x_{I \setminus i}) $ in the paper

std::vector<Factor> dai::LC::_beliefs
private

Single variable beliefs.

Real dai::LC::_maxdiff
private

Maximum difference encountered so far.

size_t dai::LC::_iters
private

Number of iterations needed.


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