13 #ifndef __defined_libdai_trwbp_h
14 #define __defined_libdai_trwbp_h
92 virtual std::string
name()
const {
return "TRWBP"; }
101 Real Weight(
size_t I )
const {
return _weight[I]; }
113 void setWeights(
const std::vector<Real> &c ) { _weight = c; }
Approximate inference algorithm "Tree-Reweighted Belief Propagation" [WJW03].
Definition: trwbp.h:52
void addTreeToWeights(const RootedTree &tree)
Increases weights corresponding to pairwise factors in tree with 1.
Definition: trwbp.cpp:151
virtual TRWBP * clone() const
Returns a pointer to a new, cloned copy of *this (i.e., virtual copy constructor) ...
Definition: trwbp.h:90
virtual Prob calcIncomingMessageProduct(size_t I, bool without_i, size_t i) const
Calculate the product of factor I and the incoming messages.
Definition: trwbp.cpp:71
Defines class BP, which implements (Loopy) Belief Propagation.
std::vector< Real > _weight
"Edge weights" (indexed by factor ID)
Definition: trwbp.h:60
void sampleWeights(size_t nrTrees)
Samples weights from a sample of nrTrees random spanning trees.
Definition: trwbp.cpp:160
virtual TRWBP * construct(const FactorGraph &fg, const PropertySet &opts) const
Returns a pointer to a newly constructed inference algorithm.
Definition: trwbp.h:91
virtual std::string name() const
Returns the name of the algorithm.
Definition: trwbp.h:92
Represents a factor graph.
Definition: factorgraph.h:65
FactorGraph & fg()
Returns reference to underlying FactorGraph.
Definition: daialg.h:221
double Real
Real number (alias for double, which could be changed to long double if necessary) ...
Definition: util.h:98
TRWBP(const FactorGraph &fg, const PropertySet &opts)
Construct from FactorGraph fg and PropertySet opts.
Definition: trwbp.h:82
virtual void setProperties(const PropertySet &opts)
Definition: trwbp.cpp:25
virtual void calcBeliefV(size_t i, Prob &p) const
Calculates unnormalized belief of variable i.
Definition: trwbp.cpp:130
Defines the DAI_ENUM macro, which can be used to define an enum with additional functionality.
virtual Real logZ() const
Returns the logarithm of the (approximated) partition sum (normalizing constant of the factor graph)...
Definition: trwbp.cpp:53
size_t nrtrees
Size of sample of trees used to set the weights.
Definition: trwbp.h:68
void setWeights(const std::vector< Real > &c)
Sets the weights of all factors simultaenously.
Definition: trwbp.h:113
Defines the Property and PropertySet classes, which are mainly used for managing parameters of infere...
Approximate inference algorithm "(Loopy) Belief Propagation".
Definition: bp.h:63
void setWeight(size_t I, Real c)
Sets the weight of the I 'th factor to c.
Definition: trwbp.h:108
Represents a rooted tree, implemented as a vector of directed edges.
Definition: weightedgraph.h:157
Represents a set of properties, mapping keys (of type PropertyKey) to values (of type PropertyValue) ...
Definition: properties.h:73
TRWBP()
Default constructor.
Definition: trwbp.h:74
Namespace for libDAI.
Definition: alldai.cpp:16
Defines the FactorGraph class, which represents factor graphs (e.g., Bayesian networks or Markov rand...
Defines the general interface for inference methods in libDAI (classes InfAlg, DaiAlg<>, DaiAlgFG and DaiAlgRG).
Allows the user to specify which algorithms will be built into libDAI.
virtual std::string printProperties() const
Returns parameters of this inference algorithm formatted as a string in the format "[key1=val1...
Definition: trwbp.cpp:42
Real Weight(size_t I) const
Returns weight corresponding to the I 'th factor.
Definition: trwbp.h:102
virtual void construct()
Helper function for constructors.
Definition: trwbp.cpp:142
const std::vector< Real > & Weights() const
Returns constant reference to vector of all weights.
Definition: trwbp.h:105
virtual void calcBeliefF(size_t I, Prob &p) const
Calculates unnormalized belief of factor I.
Definition: trwbp.h:132
virtual PropertySet getProperties() const
Returns parameters of this inference algorithm converted into a PropertySet.
Definition: trwbp.cpp:35