cc.mallet.grmm.inference
Class AbstractBeliefPropagation

java.lang.Object
  extended by cc.mallet.grmm.inference.AbstractInferencer
      extended by cc.mallet.grmm.inference.AbstractBeliefPropagation
All Implemented Interfaces:
Inferencer, java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
LoopyBP, ResidualBP, TreeBP, TRP

public abstract class AbstractBeliefPropagation
extends AbstractInferencer

Abstract base class for umplementations of belief propagation for general factor graphs. This class manages arrays of messages, computing beliefs from messages, and convergence thresholds.

How to send individual messages (e.g., sum-product, max-product, etc) are mananged by istances of the interface @link{#MessageStrategy}. Concrete subclasses decide which order to send messages in.

Version:
$Id: AbstractBeliefPropagation.java,v 1.1 2007/10/22 21:37:49 mccallum Exp $
Author:
Charles Sutton
See Also:
Serialized Form

Nested Class Summary
static class AbstractBeliefPropagation.AbstractMessageStrategy
           
static class AbstractBeliefPropagation.MaxProductMessageStrategy
           
static interface AbstractBeliefPropagation.MessageStrategy
           
static class AbstractBeliefPropagation.SumProductMessageStrategy
           
 
Field Summary
protected  int[] assignedVertexPtls
           
protected  int iterUsed
           
protected static java.util.logging.Logger logger
           
protected  FactorGraph mdlCurrent
           
protected  boolean normalizeBeliefs
           
protected  boolean useCaching
           
 
Constructor Summary
protected AbstractBeliefPropagation()
           
protected AbstractBeliefPropagation(AbstractBeliefPropagation.MessageStrategy messager)
           
 
Method Summary
protected  void copyOldMessages()
           
protected  void doneWithGraph(FactorGraph mdl)
           
 void dump()
           
 void dump(java.io.PrintWriter writer)
           
 AbstractBeliefPropagation.MessageStrategy getMessager()
           
 int getMessagesSent()
          Returns the total number of messages this inferencer has sent since its creation.
 int getMessagesUsedLastTime()
          Returns the number of messages sent during the last call to computeMarginals.
static int getTotalMessagesSent()
          Returns the total number of messages all BP inferencers have sent in the current Java image.
protected  boolean hasConverged()
           
protected  boolean hasConverged(double threshold)
           
protected  void initForGraph(FactorGraph mdl)
           
 int iterationsUsed()
           
 double lookupLogJoint(Assignment assn)
          Returns the natural logarithm of the joint probability of a given assignment, computed in some factorized fashion.
 Factor lookupMarginal(Variable var)
          Returns the computed marginal of a given variable.
 Factor lookupMarginal(VarSet c)
          Returns the computed marginal of a given clique in a graph.
 void reportTime()
          Outputs some measure of the total time spent in this inferencer.
protected  void resetMessagesSentAtStart()
           
protected  void sendMessage(FactorGraph mdl, Factor from, Variable to)
           
protected  void sendMessage(FactorGraph mdl, Variable from, Factor to)
           
 AbstractBeliefPropagation setMessager(AbstractBeliefPropagation.MessageStrategy messager)
           
 
Methods inherited from class cc.mallet.grmm.inference.AbstractInferencer
computeMarginals, duplicate, lookupJoint, query
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static java.util.logging.Logger logger

normalizeBeliefs

protected boolean normalizeBeliefs

useCaching

protected boolean useCaching

iterUsed

protected transient int iterUsed

mdlCurrent

protected transient FactorGraph mdlCurrent

assignedVertexPtls

protected transient int[] assignedVertexPtls
Constructor Detail

AbstractBeliefPropagation

protected AbstractBeliefPropagation()

AbstractBeliefPropagation

protected AbstractBeliefPropagation(AbstractBeliefPropagation.MessageStrategy messager)
Method Detail

getMessager

public AbstractBeliefPropagation.MessageStrategy getMessager()

setMessager

public AbstractBeliefPropagation setMessager(AbstractBeliefPropagation.MessageStrategy messager)

getTotalMessagesSent

public static int getTotalMessagesSent()
Returns the total number of messages all BP inferencers have sent in the current Java image.


getMessagesSent

public int getMessagesSent()
Returns the total number of messages this inferencer has sent since its creation.


getMessagesUsedLastTime

public int getMessagesUsedLastTime()
Returns the number of messages sent during the last call to computeMarginals.


resetMessagesSentAtStart

protected void resetMessagesSentAtStart()

copyOldMessages

protected final void copyOldMessages()

hasConverged

protected final boolean hasConverged()

hasConverged

protected final boolean hasConverged(double threshold)

initForGraph

protected void initForGraph(FactorGraph mdl)

sendMessage

protected void sendMessage(FactorGraph mdl,
                           Variable from,
                           Factor to)

sendMessage

protected void sendMessage(FactorGraph mdl,
                           Factor from,
                           Variable to)

doneWithGraph

protected void doneWithGraph(FactorGraph mdl)

iterationsUsed

public int iterationsUsed()

lookupMarginal

public Factor lookupMarginal(Variable var)
Description copied from interface: Inferencer
Returns the computed marginal of a given variable. Before using this method, computeMarginals must have been previously called on the graphical model that contains v.

Specified by:
lookupMarginal in interface Inferencer
Specified by:
lookupMarginal in class AbstractInferencer
See Also:
Inferencer.computeMarginals(FactorGraph)

dump

public void dump()
Specified by:
dump in interface Inferencer
Overrides:
dump in class AbstractInferencer

reportTime

public void reportTime()
Description copied from interface: Inferencer
Outputs some measure of the total time spent in this inferencer.

Specified by:
reportTime in interface Inferencer
Overrides:
reportTime in class AbstractInferencer

dump

public void dump(java.io.PrintWriter writer)

lookupMarginal

public Factor lookupMarginal(VarSet c)
Description copied from interface: Inferencer
Returns the computed marginal of a given clique in a graph. Before using this method, computeMarginals must have been previously called on the graphical model that contains the clique.

Specified by:
lookupMarginal in interface Inferencer
Overrides:
lookupMarginal in class AbstractInferencer
See Also:
Inferencer.computeMarginals(cc.mallet.grmm.types.FactorGraph), #computeMarginals(JunctionTree)

lookupLogJoint

public double lookupLogJoint(Assignment assn)
Description copied from interface: Inferencer
Returns the natural logarithm of the joint probability of a given assignment, computed in some factorized fashion. Before using this method, computeMarginals must have been previously called on the graphical model that contains the variables of assn.

This method is less likely to underflow than Math.log (lookupJoint (assn)).

Specified by:
lookupLogJoint in interface Inferencer
Overrides:
lookupLogJoint in class AbstractInferencer
See Also:
Inferencer.computeMarginals(cc.mallet.grmm.types.FactorGraph), #computeMarginals(JunctionTree)