14 #ifndef ___defined_libdai_bbp_h
15 #define ___defined_libdai_bbp_h
38 DAI_ENUM(BBPCostFunctionBase,CFN_GIBBS_B,CFN_GIBBS_B2,CFN_GIBBS_EXP,CFN_GIBBS_B_FACTOR,CFN_GIBBS_B2_FACTOR,CFN_GIBBS_EXP_FACTOR,CFN_VAR_ENT,CFN_FACTOR_ENT,CFN_BETHE_ENT);
58 BBPCostFunctionBase::operator=( x );
86 std::vector<std::vector<Prob> >
_adj_n;
88 std::vector<std::vector<Prob> >
_adj_m;
116 std::vector<std::vector<Prob > >
_Tmsg;
118 std::vector<std::vector<Prob > >
_Umsg;
120 std::vector<std::vector<std::vector<Prob > > >
_Smsg;
122 std::vector<std::vector<std::vector<Prob > > >
_Rmsg;
130 typedef std::vector<size_t>
_ind_t;
139 const _ind_t&
_index(
size_t i,
size_t _I)
const {
return _indices[i][_I]; }
174 Prob &
T(
size_t i,
size_t _I) {
return _Tmsg[i][_I]; }
177 const Prob &
T(
size_t i,
size_t _I)
const {
return _Tmsg[i][_I]; }
179 Prob &
U(
size_t I,
size_t _i) {
return _Umsg[I][_i]; }
181 const Prob &
U(
size_t I,
size_t _i)
const {
return _Umsg[I][_i]; }
183 Prob &
S(
size_t i,
size_t _I,
size_t _j) {
return _Smsg[i][_I][_j]; }
185 const Prob &
S(
size_t i,
size_t _I,
size_t _j)
const {
return _Smsg[i][_I][_j]; }
187 Prob &
R(
size_t I,
size_t _i,
size_t _J) {
return _Rmsg[I][_i][_J]; }
189 const Prob &
R(
size_t I,
size_t _i,
size_t _J)
const {
return _Rmsg[I][_i][_J]; }
192 Prob&
adj_n(
size_t i,
size_t _I) {
return _adj_n[i][_I]; }
194 const Prob&
adj_n(
size_t i,
size_t _I)
const {
return _adj_n[i][_I]; }
196 Prob&
adj_m(
size_t i,
size_t _I) {
return _adj_m[i][_I]; }
198 const Prob&
adj_m(
size_t i,
size_t _I)
const {
return _adj_m[i][_I]; }
207 void calcNewN(
size_t i,
size_t _I );
212 void calcNewM(
size_t i,
size_t _I );
218 void upMsgN(
size_t i,
size_t _I );
220 void upMsgM(
size_t i,
size_t _I );
383 DAI_ENUM(UpdateType,SEQ_FIX,SEQ_MAX,SEQ_BP_REV,SEQ_BP_FWD,PAR);
const Prob & R(size_t I, size_t _i, size_t _J) const
Returns constant reference to R value; see eqn. (44) in [EaG09].
Definition: bbp.h:189
std::vector< Prob > _adj_b_F_unnorm
Unnormalized factor belief adjoints.
Definition: bbp.h:113
std::vector< Prob > _adj_psi_F
Factor adjoints.
Definition: bbp.h:84
std::vector< std::vector< _ind_t > > _indices
Cached indices (indexed [i][_I])
Definition: bbp.h:133
Prob & T(size_t i, size_t _I)
Returns reference to T value; see eqn. (41) in [EaG09].
Definition: bbp.h:175
std::vector< std::vector< std::vector< Prob > > > _Smsg
_Smsg[i][_I]_j in [EaG09])
Definition: bbp.h:120
DAI_ENUM(UpdateType, SEQ_FIX, SEQ_MAX, SEQ_BP_REV, SEQ_BP_FWD, PAR)
Enumeration of possible update schedules.
std::vector< Prob > _init_adj_psi_V
Initial variable factor adjoints.
Definition: bbp.h:98
void init_V(const std::vector< Prob > &adj_b_V)
Initializes variable belief adjoints adj_b_V (and sets factor belief adjoints and initial factor adjo...
Definition: bbp.h:294
Real damping
Damping constant (0 for none); damping = 1 - lambda where lambda is the damping constant used in [EaG...
Definition: bbp.h:393
const Prob & adj_b_V(size_t i) const
Returns constant reference to variable belief adjoint.
Definition: bbp.h:330
std::vector< Prob > getZeroAdjV(const FactorGraph &fg)
Returns a vector of Probs (filled with zeroes) with state spaces corresponding to the variables in th...
Definition: bbp.cpp:743
std::string toString() const
Convert to a string which can be parsed as a PropertySet.
Definition: bbp.cpp:1183
void init_F(const std::vector< Prob > &adj_b_F)
Initializes factor belief adjoints adj_b_F (and sets variable belief adjoints and initial factor adjo...
Definition: bbp.h:299
std::vector< std::vector< std::vector< Prob > > > _Rmsg
_Rmsg[I][_i]_J in [EaG09])
Definition: bbp.h:122
void calcNewN(size_t i, size_t _I)
Calculates new variable->factor message adjoint.
Definition: bbp.cpp:405
Prob & adj_psi_F(size_t I)
Returns reference to factor adjoint.
Definition: bbp.h:324
void upMsgM(size_t i, size_t _I)
Updates (un)normalized factor->variable message adjoints.
Definition: bbp.cpp:461
void init(const std::vector< Prob > &adj_b_V, const std::vector< Prob > &adj_b_F)
Initializes from given belief adjoints adj_b_V and adj_b_F (setting initial factor adjoints to zero) ...
Definition: bbp.h:289
std::vector< std::vector< Prob > > _adj_n_unnorm
Unnormalized variable->factor message adjoint (indexed [i][_I])
Definition: bbp.h:103
Implements BBP (Back-Belief-Propagation) [EaG09].
Definition: bbp.h:67
Real getTotalMsgM()
Calculates sum of L1 norms of all normalized factor->variable message adjoints.
Definition: bbp.cpp:707
void set(const PropertySet &opts)
Set members from PropertySet.
Definition: bbp.cpp:1140
bool needGibbsState() const
Returns whether this cost function depends on having a Gibbs state.
Definition: bbp.cpp:40
Represents a factor graph.
Definition: factorgraph.h:65
Prob unnormAdjoint(const Prob &w, Real Z_w, const Prob &adj_w)
Computes the adjoint of the unnormed probability vector from the normalizer and the adjoint of the no...
Definition: bbp.cpp:623
size_t maxiter
Maximum number of iterations.
Definition: bbp.h:387
BBP(const InfAlg *ia, const PropertySet &opts)
Construct BBP object from a InfAlg ia and a PropertySet opts.
Definition: bbp.h:272
std::vector< Prob > _init_adj_psi_F
Initial factor adjoints.
Definition: bbp.h:100
Real getMaxMsgM()
Returns magnitude of the largest (in L1-norm) normalized factor->variable message adjoint...
Definition: bbp.cpp:699
size_t _iters
Number of iterations done.
Definition: bbp.h:125
double Real
Real number (alias for double, which could be changed to long double if necessary) ...
Definition: util.h:98
void init(const std::vector< Prob > &adj_b_V, const std::vector< Prob > &adj_b_F, const std::vector< Prob > &adj_psi_V, const std::vector< Prob > &adj_psi_F)
Initializes from given belief adjoints adj_b_V, adj_b_F and initial factor adjoints adj_psi_V...
Definition: bbp.h:280
BBPCostFunction()
Default constructor.
Definition: bbp.h:45
void initCostFnAdj(const BBPCostFunction &cfn, const std::vector< size_t > *stateP)
Initializes with adjoints calculated from cost function cfn, and state stateP.
Definition: bbp.cpp:752
Defines TProb<> and Prob classes which represent (probability) vectors (e.g., probability distributio...
void RegenerateSeqMessageAdjoints()
Initialise members for message adjoints for sequential algorithm.
Definition: bbp.cpp:344
void getArgmaxMsgM(size_t &i, size_t &_I, Real &mag)
Returns indices and magnitude of the largest normalized factor->variable message adjoint.
Definition: bbp.cpp:683
UpdateType updates
Update schedule.
Definition: bbp.h:395
size_t Iterations()
Return number of iterations done so far.
Definition: bbp.h:336
void RegenerateT()
Calculate T values; see eqn. (41) in [EaG09].
Definition: bbp.cpp:167
void doParUpdate()
Do one parallel update of all message adjoints.
Definition: bbp.cpp:467
Calculates both types of BP messages and their normalizers from an InfAlg.
Definition: bp_dual.h:39
const Prob & adj_m(size_t i, size_t _I) const
Returns constant reference to factor->variable message adjoint.
Definition: bbp.h:198
void RegenerateR()
Calculate R values; see eqn. (44) in [EaG09].
Definition: bbp.cpp:232
Real getUnMsgMag()
Calculates averaged L1 norm of unnormalized message adjoints.
Definition: bbp.cpp:636
void calcNewM(size_t i, size_t _I)
Calculates new factor->variable message adjoint.
Definition: bbp.cpp:426
std::vector< std::vector< Prob > > _new_adj_m
Updated normalized factor->variable message adjoint (indexed [i][_I])
Definition: bbp.h:109
const InfAlg * _ia
Pointer to the approximate inference algorithm (currently, only BP objects are supported) ...
Definition: bbp.h:76
Defines the DAI_ENUM macro, which can be used to define an enum with additional functionality.
void sendSeqMsgM(size_t i, size_t _I)
Implements routine Send-m in Figure 5 in [EaG09].
Definition: bbp.cpp:558
std::vector< std::vector< Prob > > _adj_n
Variable->factor message adjoints (indexed [i][_I])
Definition: bbp.h:86
void incrSeqMsgM(size_t i, size_t _I, const Prob &p)
Helper function for sendSeqMsgM(): increases factor->variable message adjoint by p and calculates the...
Definition: bbp.cpp:481
std::vector< std::vector< Prob > > _adj_m
Factor->variable message adjoints (indexed [i][_I])
Definition: bbp.h:88
BBPCostFunction & operator=(const BBPCostFunctionBase &x)
Assignment operator.
Definition: bbp.h:57
std::vector< std::vector< Prob > > _new_adj_n
Updated normalized variable->factor message adjoint (indexed [i][_I])
Definition: bbp.h:107
size_t verbose
Verbosity (amount of output sent to stderr)
Definition: bbp.h:385
Real getTotalNewMsgM()
Calculates sum of L1 norms of all updated normalized factor->variable message adjoints.
Definition: bbp.cpp:716
void RegenerateParMessageAdjoints()
Initialise members for message adjoints for parallel algorithm.
Definition: bbp.cpp:294
void RegenerateS()
Calculate S values; see eqn. (43) in [EaG09].
Definition: bbp.cpp:204
void Regenerate()
Called by init, recalculates intermediate values.
Definition: bbp.cpp:389
Prob & S(size_t i, size_t _I, size_t _j)
Returns reference to S value; see eqn. (43) in [EaG09].
Definition: bbp.h:183
Prob & adj_b_F(size_t I)
Returns reference to factor belief adjoint.
Definition: bbp.h:332
Prob & adj_n(size_t i, size_t _I)
Returns reference to variable->factor message adjoint.
Definition: bbp.h:192
void RegeneratePsiAdjoints()
Initialise members for factor adjoints.
Definition: bbp.cpp:265
void setSeqMsgM(size_t i, size_t _I, const Prob &p)
Sets normalized factor->variable message adjoint and calculates the corresponding unnormalized adjoin...
Definition: bbp.cpp:517
std::vector< std::vector< Prob > > _Umsg
_Umsg[I]_i in [EaG09])
Definition: bbp.h:118
void RegenerateU()
Calculate U values; see eqn. (42) in [EaG09].
Definition: bbp.cpp:183
std::vector< Prob > _adj_psi_V
Variable factor adjoints.
Definition: bbp.h:82
DAI_ENUM(LDPCType, SMALL, GROUP, RANDOM)
Possible LDPC structures.
void upMsgN(size_t i, size_t _I)
Updates (un)normalized variable->factor message adjoints.
Definition: bbp.cpp:455
const _ind_t & _index(size_t i, size_t _I) const
Returns an index from the cache.
Definition: bbp.h:139
std::vector< Prob > _adj_b_F
Normalized factor belief adjoints.
Definition: bbp.h:92
Prob & U(size_t I, size_t _i)
Returns reference to U value; see eqn. (42) in [EaG09].
Definition: bbp.h:179
InfAlg is an abstract base class, defining the common interface of all inference algorithms in libDAI...
Definition: daialg.h:35
const Prob & U(size_t I, size_t _i) const
Returns constant reference to U value; see eqn. (42) in [EaG09].
Definition: bbp.h:181
Prob & adj_b_V(size_t i)
Returns reference to variable belief adjoint.
Definition: bbp.h:328
Parameters for BBP.
Definition: bbp.h:374
const Prob & S(size_t i, size_t _I, size_t _j) const
Returns constant reference to S value; see eqn. (43) in [EaG09].
Definition: bbp.h:185
std::vector< Prob > _adj_b_V_unnorm
Unnormalized variable belief adjoints.
Definition: bbp.h:111
std::vector< std::vector< Prob > > _adj_m_unnorm
Unnormalized factor->variable message adjoint (indexed [i][_I])
Definition: bbp.h:105
BBPCostFunction(const BBPCostFunctionBase &x)
Construct from BBPCostFunctionBase x.
Definition: bbp.h:48
void calcUnnormMsgN(size_t i, size_t _I)
Calculates unnormalized variable->factor message adjoint from the normalized one. ...
Definition: bbp.cpp:445
Represents a set of properties, mapping keys (of type PropertyKey) to values (of type PropertyValue) ...
Definition: properties.h:73
void RegenerateInputs()
Calculate _adj_b_V_unnorm and _adj_b_F_unnorm from _adj_b_V and _adj_b_F.
Definition: bbp.cpp:253
void RegenerateInds()
Prepares index cache _indices.
Definition: bbp.cpp:148
std::vector< std::vector< Prob > > _Tmsg
_Tmsg[i]_I in [EaG09])
Definition: bbp.h:116
std::vector< Prob > getZeroAdjF(const FactorGraph &fg)
Returns a vector of Probs (filled with zeroes) with state spaces corresponding to the factors in the ...
Definition: bbp.cpp:734
Namespace for libDAI.
Definition: alldai.cpp:16
Real getTotalMsgN()
Calculates sum of L1 norms of all normalized variable->factor message adjoints.
Definition: bbp.cpp:725
void run()
Perform iterative updates until change is less than given tolerance.
Definition: bbp.cpp:903
const Prob & adj_b_F(size_t I) const
Returns constant reference to factor belief adjoint.
Definition: bbp.h:334
Prob & adj_m(size_t i, size_t _I)
Returns reference to factor->variable message adjoint.
Definition: bbp.h:196
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).
void calcUnnormMsgM(size_t i, size_t _I)
Calculates unnormalized factor->variable message adjoint from the normalized one. ...
Definition: bbp.cpp:450
Allows the user to specify which algorithms will be built into libDAI.
const Prob & T(size_t i, size_t _I) const
Returns constant reference to T value; see eqn. (41) in [EaG09].
Definition: bbp.h:177
Prob & adj_psi_V(size_t i)
Returns reference to variable factor adjoint.
Definition: bbp.h:320
std::vector< size_t > _ind_t
Index type.
Definition: bbp.h:131
std::vector< Prob > _adj_b_V
Normalized variable belief adjoints.
Definition: bbp.h:90
void getMsgMags(Real &s, Real &new_s)
Calculates averaged L1 norms of current and new normalized message adjoints.
Definition: bbp.cpp:649
Real evaluate(const InfAlg &ia, const std::vector< size_t > *stateP) const
Evaluates cost function in state stateP using the information in inference algorithm ia...
Definition: bbp.cpp:55
const Prob & adj_n(size_t i, size_t _I) const
Returns constant reference to variable->factor message adjoint.
Definition: bbp.h:194
Real tol
Tolerance for convergence test.
Definition: bbp.h:391
BP_dual _bp_dual
Stores a BP_dual helper object.
Definition: bbp.h:72
Prob & R(size_t I, size_t _i, size_t _J)
Returns reference to R value; see eqn. (44) in [EaG09].
Definition: bbp.h:187
void sendSeqMsgN(size_t i, size_t _I, const Prob &f)
Implements routine Send-n in Figure 5 in [EaG09].
Definition: bbp.cpp:523
Predefined cost functions that can be used with BBP.
Definition: bbp.h:42
const FactorGraph * _fg
Pointer to the factor graph.
Definition: bbp.h:74
const Prob & adj_psi_V(size_t i) const
Returns constant reference to variable factor adjoint.
Definition: bbp.h:322
const Prob & adj_psi_F(size_t I) const
Returns constant reference to factor adjoint.
Definition: bbp.h:326
Defines class BP_dual, which is used primarily by BBP.