13 #ifndef __defined_libdai_mr_h
14 #define __defined_libdai_mr_h
29 #include <boost/dynamic_bitset.hpp>
47 std::vector<std::vector<Real> >
tJ;
52 std::vector<std::vector<Real> >
M;
54 std::vector<std::vector<std::vector<Real> > >
cors;
57 typedef boost::dynamic_bitset<>
sub_nb;
60 std::vector<Real>
Mag;
84 DAI_ENUM(InitType,RESPPROP,CLAMPING,EXACT);
101 MR() :
DAIAlgFG(), supported(), G(), tJ(), theta(), M(), cors(), Mag(), _maxdiff(), _iters(), props() {}
116 virtual std::string
name()
const {
return "MR"; }
120 virtual std::vector<Factor>
beliefs()
const;
121 virtual Real logZ()
const { DAI_THROW(NOT_IMPLEMENTED);
return 0.0; }
123 virtual void init(
const VarSet & ) { DAI_THROW(NOT_IMPLEMENTED); }
149 Real Omega(
size_t i,
size_t _j,
size_t _l);
155 Real T(
size_t i, sub_nb A);
158 Real T(
size_t i,
size_t _j);
161 Real Gamma(
size_t i,
size_t _j,
size_t _l1,
size_t _l2);
164 Real Gamma(
size_t i,
size_t _l1,
size_t _l2);
virtual MR * construct(const FactorGraph &fg, const PropertySet &opts) const
Returns a pointer to a newly constructed inference algorithm.
Definition: mr.h:115
DAI_ENUM(UpdateType, FULL, LINEAR)
Enumeration of different types of update equations.
virtual Real maxDiff() const
Returns maximum difference between single variable beliefs in the last iteration. ...
Definition: mr.h:125
void calcMagnetizations()
Calculate magnetizations.
Definition: mr.cpp:249
std::vector< std::vector< Real > > M
M[i][_j] is .
Definition: mr.h:52
Real calcCavityCorrelations()
Initialize cors.
Definition: mr.cpp:276
virtual MR * clone() const
Returns a pointer to a new, cloned copy of *this (i.e., virtual copy constructor) ...
Definition: mr.h:114
size_t verbose
Verbosity (amount of output sent to stderr)
Definition: mr.h:87
Represents a factor graph.
Definition: factorgraph.h:65
virtual void init()
Initializes all data structures of the approximate inference algorithm.
Definition: mr.h:122
InitType inits
How to initialize the cavity correlations.
Definition: mr.h:96
FactorGraph & fg()
Returns reference to underlying FactorGraph.
Definition: daialg.h:221
std::vector< std::vector< std::vector< Real > > > cors
Cavity correlations.
Definition: mr.h:54
virtual PropertySet getProperties() const
Returns parameters of this inference algorithm converted into a PropertySet.
Definition: mr.cpp:45
Real tol
Tolerance for convergence test.
Definition: mr.h:90
Real Omega(size_t i, size_t _j, size_t _l)
Calculate as defined in [MoR05] eqn. (2.15)
Definition: mr.cpp:86
double Real
Real number (alias for double, which could be changed to long double if necessary) ...
Definition: util.h:98
boost::dynamic_bitset sub_nb
Type used for managing a subset of neighbors.
Definition: mr.h:57
Real Gamma(size_t i, size_t _j, size_t _l1, size_t _l2)
Calculates as defined in [MoR05] eqn. (2.16)
Definition: mr.cpp:95
void sum_subs(size_t j, sub_nb A, Real *sum_even, Real *sum_odd)
Calculate sum over all even/odd subsets B of A of _tJ(j,B) appM(j,B)
Definition: mr.cpp:146
std::vector< Real > theta
theta[i] is the local field on spin i
Definition: mr.h:49
Real _maxdiff
Maximum difference encountered so far.
Definition: mr.h:63
Defines the DAI_ENUM macro, which can be used to define an enum with additional functionality.
virtual std::string printProperties() const
Returns parameters of this inference algorithm formatted as a string in the format "[key1=val1...
Definition: mr.cpp:55
virtual void setProperties(const PropertySet &opts)
Set parameters of this inference algorithm.
Definition: mr.cpp:30
Represents a set of variables.
Definition: varset.h:94
UpdateType updates
Update equations.
Definition: mr.h:93
MR()
Default constructor.
Definition: mr.h:101
virtual size_t Iterations() const
Returns number of iterations done (one iteration passes over the complete factorgraph).
Definition: mr.h:126
Defines the Exception class and macros for throwing exceptions and doing assertions.
virtual Real run()
Runs the approximate inference algorithm.
Definition: mr.cpp:346
virtual Real logZ() const
Returns the logarithm of the (approximated) partition sum (normalizing constant of the factor graph)...
Definition: mr.h:121
virtual void init(const VarSet &)
Initializes all data structures corresponding to some set of variables.
Definition: mr.h:123
bool supported
Is the underlying factor graph supported?
Definition: mr.h:41
Real appM(size_t i, sub_nb A)
Approximates moments of variables in A.
Definition: mr.cpp:127
Defines the Property and PropertySet classes, which are mainly used for managing parameters of infere...
GraphAL G
The interaction graph (Markov graph)
Definition: mr.h:44
Defines the GraphAL class, which represents an undirected graph as an adjacency list.
size_t _iters
Number of iterations needed.
Definition: mr.h:66
virtual std::string name() const
Returns the name of the algorithm.
Definition: mr.h:116
Represents a set of properties, mapping keys (of type PropertyKey) to values (of type PropertyValue) ...
Definition: properties.h:73
Real T(size_t i, sub_nb A)
Calculate as defined in [MoR05] eqn. (2.17) with .
Definition: mr.cpp:66
virtual std::vector< Factor > beliefs() const
Returns all beliefs (approximate marginal probability distributions) calculated by the algorithm...
Definition: mr.cpp:397
void propagateCavityFields()
Iterate update equations for cavity fields.
Definition: mr.cpp:172
Represents a discrete random variable.
Definition: var.h:37
Namespace for libDAI.
Definition: alldai.cpp:16
Parameters for MR.
Definition: mr.h:70
Defines the FactorGraph class, which represents factor graphs (e.g., Bayesian networks or Markov rand...
std::vector< Real > Mag
Magnetizations.
Definition: mr.h:60
Defines the general interface for inference methods in libDAI (classes InfAlg, DaiAlg<>, DaiAlgFG and DaiAlgRG).
virtual Factor beliefV(size_t i) const
Returns the (approximate) marginal probability distribution of the variable with index i...
Definition: mr.cpp:373
Allows the user to specify which algorithms will be built into libDAI.
virtual Factor belief(const Var &v) const
Returns the (approximate) marginal probability distribution of a variable.
Definition: mr.h:117
Represents the neighborhood structure of nodes in an undirected graph.
Definition: graph.h:114
Combines the abstract base class InfAlg with a graphical model (e.g., a FactorGraph or RegionGraph)...
Definition: daialg.h:207
std::vector< std::vector< Real > > tJ
tJ[i][_j] is the hyperbolic tangent of the interaction between spin i and its neighbour G...
Definition: mr.h:47
Real _tJ(size_t i, sub_nb A)
Calculate the product of all tJ[i][_j] for _j in A.
Definition: mr.cpp:118
Approximate inference algorithm by Montanari and Rizzo [MoR05].
Definition: mr.h:38