libDAI
|
Approximate inference algorithm "Tree-Reweighted Belief Propagation" [WJW03]. More...
#include <dai/trwbp.h>
Public Member Functions | |
Constructors/destructors | |
TRWBP () | |
Default constructor. | |
TRWBP (const FactorGraph &fg, const PropertySet &opts) | |
Construct from FactorGraph fg and PropertySet opts. | |
General InfAlg interface | |
virtual TRWBP * | clone () const |
Returns a pointer to a new, cloned copy of *this (i.e., virtual copy constructor) | |
virtual TRWBP * | construct (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 Real | logZ () const |
Returns the logarithm of the (approximated) partition sum (normalizing constant of the factor graph). | |
virtual void | setProperties (const PropertySet &opts) |
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]". | |
![]() | |
BP () | |
Default constructor. | |
BP (const FactorGraph &fg, const PropertySet &opts) | |
Construct from FactorGraph fg and PropertySet opts. | |
BP (const BP &x) | |
Copy constructor. | |
BP & | operator= (const BP &x) |
Assignment operator. | |
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 Factor | beliefF (size_t I) const |
Returns the (approximate) marginal probability distribution of the variables on which factor I depends. | |
virtual std::vector< Factor > | beliefs () const |
Returns all beliefs (approximate marginal probability distributions) calculated by the algorithm. | |
std::vector< std::size_t > | findMaximum () const |
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). | |
const std::vector< std::pair < std::size_t, std::size_t > > & | getSentMessages () const |
Returns history of which messages have been updated. | |
void | clearSentMessages () |
Clears history of which messages have been updated. | |
![]() | |
DAIAlg () | |
Default constructor. | |
DAIAlg (const GRM &grm) | |
Construct from GRM. | |
FactorGraph & | fg () |
Returns reference to underlying FactorGraph. | |
const FactorGraph & | fg () 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 ![]() | |
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. | |
![]() | |
virtual | ~InfAlg () |
Virtual destructor (needed because this class contains virtual functions) | |
virtual std::string | identify () const |
Identifies itself for logging purposes. |
Public Attributes | |
size_t | nrtrees |
Size of sample of trees used to set the weights. | |
![]() | |
struct dai::BP::Properties | props |
bool | recordSentMessages |
Specifies whether the history of message updates should be recorded. |
Protected Attributes | |
std::vector< Real > | _weight |
"Edge weights" (indexed by factor ID) | |
![]() | |
std::vector< std::vector < EdgeProp > > | _edges |
Stores all edge properties. | |
std::vector< std::vector < LutType::iterator > > | _edge2lut |
Lookup table (only used for maximum-residual BP) | |
LutType | _lut |
Lookup table (only used for maximum-residual BP) | |
Real | _maxdiff |
Maximum difference between variable beliefs encountered so far. | |
size_t | _iters |
Number of iterations needed. | |
std::vector< std::pair < std::size_t, std::size_t > > | _sentMessages |
The history of message updates (only recorded if recordSentMessages is true ) | |
std::vector< Factor > | _oldBeliefsV |
Stores variable beliefs of previous iteration. | |
std::vector< Factor > | _oldBeliefsF |
Stores factor beliefs of previous iteration. | |
std::vector< Edge > | _updateSeq |
Stores the update schedule. |
TRWBP accessors/mutators for scale parameters | |
Real | Weight (size_t I) const |
Returns weight corresponding to the I 'th factor. | |
const std::vector< Real > & | Weights () const |
Returns constant reference to vector of all weights. | |
void | setWeight (size_t I, Real c) |
Sets the weight of the I 'th factor to c. | |
void | setWeights (const std::vector< Real > &c) |
Sets the weights of all factors simultaenously. | |
void | addTreeToWeights (const RootedTree &tree) |
Increases weights corresponding to pairwise factors in tree with 1. | |
void | sampleWeights (size_t nrTrees) |
Samples weights from a sample of nrTrees random spanning trees. | |
virtual Prob | calcIncomingMessageProduct (size_t I, bool without_i, size_t i) const |
Calculate the product of factor I and the incoming messages. | |
virtual void | calcBeliefV (size_t i, Prob &p) const |
Calculates unnormalized belief of variable i. | |
virtual void | calcBeliefF (size_t I, Prob &p) const |
Calculates unnormalized belief of factor I. | |
virtual void | construct () |
Helper function for constructors. |
Additional Inherited Members | |
![]() | |
typedef std::vector< size_t > | ind_t |
Type used for index cache. | |
typedef std::multimap< Real, std::pair< std::size_t, std::size_t > > | LutType |
Type of lookup table (only used for maximum-residual BP) | |
![]() | |
const Prob & | message (size_t i, size_t _I) const |
Returns constant reference to message from the _I 'th neighbor of variable i to variable i. | |
Prob & | message (size_t i, size_t _I) |
Returns reference to message from the _I 'th neighbor of variable i to variable i. | |
const Prob & | newMessage (size_t i, size_t _I) const |
Returns constant reference to updated message from the _I 'th neighbor of variable i to variable i. | |
Prob & | newMessage (size_t i, size_t _I) |
Returns reference to updated message from the _I 'th neighbor of variable i to variable i. | |
const ind_t & | index (size_t i, size_t _I) const |
Returns constant reference to cached index for the edge between variable i and its _I 'th neighbor. | |
ind_t & | index (size_t i, size_t _I) |
Returns reference to cached index for the edge between variable i and its _I 'th neighbor. | |
const Real & | residual (size_t i, size_t _I) const |
Returns constant reference to residual for the edge between variable i and its _I 'th neighbor. | |
Real & | residual (size_t i, size_t _I) |
Returns reference to residual for the edge between variable i and its _I 'th neighbor. | |
virtual void | calcNewMessage (size_t i, size_t _I) |
Calculate the updated message from the _I 'th neighbor of variable i to variable i. | |
void | updateMessage (size_t i, size_t _I) |
Replace the "old" message from the _I 'th neighbor of variable i to variable i by the "new" (updated) message. | |
void | updateResidual (size_t i, size_t _I, Real r) |
Set the residual (difference between new and old message) for the edge between variable i and its _I 'th neighbor to r. | |
void | findMaxResidual (size_t &i, size_t &_I) |
Finds the edge which has the maximum residual (difference between new and old message) |
Approximate inference algorithm "Tree-Reweighted Belief Propagation" [WJW03].
The Tree-Reweighted Belief Propagation algorithm is like Belief Propagation, but associates each factor with a scale parameter. which controls the divergence measure being minimized.
The messages are passed from factors
to variables
. The update equation is given by:
After convergence, the variable beliefs are calculated by:
and the factor beliefs are calculated by:
The logarithm of the partition sum is approximated by:
where the variable weights are defined as
|
inline |
Default constructor.
|
inline |
Construct from FactorGraph fg and PropertySet opts.
There is an additional property "nrtrees" which allows to specify the number of random spanning trees used to set the scale parameters.
fg | Factor graph. |
opts | Parameters |
|
inlinevirtual |
Returns a pointer to a new, cloned copy of *this
(i.e., virtual copy constructor)
Reimplemented from dai::BP.
|
inlinevirtual |
Returns a pointer to a newly constructed inference algorithm.
fg | Factor graph on which to perform the inference algorithm; |
opts | Parameters passed to constructor of inference algorithm; |
Reimplemented from dai::BP.
|
inlinevirtual |
Returns the name of the algorithm.
Reimplemented from dai::BP.
|
virtual |
|
virtual |
|
virtual |
Returns parameters of this inference algorithm converted into a PropertySet.
Reimplemented from dai::BP.
|
virtual |
Returns parameters of this inference algorithm formatted as a string in the format "[key1=val1,key2=val2,...,keyn=valn]".
Reimplemented from dai::BP.
|
inline |
Returns weight corresponding to the I 'th factor.
|
inline |
Returns constant reference to vector of all weights.
|
inline |
Sets the weight of the I 'th factor to c.
|
inline |
Sets the weights of all factors simultaenously.
void dai::TRWBP::addTreeToWeights | ( | const RootedTree & | tree | ) |
Increases weights corresponding to pairwise factors in tree with 1.
void dai::TRWBP::sampleWeights | ( | size_t | nrTrees | ) |
Samples weights from a sample of nrTrees random spanning trees.
|
protectedvirtual |
Calculate the product of factor I and the incoming messages.
If without_i == true
, the message coming from variable i is omitted from the product
Reimplemented from dai::BP.
|
protectedvirtual |
Calculates unnormalized belief of variable i.
Reimplemented from dai::BP.
|
inlineprotectedvirtual |
Calculates unnormalized belief of factor I.
Reimplemented from dai::BP.
|
protectedvirtual |
Helper function for constructors.
Reimplemented from dai::BP.
|
protected |
size_t dai::TRWBP::nrtrees |
Size of sample of trees used to set the weights.