libDAI
List of all members
dai::DAIAlg< GRM > Class Template Reference

Combines the abstract base class InfAlg with a graphical model (e.g., a FactorGraph or RegionGraph). More...

#include <dai/daialg.h>

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

Public Member Functions

Constructors/destructors
 DAIAlg ()
 Default constructor. More...
 
 DAIAlg (const GRM &grm)
 Construct from GRM. More...
 
Queries
FactorGraphfg ()
 Returns reference to underlying FactorGraph. More...
 
const FactorGraphfg () const
 Returns constant reference to underlying FactorGraph. More...
 
Changing the factor graph
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...
 
Backup/restore mechanism for factors
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 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...
 
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 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...
 
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

template<class GRM>
class dai::DAIAlg< GRM >

Combines the abstract base class InfAlg with a graphical model (e.g., a FactorGraph or RegionGraph).

Inference algorithms in libDAI directly inherit from a DAIAlg, currently either from a DAIAlg<FactorGraph> or from a DAIAlg<RegionGraph>.

Template Parameters
GRMShould be castable to FactorGraph
Idea:
A DAIAlg should not inherit from a FactorGraph or RegionGraph, but should store a reference to the graphical model object. This prevents needless copying of (possibly large) data structures. Disadvantage: the caller must not change the graphical model between calls to the inference algorithm (maybe a smart_ptr or some locking mechanism would help here?).

Constructor & Destructor Documentation

template<class GRM >
dai::DAIAlg< GRM >::DAIAlg ( )
inline

Default constructor.

template<class GRM >
dai::DAIAlg< GRM >::DAIAlg ( const GRM &  grm)
inline

Construct from GRM.

Member Function Documentation

template<class GRM >
FactorGraph& dai::DAIAlg< GRM >::fg ( )
inlinevirtual

Returns reference to underlying FactorGraph.

Implements dai::InfAlg.

template<class GRM >
const FactorGraph& dai::DAIAlg< GRM >::fg ( ) const
inlinevirtual

Returns constant reference to underlying FactorGraph.

Implements dai::InfAlg.

template<class GRM >
void dai::DAIAlg< GRM >::clamp ( size_t  i,
size_t  x,
bool  backup = false 
)
inlinevirtual

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.

Implements dai::InfAlg.

template<class GRM >
void dai::DAIAlg< GRM >::makeCavity ( size_t  i,
bool  backup = false 
)
inlinevirtual

Sets all factors interacting with variable with index i to one.

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

Implements dai::InfAlg.

template<class GRM >
void dai::DAIAlg< GRM >::makeRegionCavity ( std::vector< size_t >  facInds,
bool  backup 
)
inlinevirtual

Sets all factors indicated by facInds to one.

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

Implements dai::InfAlg.

template<class GRM >
void dai::DAIAlg< GRM >::backupFactor ( size_t  I)
inlinevirtual

Make a backup copy of factor I.

Implements dai::InfAlg.

template<class GRM >
void dai::DAIAlg< GRM >::backupFactors ( const VarSet vs)
inlinevirtual

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

Implements dai::InfAlg.

template<class GRM >
void dai::DAIAlg< GRM >::restoreFactor ( size_t  I)
inlinevirtual

Restore factor I from its backup copy.

Implements dai::InfAlg.

template<class GRM >
void dai::DAIAlg< GRM >::restoreFactors ( const VarSet vs)
inlinevirtual

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

Implements dai::InfAlg.

template<class GRM >
void dai::DAIAlg< GRM >::restoreFactors ( )
inline

Restore all factors from their backup copies.


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