com.cra.bnet.engine
Class JunctionTreeInferenceEngine

java.lang.Object
  |
  +--com.cra.bnet.engine.JunctionTreeInferenceEngine
All Implemented Interfaces:
InferenceEngine
Direct Known Subclasses:
HuginInferenceEngine

public abstract class JunctionTreeInferenceEngine
extends Object
implements InferenceEngine

Skeletal implementation of the InferenceEngine interface for junction tree based inference algorithms. This class stores the Bayesian network, corresponding junction tree, and all evidence. It also provides generic implementations of the methods in the InferenceEngine interface. Specific junction tree based inference algorithms should extend this class and override the initialize, restorePotentials, multiplyEvidence, sendMessage, and calculateBeliefs methods and implement algorithm-specific behavior in these methods. Subclasses are also responsible for storage of clique and separator potentials.


Constructor Summary
protected JunctionTreeInferenceEngine(BayesianNetwork network)
          Creates a new junction tree inference engine using the specified Bayesian network.
protected JunctionTreeInferenceEngine(BayesianNetwork network, boolean primary)
          Creates a new junction tree inference engine using the specified Bayesian network.
 
Method Summary
protected abstract  double[] calculateBeliefs(DiscreteNode node)
          Calculates the current beliefs for the specified variable given the current evidence.
 void clearEvidence()
          Removes (or equivalently, retracts) evidence from all nodes in the network.
 BayesianNetwork getBayesianNetwork()
          Returns this inference engine's Bayesian network.
 double[] getBeliefs(DiscreteNode node)
          Returns the current beliefs for the specified variable.
 double[] getEvidence(DiscreteNode node)
          Returns the current evidence associated with the specified variable.
 JunctionTree getJunctionTree()
          Returns this inference engine's current junction tree.
protected  Map getNewEvidence()
          Returns the evidence that has not been multiplied into the junction tree potentials yet.
protected  Map getNewQuotients()
          Returns the evidence quotients that have not been multiplied into the junction tree potentials yet.
 List getSaturated()
          Returns the nodes saturated in this junction tree inference engine.
protected abstract  void initialize()
          Initializes the junction tree potentials.
 void makeConsistent()
          Makes the junction tree consistent so beliefs can be calculated from it.
protected abstract  void multiplyEvidence()
          Multiplies the new evidence into the junction tree potentials.
 void reconstruct()
          Notifies this engine that it must reconstruct its junction tree before doing anything else.
 void removed()
          Called by BayesianNetwork to notify this inference engine that it has been replaced by another inference engine and will not be used anymore.
 void removeEvidence(DiscreteNode node)
          Removes (or equivalently, retracts) evidence from the specified variable.
protected abstract  void restorePotentials()
          Restores the junction tree potentials to their initialized state.
protected abstract  void sendMessage(Set fromClique, Set toClique)
          Sends a message from the first clique to the second clique.
 void setEvidence(DiscreteNode node, double[] likelihood)
          Posts the specified evidence to the specified variable.
 void setSaturated(List saturated)
          Sets the nodes saturated in this junction tree inference engine.
 void transferEvidence()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JunctionTreeInferenceEngine

protected JunctionTreeInferenceEngine(BayesianNetwork network)
Creates a new junction tree inference engine using the specified Bayesian network. This constructor creates a new junction tree and initializes the junction tree potentials.

This constructor just calls this(network, false).

Parameters:
network - Bayesian network for this inference engine.

JunctionTreeInferenceEngine

protected JunctionTreeInferenceEngine(BayesianNetwork network,
                                      boolean primary)
Creates a new junction tree inference engine using the specified Bayesian network. This constructor creates a new junction tree and initializes the junction tree potentials.

Parameters:
network - Bayesian network for this inference engine.
primary - true if this engine is the network's primary engine and false if this engine is just for temporary use.
Method Detail

getBayesianNetwork

public final BayesianNetwork getBayesianNetwork()
Returns this inference engine's Bayesian network.

Returns:
this inference engine's Bayesian network.

getSaturated

public final List getSaturated()
Returns the nodes saturated in this junction tree inference engine. All elements of the returned list are of type DiscreteNode. The returned list is unmodifiable.

Returns:
the nodes saturated in this junction tree inference engine.

setSaturated

public final void setSaturated(List saturated)
Sets the nodes saturated in this junction tree inference engine. All elements of the specified list must be of type DiscreteNode. By saturating the junction tree with nodes, joint probabilities can be efficiently computed. For example, if W is the set of saturated nodes, then getBeliefs will return P(V,W|e) instead of P(V|e).

Parameters:
saturated - list of nodes to be saturated in this junction tree inference engine.

getBeliefs

public double[] getBeliefs(DiscreteNode node)
Returns the current beliefs for the specified variable. The beliefs are the probability of each state of the variable given the evidence posted to the network.

If any nodes are currently saturated, the returned array will correspond to the joint beliefs in the saturated nodes and the specified variable given the current evidence (i.e. P(V,W|e) where V is the specified variable and W is the set of saturated nodes). In this case, the order of the nodes is as follows:

Thus, you can create a VbnConverter object with the nodes in the above order to make sense of the returned belief values.

A return value of null indicates that inconsistent evidence was posted. This method guarantees that the engine will be in a consistent state upon returning null, so that subsequent calls to this method will return valid beliefs. The consistent state is simply the state it was in before the inconsistent evidence was posted.

This method will also return null if there are any CPT rows that contain all zero values.

Specified by:
getBeliefs in interface InferenceEngine
Parameters:
node - variable whose beliefs are returned.
Returns:
the current beliefs for the specified variable or null if inconsistent evidence was posted.

getEvidence

public double[] getEvidence(DiscreteNode node)
Returns the current evidence associated with the specified variable. If no evidence has been posted for the specified variable, an array of all ones will be returned.

Specified by:
getEvidence in interface InferenceEngine
Returns:
the current evidence associated with the specified variable, or an array of ones if no evidence has been posted to the variable.

setEvidence

public void setEvidence(DiscreteNode node,
                        double[] likelihood)
Posts the specified evidence to the specified variable.

Specified by:
setEvidence in interface InferenceEngine
Parameters:
node - variable to post evidence to.
likelihood - evidence in the form of a likelihood vector.

removeEvidence

public void removeEvidence(DiscreteNode node)
Removes (or equivalently, retracts) evidence from the specified variable.

Specified by:
removeEvidence in interface InferenceEngine
Parameters:
node - variable whose evidence is retracted.

clearEvidence

public void clearEvidence()
Removes (or equivalently, retracts) evidence from all nodes in the network.

Specified by:
clearEvidence in interface InferenceEngine

makeConsistent

public void makeConsistent()
Makes the junction tree consistent so beliefs can be calculated from it.


getNewEvidence

protected Map getNewEvidence()
Returns the evidence that has not been multiplied into the junction tree potentials yet. Entries in the returned map are (DiscreteNode, Potential) pairs: Potentials are evidence potentials. The returned map is unmodifiable. These are not the potentials that should be multiplied into the junction tree potentials. Use the getNewQuotients method for that.

Returns:
the evidence that has not been multiplied into the junction tree potentials yet.

getNewQuotients

protected Map getNewQuotients()
Returns the evidence quotients that have not been multiplied into the junction tree potentials yet. Entries in the returned map are (DiscreteNode, Potential) pairs: Potentials are evidence quotient potentials. The returned map is unmodifiable. These are the actual potentials that should be multiplied into the junction tree potentials.

Returns:
the evidence quotients that have not been multiplied into the junction tree potentials yet.

getJunctionTree

public final JunctionTree getJunctionTree()
Returns this inference engine's current junction tree.

Returns:
this inference engine's current junction tree.

reconstruct

public void reconstruct()
Notifies this engine that it must reconstruct its junction tree before doing anything else.


initialize

protected abstract void initialize()
Initializes the junction tree potentials. Subclasses must override this method and implement algorithm-specific initialization.


restorePotentials

protected abstract void restorePotentials()
Restores the junction tree potentials to their initialized state. Subclasses can cache their initialized potentials and then restore them in this method without having to multiply in all of the cpt's.


multiplyEvidence

protected abstract void multiplyEvidence()
Multiplies the new evidence into the junction tree potentials. Subclasses must override this method and implement algorithm-specific evidence entry into the junction tree potentials.


sendMessage

protected abstract void sendMessage(Set fromClique,
                                    Set toClique)
Sends a message from the first clique to the second clique. Subclasses must override this method and implement algorithm-specific message passing.

Parameters:
fromClique - origin clique of the message.
toClique - destination clique of the message.

calculateBeliefs

protected abstract double[] calculateBeliefs(DiscreteNode node)
Calculates the current beliefs for the specified variable given the current evidence. Subclasses must override this method and implement algorithm-specific belief calculation.

Parameters:
node - variable whose beliefs are to be calculated.
Returns:
the current beliefs for the specified variable given the current evidence.

transferEvidence

public void transferEvidence()

removed

public void removed()
Description copied from interface: InferenceEngine
Called by BayesianNetwork to notify this inference engine that it has been replaced by another inference engine and will not be used anymore.

Specified by:
removed in interface InferenceEngine