13 #ifndef __defined_libdai_cbp_h
14 #define __defined_libdai_cbp_h
22 #include <boost/shared_ptr.hpp>
66 CBP() :
DAIAlgFG(), _beliefsV(), _beliefsF(), _logZ(0.0), _iters(0), _maxdiff(0.0), _sum_level(0.0), _num_leaves(0), _clamp_ofstream() {}
81 virtual std::string
name()
const {
return "CBP"; }
86 virtual std::vector<Factor>
beliefs()
const {
return concat(_beliefsV, _beliefsF); }
152 DAI_ENUM(RecurseType,REC_FIXED,REC_LOGZ,REC_BDIFF);
154 DAI_ENUM(ChooseMethodType,CHOOSE_RANDOM,CHOOSE_MAXENT,CHOOSE_BBP,CHOOSE_BP_L1,CHOOSE_BP_CFN);
156 DAI_ENUM(ClampType,CLAMP_VAR,CLAMP_FACTOR);
207 void runRecurse(
InfAlg *bp,
Real orig_logZ, std::vector<size_t> clamped_vars_list,
size_t &num_leaves,
208 size_t &choose_count,
Real &sum_level,
Real &lz_out, std::vector<Factor> &beliefs_out );
218 virtual bool chooseNextClampVar(
InfAlg* bp, std::vector<size_t> &clamped_vars_list,
size_t &i, std::vector<size_t> &xis,
Real *maxVarOut );
Defines class BBP, which implements Back-Belief-Propagation.
DAI_ENUM(RecurseType, REC_FIXED, REC_LOGZ, REC_BDIFF)
Enumeration of possible methods for deciding when to stop recursing.
virtual bool chooseNextClampVar(InfAlg *bp, std::vector< size_t > &clamped_vars_list, size_t &i, std::vector< size_t > &xis, Real *maxVarOut)
Choose the next variable to clamp.
Definition: cbp.cpp:281
CBP(const FactorGraph &fg, const PropertySet &opts)
Construct CBP object from FactorGraph fg and PropertySet opts.
Definition: cbp.h:72
boost::shared_ptr< std::ofstream > _clamp_ofstream
Output stream where information about the clampings is written.
Definition: cbp.h:61
size_t _num_leaves
Number of leaves of recursion tree.
Definition: cbp.h:58
BP::Properties::UpdateType UpdateType
Enumeration of possible update schedules.
Definition: cbp.h:150
Parameters for CBP.
Definition: cbp.h:148
virtual CBP * construct(const FactorGraph &fg, const PropertySet &opts) const
Returns a pointer to a newly constructed inference algorithm.
Definition: cbp.h:80
Real _sum_level
Number of clampings at each leaf node.
Definition: cbp.h:56
Class for CBP (Conditioned Belief Propagation) [EaG09].
Definition: cbp.h:41
virtual Factor belief(const VarSet &) const
Returns the (approximate) marginal probability distribution of a set of variables.
Definition: cbp.h:83
Represents a factor graph.
Definition: factorgraph.h:65
Real _maxdiff
Maximum difference encountered so far.
Definition: cbp.h:53
std::string clamp_outfile
If non-empty, write clamping choices to this file.
Definition: cbp.h:184
virtual size_t Iterations() const
Returns number of iterations done (one iteration passes over the complete factorgraph).
Definition: cbp.h:92
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
Real min_max_adj
If choose==CHOOSE_BBP and maximum adjoint is less than this value, don't recurse. ...
Definition: cbp.h:170
virtual void setProperties(const PropertySet &opts)
Set parameters of this inference algorithm.
Definition: cbp.h:94
Real _logZ
Logarithm of partition sum.
Definition: cbp.h:48
virtual void init()
Initializes all data structures of the approximate inference algorithm.
Definition: cbp.h:88
UpdateType updates
Update style for BP.
Definition: cbp.h:162
virtual Factor beliefV(size_t i) const
Returns the (approximate) marginal probability distribution of the variable with index i...
Definition: cbp.h:84
BBPCostFunction bbp_cfn
Cost function to use for BBP.
Definition: cbp.h:180
size_t rand_seed
Random seed.
Definition: cbp.h:182
std::vector< Factor > _beliefsF
Factor beliefs.
Definition: cbp.h:46
Real tol
Tolerance for BP convergence test.
Definition: cbp.h:160
Represents a set of variables.
Definition: varset.h:94
virtual Real run()
Runs the approximate inference algorithm.
Definition: cbp.cpp:131
void runRecurse(InfAlg *bp, Real orig_logZ, std::vector< size_t > clamped_vars_list, size_t &num_leaves, size_t &choose_count, Real &sum_level, Real &lz_out, std::vector< Factor > &beliefs_out)
Called by run(), and by itself. Implements the main algorithm.
Definition: cbp.cpp:168
size_t verbose
Verbosity (amount of output sent to stderr)
Definition: cbp.h:158
virtual Real logZ() const
Returns the logarithm of the (approximated) partition sum (normalizing constant of the factor graph)...
Definition: cbp.h:87
virtual Real maxDiff() const
Returns maximum difference between single variable beliefs in the last iteration. ...
Definition: cbp.h:91
size_t maxiter
Maximum number of iterations for BP.
Definition: cbp.h:164
virtual PropertySet getProperties() const
Returns parameters of this inference algorithm converted into a PropertySet.
Definition: cbp.h:95
RecurseType recursion
Method for deciding when to stop recursing.
Definition: cbp.h:174
std::string toString() const
Convert to a string which can be parsed as a PropertySet.
Definition: cbp.cpp:616
ClampType clamp
Whether to clamp variables or factors.
Definition: cbp.h:176
virtual Factor belief(const Var &v) const
Returns the (approximate) marginal probability distribution of a variable.
Definition: cbp.h:82
PropertySet bbp_props
Properties to pass to BBP.
Definition: cbp.h:178
Real rec_tol
Tolerance used for controlling recursion depth (recurse is REC_LOGZ or REC_BDIFF) ...
Definition: cbp.h:166
std::vector< Factor > _beliefsV
Variable beliefs.
Definition: cbp.h:44
std::vector< T > concat(const std::vector< T > &u, const std::vector< T > &v)
Concatenates two vectors.
Definition: util.h:231
void printDebugInfo()
Prints beliefs, variables and partition sum, in case of a debugging build.
Definition: cbp.cpp:447
InfAlg is an abstract base class, defining the common interface of all inference algorithms in libDAI...
Definition: daialg.h:35
void setBeliefs(const std::vector< Factor > &bs, Real logZ)
Sets variable beliefs, factor beliefs and log partition sum to the specified values.
Definition: cbp.cpp:76
Represents a set of properties, mapping keys (of type PropertyKey) to values (of type PropertyValue) ...
Definition: properties.h:73
virtual std::vector< Factor > beliefs() const
Returns all beliefs (approximate marginal probability distributions) calculated by the algorithm...
Definition: cbp.h:86
size_t max_levels
Maximum number of levels of recursion (recurse is REC_FIXED)
Definition: cbp.h:168
virtual void setMaxIter(size_t maxiter)
Sets maximum number of iterations (one iteration passes over the complete factorgraph).
Definition: cbp.h:93
Represents a discrete random variable.
Definition: var.h:37
Namespace for libDAI.
Definition: alldai.cpp:16
size_t _iters
Numer of iterations needed.
Definition: cbp.h:51
ChooseMethodType choose
Heuristic for choosing clamping variable.
Definition: cbp.h:172
Defines the general interface for inference methods in libDAI (classes InfAlg, DaiAlg<>, DaiAlgFG and DaiAlgRG).
virtual Factor beliefF(size_t I) const
Returns the (approximate) marginal probability distribution of the variables on which factor I depend...
Definition: cbp.h:85
virtual std::string name() const
Returns the name of the algorithm.
Definition: cbp.h:81
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: cbp.h:96
Combines the abstract base class InfAlg with a graphical model (e.g., a FactorGraph or RegionGraph)...
Definition: daialg.h:207
InfAlg * getInfAlg()
Return the InfAlg to use at each step of the recursion.
Definition: cbp.cpp:153
CBP()
Default constructor.
Definition: cbp.h:66
virtual CBP * clone() const
Returns a pointer to a new, cloned copy of *this (i.e., virtual copy constructor) ...
Definition: cbp.h:79
PropertySet get() const
Get members into PropertySet.
Definition: cbp.cpp:598
Predefined cost functions that can be used with BBP.
Definition: bbp.h:42
void set(const PropertySet &opts)
Set members from PropertySet.
Definition: cbp.cpp:522
void construct()
Constructor helper function.
Definition: cbp.cpp:90
virtual void init(const VarSet &)
Initializes all data structures corresponding to some set of variables.
Definition: cbp.h:89