libDAI
|
Implements BBP (Back-Belief-Propagation) [EaG09]. More...
#include <dai/bbp.h>
Classes | |
struct | Properties |
Parameters for BBP. More... | |
Public Member Functions | |
Constructors/destructors | |
BBP (const InfAlg *ia, const PropertySet &opts) | |
Construct BBP object from a InfAlg ia and a PropertySet opts. More... | |
Initialization | |
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, adj_psi_F. More... | |
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) More... | |
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 adjoints to zero) More... | |
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 adjoints to zero) More... | |
void | initCostFnAdj (const BBPCostFunction &cfn, const std::vector< size_t > *stateP) |
Initializes with adjoints calculated from cost function cfn, and state stateP. More... | |
BBP Algorithm | |
void | run () |
Perform iterative updates until change is less than given tolerance. More... | |
Query results | |
Prob & | adj_psi_V (size_t i) |
Returns reference to variable factor adjoint. More... | |
const Prob & | adj_psi_V (size_t i) const |
Returns constant reference to variable factor adjoint. More... | |
Prob & | adj_psi_F (size_t I) |
Returns reference to factor adjoint. More... | |
const Prob & | adj_psi_F (size_t I) const |
Returns constant reference to factor adjoint. More... | |
Prob & | adj_b_V (size_t i) |
Returns reference to variable belief adjoint. More... | |
const Prob & | adj_b_V (size_t i) const |
Returns constant reference to variable belief adjoint. More... | |
Prob & | adj_b_F (size_t I) |
Returns reference to factor belief adjoint. More... | |
const Prob & | adj_b_F (size_t I) const |
Returns constant reference to factor belief adjoint. More... | |
size_t | Iterations () |
Return number of iterations done so far. More... | |
Public Attributes | |
struct dai::BBP::Properties | props |
Private Member Functions | |
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 normalized probability vector. More... | |
Real | getUnMsgMag () |
Calculates averaged L1 norm of unnormalized message adjoints. More... | |
void | getMsgMags (Real &s, Real &new_s) |
Calculates averaged L1 norms of current and new normalized message adjoints. More... | |
void | getArgmaxMsgM (size_t &i, size_t &_I, Real &mag) |
Returns indices and magnitude of the largest normalized factor->variable message adjoint. More... | |
Real | getMaxMsgM () |
Returns magnitude of the largest (in L1-norm) normalized factor->variable message adjoint. More... | |
Real | getTotalMsgM () |
Calculates sum of L1 norms of all normalized factor->variable message adjoints. More... | |
Real | getTotalNewMsgM () |
Calculates sum of L1 norms of all updated normalized factor->variable message adjoints. More... | |
Real | getTotalMsgN () |
Calculates sum of L1 norms of all normalized variable->factor message adjoints. More... | |
std::vector< Prob > | getZeroAdjF (const FactorGraph &fg) |
Returns a vector of Probs (filled with zeroes) with state spaces corresponding to the factors in the factor graph fg. More... | |
std::vector< Prob > | getZeroAdjV (const FactorGraph &fg) |
Returns a vector of Probs (filled with zeroes) with state spaces corresponding to the variables in the factor graph fg. More... | |
Initialization helper functions | |
void | RegenerateT () |
Calculate T values; see eqn. (41) in [EaG09]. More... | |
void | RegenerateU () |
Calculate U values; see eqn. (42) in [EaG09]. More... | |
void | RegenerateS () |
Calculate S values; see eqn. (43) in [EaG09]. More... | |
void | RegenerateR () |
Calculate R values; see eqn. (44) in [EaG09]. More... | |
void | RegenerateInputs () |
Calculate _adj_b_V_unnorm and _adj_b_F_unnorm from _adj_b_V and _adj_b_F. More... | |
void | RegeneratePsiAdjoints () |
Initialise members for factor adjoints. More... | |
void | RegenerateParMessageAdjoints () |
Initialise members for message adjoints for parallel algorithm. More... | |
void | RegenerateSeqMessageAdjoints () |
Initialise members for message adjoints for sequential algorithm. More... | |
void | Regenerate () |
Called by init, recalculates intermediate values. More... | |
Accessors/mutators | |
Prob & | T (size_t i, size_t _I) |
Returns reference to T value; see eqn. (41) in [EaG09]. More... | |
const Prob & | T (size_t i, size_t _I) const |
Returns constant reference to T value; see eqn. (41) in [EaG09]. More... | |
Prob & | U (size_t I, size_t _i) |
Returns reference to U value; see eqn. (42) in [EaG09]. More... | |
const Prob & | U (size_t I, size_t _i) const |
Returns constant reference to U value; see eqn. (42) in [EaG09]. More... | |
Prob & | S (size_t i, size_t _I, size_t _j) |
Returns reference to S value; see eqn. (43) in [EaG09]. More... | |
const Prob & | S (size_t i, size_t _I, size_t _j) const |
Returns constant reference to S value; see eqn. (43) in [EaG09]. More... | |
Prob & | R (size_t I, size_t _i, size_t _J) |
Returns reference to R value; see eqn. (44) in [EaG09]. More... | |
const Prob & | R (size_t I, size_t _i, size_t _J) const |
Returns constant reference to R value; see eqn. (44) in [EaG09]. More... | |
Prob & | adj_n (size_t i, size_t _I) |
Returns reference to variable->factor message adjoint. More... | |
const Prob & | adj_n (size_t i, size_t _I) const |
Returns constant reference to variable->factor message adjoint. More... | |
Prob & | adj_m (size_t i, size_t _I) |
Returns reference to factor->variable message adjoint. More... | |
const Prob & | adj_m (size_t i, size_t _I) const |
Returns constant reference to factor->variable message adjoint. More... | |
Parallel algorithm | |
void | calcNewN (size_t i, size_t _I) |
Calculates new variable->factor message adjoint. More... | |
void | calcNewM (size_t i, size_t _I) |
Calculates new factor->variable message adjoint. More... | |
void | calcUnnormMsgN (size_t i, size_t _I) |
Calculates unnormalized variable->factor message adjoint from the normalized one. More... | |
void | calcUnnormMsgM (size_t i, size_t _I) |
Calculates unnormalized factor->variable message adjoint from the normalized one. More... | |
void | upMsgN (size_t i, size_t _I) |
Updates (un)normalized variable->factor message adjoints. More... | |
void | upMsgM (size_t i, size_t _I) |
Updates (un)normalized factor->variable message adjoints. More... | |
void | doParUpdate () |
Do one parallel update of all message adjoints. More... | |
Sequential algorithm | |
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 corresponding unnormalized adjoint. More... | |
void | setSeqMsgM (size_t i, size_t _I, const Prob &p) |
Sets normalized factor->variable message adjoint and calculates the corresponding unnormalized adjoint. More... | |
void | sendSeqMsgN (size_t i, size_t _I, const Prob &f) |
Implements routine Send-n in Figure 5 in [EaG09]. More... | |
void | sendSeqMsgM (size_t i, size_t _I) |
Implements routine Send-m in Figure 5 in [EaG09]. More... | |
Private Attributes | |
Input variables | |
BP_dual | _bp_dual |
Stores a BP_dual helper object. More... | |
const FactorGraph * | _fg |
Pointer to the factor graph. More... | |
const InfAlg * | _ia |
Pointer to the approximate inference algorithm (currently, only BP objects are supported) More... | |
Output variables | |
std::vector< Prob > | _adj_psi_V |
Variable factor adjoints. More... | |
std::vector< Prob > | _adj_psi_F |
Factor adjoints. More... | |
std::vector< std::vector< Prob > > | _adj_n |
Variable->factor message adjoints (indexed [i][_I]) More... | |
std::vector< std::vector< Prob > > | _adj_m |
Factor->variable message adjoints (indexed [i][_I]) More... | |
std::vector< Prob > | _adj_b_V |
Normalized variable belief adjoints. More... | |
std::vector< Prob > | _adj_b_F |
Normalized factor belief adjoints. More... | |
Internal state variables | |
std::vector< Prob > | _init_adj_psi_V |
Initial variable factor adjoints. More... | |
std::vector< Prob > | _init_adj_psi_F |
Initial factor adjoints. More... | |
std::vector< std::vector< Prob > > | _adj_n_unnorm |
Unnormalized variable->factor message adjoint (indexed [i][_I]) More... | |
std::vector< std::vector< Prob > > | _adj_m_unnorm |
Unnormalized factor->variable message adjoint (indexed [i][_I]) More... | |
std::vector< std::vector< Prob > > | _new_adj_n |
Updated normalized variable->factor message adjoint (indexed [i][_I]) More... | |
std::vector< std::vector< Prob > > | _new_adj_m |
Updated normalized factor->variable message adjoint (indexed [i][_I]) More... | |
std::vector< Prob > | _adj_b_V_unnorm |
Unnormalized variable belief adjoints. More... | |
std::vector< Prob > | _adj_b_F_unnorm |
Unnormalized factor belief adjoints. More... | |
std::vector< std::vector< Prob > > | _Tmsg |
_Tmsg[i]_I in [EaG09]) More... | |
std::vector< std::vector< Prob > > | _Umsg |
_Umsg[I]_i in [EaG09]) More... | |
std::vector< std::vector< std::vector< Prob > > > | _Smsg |
_Smsg[i][_I]_j in [EaG09]) More... | |
std::vector< std::vector< std::vector< Prob > > > | _Rmsg |
_Rmsg[I][_i]_J in [EaG09]) More... | |
size_t | _iters |
Number of iterations done. More... | |
Related Functions | |
(Note that these are not member functions.) | |
Real | numericBBPTest (const InfAlg &bp, const std::vector< size_t > *state, const PropertySet &bbp_props, const BBPCostFunction &cfn, Real h) |
Function to verify the validity of adjoints computed by BBP using numerical differentiation. More... | |
Index cache management (for performance) | |
typedef std::vector< size_t > | _ind_t |
Index type. More... | |
std::vector< std::vector< _ind_t > > | _indices |
Cached indices (indexed [i][_I]) More... | |
void | RegenerateInds () |
Prepares index cache _indices. More... | |
const _ind_t & | _index (size_t i, size_t _I) const |
Returns an index from the cache. More... | |
|
private |
Index type.
|
inline |
Construct BBP object from a InfAlg ia and a PropertySet opts.
ia | should be a BP object or something compatible |
opts | Parameters |
|
private |
Prepares index cache _indices.
|
inlineprivate |
Returns an index from the cache.
|
private |
Calculate T values; see eqn. (41) in [EaG09].
|
private |
Calculate U values; see eqn. (42) in [EaG09].
|
private |
Calculate S values; see eqn. (43) in [EaG09].
|
private |
Calculate R values; see eqn. (44) in [EaG09].
|
private |
Calculate _adj_b_V_unnorm and _adj_b_F_unnorm from _adj_b_V and _adj_b_F.
|
private |
Initialise members for factor adjoints.
|
private |
Initialise members for message adjoints for parallel algorithm.
|
private |
Initialise members for message adjoints for sequential algorithm.
Same as RegenerateMessageAdjoints, but calls sendSeqMsgN rather than updating _adj_n (and friends) which are unused in the sequential algorithm.
|
private |
Called by init, recalculates intermediate values.
|
inlineprivate |
Returns reference to T value; see eqn. (41) in [EaG09].
|
inlineprivate |
Returns constant reference to T value; see eqn. (41) in [EaG09].
|
inlineprivate |
Returns reference to U value; see eqn. (42) in [EaG09].
|
inlineprivate |
Returns constant reference to U value; see eqn. (42) in [EaG09].
|
inlineprivate |
Returns reference to S value; see eqn. (43) in [EaG09].
|
inlineprivate |
Returns constant reference to S value; see eqn. (43) in [EaG09].
|
inlineprivate |
Returns reference to R value; see eqn. (44) in [EaG09].
|
inlineprivate |
Returns constant reference to R value; see eqn. (44) in [EaG09].
|
inlineprivate |
Returns reference to variable->factor message adjoint.
|
inlineprivate |
Returns constant reference to variable->factor message adjoint.
|
inlineprivate |
Returns reference to factor->variable message adjoint.
|
inlineprivate |
Returns constant reference to factor->variable message adjoint.
|
private |
|
private |
|
private |
Calculates unnormalized variable->factor message adjoint from the normalized one.
|
private |
Calculates unnormalized factor->variable message adjoint from the normalized one.
|
private |
Updates (un)normalized variable->factor message adjoints.
|
private |
Updates (un)normalized factor->variable message adjoints.
|
private |
Do one parallel update of all message adjoints.
|
private |
Helper function for sendSeqMsgM(): increases factor->variable message adjoint by p and calculates the corresponding unnormalized adjoint.
|
private |
Sets normalized factor->variable message adjoint and calculates the corresponding unnormalized adjoint.
|
private |
Implements routine Send-n in Figure 5 in [EaG09].
|
private |
Implements routine Send-m in Figure 5 in [EaG09].
Computes the adjoint of the unnormed probability vector from the normalizer and the adjoint of the normalized probability vector.
|
private |
Calculates averaged L1 norm of unnormalized message adjoints.
Calculates averaged L1 norms of current and new normalized message adjoints.
|
private |
Returns indices and magnitude of the largest normalized factor->variable message adjoint.
|
private |
Returns magnitude of the largest (in L1-norm) normalized factor->variable message adjoint.
|
private |
Calculates sum of L1 norms of all normalized factor->variable message adjoints.
|
private |
Calculates sum of L1 norms of all updated normalized factor->variable message adjoints.
|
private |
Calculates sum of L1 norms of all normalized variable->factor message adjoints.
|
private |
Returns a vector of Probs (filled with zeroes) with state spaces corresponding to the factors in the factor graph fg.
|
private |
Returns a vector of Probs (filled with zeroes) with state spaces corresponding to the variables in the factor graph fg.
|
inline |
Initializes from given belief adjoints adj_b_V, adj_b_F and initial factor adjoints adj_psi_V, adj_psi_F.
|
inline |
Initializes from given belief adjoints adj_b_V and adj_b_F (setting initial factor adjoints to zero)
|
inline |
Initializes variable belief adjoints adj_b_V (and sets factor belief adjoints and initial factor adjoints to zero)
|
inline |
Initializes factor belief adjoints adj_b_F (and sets variable belief adjoints and initial factor adjoints to zero)
void dai::BBP::initCostFnAdj | ( | const BBPCostFunction & | cfn, |
const std::vector< size_t > * | stateP | ||
) |
Initializes with adjoints calculated from cost function cfn, and state stateP.
Uses the internal pointer to an inference algorithm in combination with the cost function and state for initialization.
cfn | Cost function used for initialization; |
stateP | is a Gibbs state and can be NULL; it will be initialised using a Gibbs run. |
void dai::BBP::run | ( | ) |
Perform iterative updates until change is less than given tolerance.
|
inline |
Returns reference to variable factor adjoint.
|
inline |
Returns constant reference to variable factor adjoint.
|
inline |
Returns reference to factor adjoint.
|
inline |
Returns constant reference to factor adjoint.
|
inline |
Returns reference to variable belief adjoint.
|
inline |
Returns constant reference to variable belief adjoint.
|
inline |
Returns reference to factor belief adjoint.
|
inline |
Returns constant reference to factor belief adjoint.
|
inline |
Return number of iterations done so far.
|
related |
Function to verify the validity of adjoints computed by BBP using numerical differentiation.
Factors containing a variable are multiplied by small adjustments to verify accuracy of calculated variable factor adjoints.
|
private |
Pointer to the factor graph.
|
private |
Pointer to the approximate inference algorithm (currently, only BP objects are supported)
|
private |
Variable factor adjoints.
|
private |
Factor adjoints.
|
private |
Variable->factor message adjoints (indexed [i][_I])
|
private |
Factor->variable message adjoints (indexed [i][_I])
|
private |
Normalized variable belief adjoints.
|
private |
Normalized factor belief adjoints.
|
private |
Initial variable factor adjoints.
|
private |
Initial factor adjoints.
|
private |
Unnormalized variable->factor message adjoint (indexed [i][_I])
|
private |
Unnormalized factor->variable message adjoint (indexed [i][_I])
|
private |
Updated normalized variable->factor message adjoint (indexed [i][_I])
|
private |
Updated normalized factor->variable message adjoint (indexed [i][_I])
|
private |
Unnormalized variable belief adjoints.
|
private |
Unnormalized factor belief adjoints.
|
private |
Number of iterations done.
|
private |
Cached indices (indexed [i][_I])