dai::JTree Class Reference

Exact inference algorithm using junction tree. More...

#include <dai/jtree.h>

Inheritance diagram for dai::JTree:

dai::DAIAlg< GRM > dai::InfAlg dai::TreeEP

List of all members.

Public Member Functions

Constructors/destructors
 JTree ()
 Default constructor.
 JTree (const FactorGraph &fg, const PropertySet &opts, bool automatic=true)
 Construct from FactorGraph fg and PropertySet opts.
General InfAlg interface
virtual JTreeclone () 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 VarSet &vs) const
 Returns the (approximate) marginal probability distribution of a set of variables.
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
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 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 JTree
void construct (const FactorGraph &fg, const std::vector< VarSet > &cl, bool verify=false)
 Constructs a junction tree based on the cliques cl (corresponding to some elimination sequence).
void GenerateJT (const FactorGraph &fg, const std::vector< VarSet > &cl)
 Constructs a junction tree based on the cliques cl (corresponding to some elimination sequence).
const Factormessage (size_t alpha, size_t _beta) const
 Returns constant reference to the message from outer region alpha to its _beta 'th neighboring inner region.
Factormessage (size_t alpha, size_t _beta)
 Returns reference to the message from outer region alpha to its _beta 'th neighboring inner region.
void runHUGIN ()
 Runs junction tree algorithm using HUGIN (message-free) updates.
void runShaferShenoy ()
 Runs junction tree algorithm using Shafer-Shenoy updates.
size_t findEfficientTree (const VarSet &vs, RootedTree &Tree, size_t PreviousRoot=(size_t)-1) const
 Finds an efficient subtree for calculating the marginal of the variables in vs.
Factor calcMarginal (const VarSet &vs)
 Calculates the marginal of a set of variables (using cutset conditioning, if necessary).

Public Attributes

RootedTree RTree
 The junction tree (stored as a rooted tree).
std::vector< FactorQa
 Outer region beliefs.
std::vector< FactorQb
 Inner region beliefs.
struct dai::JTree::Properties props

Static Public Attributes

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

Private Attributes

std::vector< std::vector
< Factor > > 
_mes
 Stores the messages.
Real _logZ
 Stores the logarithm of the partition sum.

Related Functions

(Note that these are not member functions.)

std::pair< size_t, long double > boundTreewidth (const FactorGraph &fg, greedyVariableElimination::eliminationCostFunction fn, size_t maxStates=0)
 Calculates upper bound to the treewidth of a FactorGraph, using the specified heuristic.

Classes

struct  Properties
 Parameters for JTree. More...


Detailed Description

Exact inference algorithm using junction tree.

The junction tree algorithm uses message passing on a junction tree to calculate exact marginal probability distributions ("beliefs") for specified cliques (outer regions) and separators (intersections of pairs of cliques).

There are two variants, the sum-product algorithm (corresponding to finite temperature) and the max-product algorithm (corresponding to zero temperature).

Examples:

example.cpp.


Constructor & Destructor Documentation

dai::JTree::JTree (  )  [inline]

Default constructor.

dai::JTree::JTree ( const FactorGraph fg,
const PropertySet opts,
bool  automatic = true 
)

Construct from FactorGraph fg and PropertySet opts.

Parameters:
fg factor graph
opts Parameters
See also:
Properties
Parameters:
automatic if true, construct the junction tree automatically, using the heuristic in opts['heuristic'].


Member Function Documentation

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

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

Implements dai::InfAlg.

Reimplemented in dai::TreeEP.

string dai::JTree::identify (  )  const [virtual]

Identifies itself for logging purposes.

Implements dai::InfAlg.

Reimplemented in dai::TreeEP.

Factor dai::JTree::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.

Examples:
example.cpp.

vector< Factor > dai::JTree::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.

Real dai::JTree::logZ (  )  const [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.

Reimplemented in dai::TreeEP.

Examples:
example.cpp.

std::vector< size_t > dai::JTree::findMaximum (  )  const [virtual]

Precondition:
Assumes that run() has been called and that props.inference == MAXPROD

Reimplemented from dai::InfAlg.

Examples:
example.cpp.

virtual void dai::JTree::init (  )  [inline, 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.

Reimplemented in dai::TreeEP.

Examples:
example.cpp.

virtual void dai::JTree::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.

Reimplemented in dai::TreeEP.

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

Runs the approximate inference algorithm.

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

Implements dai::InfAlg.

Reimplemented in dai::TreeEP.

Examples:
example.cpp.

virtual Real dai::JTree::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.

Reimplemented in dai::TreeEP.

virtual size_t dai::JTree::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.

Reimplemented in dai::TreeEP.

void dai::JTree::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.

Reimplemented in dai::TreeEP.

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

Returns parameters of this inference algorithm converted into a PropertySet.

Implements dai::InfAlg.

Reimplemented in dai::TreeEP.

string dai::JTree::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.

Reimplemented in dai::TreeEP.

void dai::JTree::construct ( const FactorGraph fg,
const std::vector< VarSet > &  cl,
bool  verify = false 
)

Constructs a junction tree based on the cliques cl (corresponding to some elimination sequence).

First, constructs a weighted graph, where the nodes are the elements of cl, and each edge is weighted with the cardinality of the intersection of the state spaces of the nodes. Then, a maximal spanning tree for this weighted graph is calculated. Subsequently, a corresponding region graph is built:

  • the outer regions correspond with the cliques and have counting number 1;
  • the inner regions correspond with the seperators, i.e., the intersections of two cliques that are neighbors in the spanning tree, and have counting number -1 (except empty ones, which have counting number 0);
  • inner and outer regions are connected by an edge if the inner region is a seperator for the outer region. Finally, Beliefs are constructed. If verify == true, checks whether each factor is subsumed by a clique.

void dai::JTree::GenerateJT ( const FactorGraph fg,
const std::vector< VarSet > &  cl 
)

Constructs a junction tree based on the cliques cl (corresponding to some elimination sequence).

Invokes construct() and then constructs messages.

See also:
construct()

const Factor& dai::JTree::message ( size_t  alpha,
size_t  _beta 
) const [inline]

Returns constant reference to the message from outer region alpha to its _beta 'th neighboring inner region.

Factor& dai::JTree::message ( size_t  alpha,
size_t  _beta 
) [inline]

Returns reference to the message from outer region alpha to its _beta 'th neighboring inner region.

void dai::JTree::runHUGIN (  ) 

Runs junction tree algorithm using HUGIN (message-free) updates.

Note:
The initial messages may be arbitrary; actually they are not used at all.

void dai::JTree::runShaferShenoy (  ) 

Runs junction tree algorithm using Shafer-Shenoy updates.

Note:
The initial messages may be arbitrary.

size_t dai::JTree::findEfficientTree ( const VarSet vs,
RootedTree Tree,
size_t  PreviousRoot = (size_t)-1 
) const

Finds an efficient subtree for calculating the marginal of the variables in vs.

First, the current junction tree is reordered such that it gets as root the clique that has maximal state space overlap with vs. Then, the minimal subtree (starting from the root) is identified that contains all the variables in vs and also the outer region with index PreviousRoot (if specified). Finally, the current junction tree is reordered such that this minimal subtree comes before the other edges, and the size of the minimal subtree is returned.

Factor dai::JTree::calcMarginal ( const VarSet vs  ) 

Calculates the marginal of a set of variables (using cutset conditioning, if necessary).

Precondition:
assumes that run() has been called already


Friends And Related Function Documentation

std::pair< size_t, long double > boundTreewidth ( const FactorGraph fg,
greedyVariableElimination::eliminationCostFunction  fn,
size_t  maxStates = 0 
) [related]

Calculates upper bound to the treewidth of a FactorGraph, using the specified heuristic.

Parameters:
fg the factor graph for which the treewidth should be bounded
fn the heuristic cost function used for greedy variable elimination
maxStates maximum total number of states in outer regions of junction tree (0 means no limit)
Exceptions:
OUT_OF_MEMORY if the total number of states becomes larger than maxStates
Returns:
a pair (number of variables in largest clique, number of states in largest clique)


Member Data Documentation

std::vector<std::vector<Factor> > dai::JTree::_mes [private]

Stores the messages.

Stores the logarithm of the partition sum.

The junction tree (stored as a rooted tree).

std::vector<Factor> dai::JTree::Qa

Outer region beliefs.

std::vector<Factor> dai::JTree::Qb

Inner region beliefs.

const char * dai::JTree::Name = "JTREE" [static]

Name of this inference algorithm.

Reimplemented in dai::TreeEP.


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

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