libDAI
|
Approximate inference algorithm "Gibbs sampling". More...
#include <dai/gibbs.h>
Classes | |
struct | Properties |
Parameters for Gibbs. More... |
Public Member Functions | |
Gibbs () | |
Default constructor. | |
Gibbs (const FactorGraph &fg, const PropertySet &opts) | |
Construct from FactorGraph fg and PropertySet opts. | |
General InfAlg interface | |
virtual Gibbs * | clone () const |
Returns a pointer to a new, cloned copy of *this (i.e., virtual copy constructor) | |
virtual Gibbs * | construct (const FactorGraph &fg, const PropertySet &opts) const |
Returns a pointer to a newly constructed inference algorithm. | |
virtual std::string | name () const |
Returns the name of the algorithm. | |
virtual Factor | belief (const Var &v) const |
Returns the (approximate) marginal probability distribution of a variable. | |
virtual Factor | belief (const VarSet &vs) const |
Returns the (approximate) marginal probability distribution of a set of variables. | |
virtual Factor | beliefV (size_t i) const |
Returns the (approximate) marginal probability distribution of the variable with index i. | |
virtual Factor | beliefF (size_t I) const |
Returns the (approximate) marginal probability distribution of the variables on which factor I depends. | |
virtual std::vector< Factor > | beliefs () const |
Returns all beliefs (approximate marginal probability distributions) calculated by the algorithm. | |
virtual Real | logZ () const |
Returns the logarithm of the (approximated) partition sum (normalizing constant of the factor graph). | |
std::vector< std::size_t > | findMaximum () const |
Calculates the joint state of all variables that has maximum probability. | |
virtual void | init () |
Initializes all data structures of the approximate inference algorithm. | |
virtual void | init (const VarSet &) |
Initializes all data structures corresponding to some set of variables. | |
virtual Real | run () |
Runs the approximate inference algorithm. | |
virtual Real | maxDiff () const |
Returns maximum difference between single variable beliefs in the last iteration. | |
virtual size_t | Iterations () const |
Returns number of iterations done (one iteration passes over the complete factorgraph). | |
virtual void | setMaxIter (size_t maxiter) |
Sets maximum number of iterations (one iteration passes over the complete factorgraph). | |
virtual void | setProperties (const PropertySet &opts) |
Set parameters of this inference algorithm. | |
virtual PropertySet | getProperties () const |
Returns parameters of this inference algorithm converted into a PropertySet. | |
virtual std::string | printProperties () const |
Returns parameters of this inference algorithm formatted as a string in the format "[key1=val1,key2=val2,...,keyn=valn]". | |
Additional interface specific for Gibbs | |
void | randomizeState () |
Draw the current joint state of all variables from a uniform random distribution. | |
std::vector< size_t > & | state () |
Return reference to current state of all variables. | |
const std::vector< size_t > & | state () const |
Return constant reference to current state of all variables. | |
![]() | |
DAIAlg () | |
Default constructor. | |
DAIAlg (const GRM &grm) | |
Construct from GRM. | |
FactorGraph & | fg () |
Returns reference to underlying FactorGraph. | |
const FactorGraph & | fg () const |
Returns constant reference to underlying FactorGraph. | |
void | clamp (size_t i, size_t x, bool backup=false) |
Clamp variable with index i to value x (i.e. multiply with a Kronecker delta ![]() | |
void | makeCavity (size_t i, bool backup=false) |
Sets all factors interacting with variable with index i to one. | |
void | backupFactor (size_t I) |
Make a backup copy of factor I. | |
void | backupFactors (const VarSet &vs) |
Make backup copies of all factors involving the variables in vs. | |
void | restoreFactor (size_t I) |
Restore factor I from its backup copy. | |
void | restoreFactors (const VarSet &vs) |
Restore the factors involving the variables in vs from their backup copies. | |
![]() | |
virtual | ~InfAlg () |
Virtual destructor (needed because this class contains virtual functions) | |
virtual std::string | identify () const |
Identifies itself for logging purposes. |
Public Attributes | |
struct dai::Gibbs::Properties | props |
Private Types | |
typedef std::vector< size_t > | _count_t |
Type used to store the counts of various states. | |
typedef std::vector< size_t > | _state_t |
Type used to store the joint state of all variables. |
Private Member Functions | |
void | construct () |
Helper function for constructors. | |
void | updateCounts () |
Updates all counts (_sample_count, _var_counts, _factor_counts) based on current state. | |
Prob | getVarDist (size_t i) |
Calculate conditional distribution of variable i, given the current state. | |
void | resampleVar (size_t i) |
Draw state of variable i randomly from its conditional distribution and update the current state. | |
size_t | getFactorEntry (size_t I) |
Calculates linear index into factor I corresponding to the current state. | |
size_t | getFactorEntryDiff (size_t I, size_t i) |
Calculates the differences between linear indices into factor I corresponding with a state change of variable i. |
Private Attributes | |
size_t | _sample_count |
Number of samples counted so far (excluding burn-in periods) | |
std::vector< _count_t > | _var_counts |
State counts for each variable. | |
std::vector< _count_t > | _factor_counts |
State counts for each factor. | |
size_t | _iters |
Number of iterations done (including burn-in periods) | |
_state_t | _state |
Current joint state of all variables. | |
_state_t | _max_state |
Joint state with maximum probability seen so far. | |
Real | _max_score |
Highest score so far. |
Related Functions | |
(Note that these are not member functions.) | |
std::vector< size_t > | getGibbsState (const FactorGraph &fg, size_t maxiter) |
Runs Gibbs sampling for maxiter iterations (of which burnin for burn-in) on FactorGraph fg, and returns the resulting state. |
Approximate inference algorithm "Gibbs sampling".
|
private |
Type used to store the counts of various states.
|
private |
Type used to store the joint state of all variables.
|
inline |
Default constructor.
|
inline |
Construct from FactorGraph fg and PropertySet opts.
fg | Factor graph. |
opts | Parameters |
|
inlinevirtual |
Returns a pointer to a new, cloned copy of *this
(i.e., virtual copy constructor)
Implements dai::InfAlg.
|
inlinevirtual |
Returns a pointer to a newly constructed inference algorithm.
fg | Factor graph on which to perform the inference algorithm; |
opts | Parameters passed to constructor of inference algorithm; |
Implements dai::InfAlg.
|
inlinevirtual |
Returns the name of the algorithm.
Implements dai::InfAlg.
Returns the (approximate) marginal probability distribution of a variable.
Reimplemented from dai::InfAlg.
Returns the (approximate) marginal probability distribution of a set of variables.
NOT_IMPLEMENTED | if not implemented/supported. |
BELIEF_NOT_AVAILABLE | if the requested belief cannot be calculated with this algorithm. |
Implements dai::InfAlg.
|
virtual |
Returns the (approximate) marginal probability distribution of the variable with index i.
For some approximate inference algorithms, using beliefV() is preferred to belief() for performance reasons.
Reimplemented from dai::InfAlg.
|
virtual |
Returns the (approximate) marginal probability distribution of the variables on which factor I depends.
For some approximate inference algorithms, using beliefF() is preferred to belief() for performance reasons.
Reimplemented from dai::InfAlg.
|
virtual |
Returns all beliefs (approximate marginal probability distributions) calculated by the algorithm.
Implements dai::InfAlg.
|
inlinevirtual |
Returns the logarithm of the (approximated) partition sum (normalizing constant of the factor graph).
NOT_IMPLEMENTED | if not implemented/supported |
Implements dai::InfAlg.
|
inlinevirtual |
Calculates the joint state of all variables that has maximum probability.
NOT_IMPLEMENTED | if not implemented/supported |
Reimplemented from dai::InfAlg.
|
virtual |
Initializes all data structures of the approximate inference algorithm.
Implements dai::InfAlg.
|
inlinevirtual |
Initializes all data structures corresponding to some set of variables.
This method can be used to do a partial initialization after a part of the factor graph has changed. Instead of initializing all data structures, it only initializes those involving the variables in vs.
NOT_IMPLEMENTED | if not implemented/supported |
Implements dai::InfAlg.
|
virtual |
Runs the approximate inference algorithm.
Implements dai::InfAlg.
|
inlinevirtual |
Returns maximum difference between single variable beliefs in the last iteration.
NOT_IMPLEMENTED | if not implemented/supported |
Reimplemented from dai::InfAlg.
|
inlinevirtual |
Returns number of iterations done (one iteration passes over the complete factorgraph).
NOT_IMPLEMENTED | if not implemented/supported |
Reimplemented from dai::InfAlg.
|
inlinevirtual |
Sets maximum number of iterations (one iteration passes over the complete factorgraph).
NOT_IMPLEMENTED | if not implemented/supported |
Reimplemented from dai::InfAlg.
|
virtual |
Set parameters of this inference algorithm.
The parameters are set according to the PropertySet opts. The values can be stored either as std::string or as the type of the corresponding MF::props member.
Implements dai::InfAlg.
|
virtual |
Returns parameters of this inference algorithm converted into a PropertySet.
Implements dai::InfAlg.
|
virtual |
Returns parameters of this inference algorithm formatted as a string in the format "[key1=val1,key2=val2,...,keyn=valn]".
Implements dai::InfAlg.
void dai::Gibbs::randomizeState | ( | ) |
Draw the current joint state of all variables from a uniform random distribution.
|
inline |
Return reference to current state of all variables.
|
inline |
Return constant reference to current state of all variables.
|
private |
Helper function for constructors.
|
private |
Updates all counts (_sample_count, _var_counts, _factor_counts) based on current state.
|
private |
Calculate conditional distribution of variable i, given the current state.
|
private |
Draw state of variable i randomly from its conditional distribution and update the current state.
|
private |
Calculates linear index into factor I corresponding to the current state.
|
private |
Calculates the differences between linear indices into factor I corresponding with a state change of variable i.
|
related |
Runs Gibbs sampling for maxiter iterations (of which burnin for burn-in) on FactorGraph fg, and returns the resulting state.
|
private |
Number of samples counted so far (excluding burn-in periods)
|
private |
Number of iterations done (including burn-in periods)
|
private |
Current joint state of all variables.
|
private |
Joint state with maximum probability seen so far.
|
private |
Highest score so far.