dai::Gibbs Class Reference

Approximate inference algorithm "Gibbs sampling". More...

#include <dai/gibbs.h>

Inheritance diagram for dai::Gibbs:

dai::DAIAlg< GRM > dai::InfAlg

List of all members.

Public Member Functions

 Gibbs ()
 Default constructor.
 Gibbs (const FactorGraph &fg, const PropertySet &opts)
 Construct from FactorGraph fg and PropertySet opts.
General InfAlg interface
virtual Gibbsclone () const
 Returns a pointer to a new, cloned copy of *this (i.e., virtual copy constructor).
virtual std::string identify () const
 Identifies itself for logging purposes.
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< Factorbeliefs () 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.

Public Attributes

struct dai::Gibbs::Properties props

Static Public Attributes

static const char * Name = "GIBBS"
 Name of this inference algorithm.

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 iters)
 Runs Gibbs sampling for iters iterations (of which burnin for burn-in) on FactorGraph fg, and returns the resulting state.

Classes

struct  Properties
 Parameters for Gibbs. More...


Detailed Description

Approximate inference algorithm "Gibbs sampling".

Author:
Frederik Eaton
Examples:

example_sprinkler_gibbs.cpp.


Member Typedef Documentation

typedef std::vector<size_t> dai::Gibbs::_count_t [private]

Type used to store the counts of various states.

typedef std::vector<size_t> dai::Gibbs::_state_t [private]

Type used to store the joint state of all variables.


Constructor & Destructor Documentation

dai::Gibbs::Gibbs (  )  [inline]

Default constructor.

dai::Gibbs::Gibbs ( const FactorGraph fg,
const PropertySet opts 
) [inline]

Construct from FactorGraph fg and PropertySet opts.

Parameters:
fg Factor graph.
opts Parameters
See also:
Properties


Member Function Documentation

virtual Gibbs* dai::Gibbs::clone (  )  const [inline, virtual]

Returns a pointer to a new, cloned copy of *this (i.e., virtual copy constructor).

Implements dai::InfAlg.

virtual std::string dai::Gibbs::identify (  )  const [inline, virtual]

Identifies itself for logging purposes.

Implements dai::InfAlg.

virtual Factor dai::Gibbs::belief ( const Var v  )  const [inline, virtual]

Returns the (approximate) marginal probability distribution of a variable.

Note:
Before this method is called, run() should have been called.

Reimplemented from dai::InfAlg.

Factor dai::Gibbs::belief ( const VarSet vs  )  const [virtual]

Returns the (approximate) marginal probability distribution of a set of variables.

Note:
Before this method is called, run() should have been called.
Exceptions:
NOT_IMPLEMENTED if not implemented/supported.
BELIEF_NOT_AVAILABLE if the requested belief cannot be calculated with this algorithm.

Implements dai::InfAlg.

Factor dai::Gibbs::beliefV ( size_t  i  )  const [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.

Note:
Before this method is called, run() should have been called.

Reimplemented from dai::InfAlg.

Factor dai::Gibbs::beliefF ( size_t  I  )  const [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.

Note:
Before this method is called, run() should have been called.

Reimplemented from dai::InfAlg.

vector< Factor > dai::Gibbs::beliefs (  )  const [virtual]

Returns all beliefs (approximate marginal probability distributions) calculated by the algorithm.

Note:
Before this method is called, run() should have been called.

Implements dai::InfAlg.

virtual Real dai::Gibbs::logZ (  )  const [inline, virtual]

Returns the logarithm of the (approximated) partition sum (normalizing constant of the factor graph).

Note:
Before this method is called, run() should have been called.
Exceptions:
NOT_IMPLEMENTED if not implemented/supported

Implements dai::InfAlg.

std::vector<std::size_t> dai::Gibbs::findMaximum (  )  const [inline, virtual]

Calculates the joint state of all variables that has maximum probability.

Note:
Before this method is called, run() should have been called.
Exceptions:
NOT_IMPLEMENTED if not implemented/supported

Reimplemented from dai::InfAlg.

void dai::Gibbs::init (  )  [virtual]

Initializes all data structures of the approximate inference algorithm.

Note:
This method should be called at least once before run() is called.

Implements dai::InfAlg.

virtual void dai::Gibbs::init ( const VarSet vs  )  [inline, virtual]

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.

Exceptions:
NOT_IMPLEMENTED if not implemented/supported

Implements dai::InfAlg.

Real dai::Gibbs::run (  )  [virtual]

Runs the approximate inference algorithm.

Note:
Before run() is called the first time, init() should have been called.

Implements dai::InfAlg.

Examples:
example_sprinkler_gibbs.cpp.

virtual Real dai::Gibbs::maxDiff (  )  const [inline, virtual]

Returns maximum difference between single variable beliefs in the last iteration.

Exceptions:
NOT_IMPLEMENTED if not implemented/supported

Reimplemented from dai::InfAlg.

virtual size_t dai::Gibbs::Iterations (  )  const [inline, virtual]

Returns number of iterations done (one iteration passes over the complete factorgraph).

Exceptions:
NOT_IMPLEMENTED if not implemented/supported

Reimplemented from dai::InfAlg.

virtual void dai::Gibbs::setMaxIter ( size_t   )  [inline, virtual]

Sets maximum number of iterations (one iteration passes over the complete factorgraph).

Exceptions:
NOT_IMPLEMENTED if not implemented/supported

Reimplemented from dai::InfAlg.

void dai::Gibbs::setProperties ( const PropertySet opts  )  [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.

PropertySet dai::Gibbs::getProperties (  )  const [virtual]

Returns parameters of this inference algorithm converted into a PropertySet.

Implements dai::InfAlg.

string dai::Gibbs::printProperties (  )  const [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.

std::vector<size_t>& dai::Gibbs::state (  )  [inline]

Return reference to current state of all variables.

Examples:
example_sprinkler_gibbs.cpp.

const std::vector<size_t>& dai::Gibbs::state (  )  const [inline]

Return constant reference to current state of all variables.

void dai::Gibbs::construct (  )  [private]

Helper function for constructors.

void dai::Gibbs::updateCounts (  )  [private]

Updates all counts (_sample_count, _var_counts, _factor_counts) based on current state.

Prob dai::Gibbs::getVarDist ( size_t  i  )  [private]

Calculate conditional distribution of variable i, given the current state.

void dai::Gibbs::resampleVar ( size_t  i  )  [private]

Draw state of variable i randomly from its conditional distribution and update the current state.

size_t dai::Gibbs::getFactorEntry ( size_t  I  )  [private]

Calculates linear index into factor I corresponding to the current state.

size_t dai::Gibbs::getFactorEntryDiff ( size_t  I,
size_t  i 
) [private]

Calculates the differences between linear indices into factor I corresponding with a state change of variable i.


Friends And Related Function Documentation

std::vector< size_t > getGibbsState ( const FactorGraph fg,
size_t  iters 
) [related]

Runs Gibbs sampling for iters iterations (of which burnin for burn-in) on FactorGraph fg, and returns the resulting state.


Member Data Documentation

size_t dai::Gibbs::_sample_count [private]

Number of samples counted so far (excluding burn-in periods).

std::vector<_count_t> dai::Gibbs::_var_counts [private]

State counts for each variable.

std::vector<_count_t> dai::Gibbs::_factor_counts [private]

State counts for each factor.

size_t dai::Gibbs::_iters [private]

Number of iterations done (including burn-in periods).

Current joint state of all variables.

Joint state with maximum probability seen so far.

Highest score so far.

const char * dai::Gibbs::Name = "GIBBS" [static]

Name of this inference algorithm.


The documentation for this class was generated from the following files:

Generated on Thu Aug 5 19:04:06 2010 for libDAI by  doxygen 1.5.5