com.cra.bnet.engine
Class BeliefUpdater

java.lang.Object
  |
  +--com.cra.bnet.engine.BeliefUpdater

public class BeliefUpdater
extends Object

Controls automatic updating of beliefs for a Bayesian network. This class can be configured to automatically update the beliefs of a Bayesian network after certain modifications are made to it. For example, in an interactive application, beliefs can be updated after the user makes modifications like adding an edge or reordering a state.

Initially, all settings are false; that is, the belief updater will not update beliefs after any event occurs. To easily enable updating on all evidence-related events, just use

 updater.setUpdateOnEvidence(true);
 

There are also two GUI classes that can be used with BeliefUpdater: BeliefUpdaterPanel and BeliefUpdaterDialog.


Field Summary
static int ALL_EVIDENCE_RETRACTED
          The integer mask for all evidence retracted.
static int CPT_ENTRY_CHANGED
          The integer mask for cpt entry changed.
static int EDGE_ADDED
          The integer mask for edge added.
static int EDGE_REMOVED
          The integer mask for edge removed.
static int EVIDENCE_POSTED
          The integer mask for evidence posted.
static int EVIDENCE_RETRACTED
          The integer mask for evidence retracted.
static int NODE_ADDED
          The integer mask for node added.
static int NODE_REMOVED
          The integer mask for node removed.
static int PARENT_REORDERED
          The integer mask for parent reordered.
static int STATE_ADDED
          The integer mask for state added.
static int STATE_REMOVED
          The integer mask for state removed.
static int STATE_REORDERED
          The integer mask for state reordered.
static String UPDATE_ON_ALL_EVIDENCE_RETRACTED_PROPERTY
          Property that represents a change in updating on all evidence retracted.
static String UPDATE_ON_CPT_ENTRY_CHANGED_PROPERTY
          Property that represents a change in updating on a cpt entry changed.
static String UPDATE_ON_EDGE_ADDED_PROPERTY
          Property that represents a change in updating on edge added.
static String UPDATE_ON_EDGE_REMOVED_PROPERTY
          Property that represents a change in updating on edge removed.
static String UPDATE_ON_EVIDENCE_POSTED_PROPERTY
          Property that represents a change in updating on evidence posted.
static String UPDATE_ON_EVIDENCE_RETRACTED_PROPERTY
          Property that represents a change in updating on evidence retracted.
static String UPDATE_ON_NODE_ADDED_PROPERTY
          Property that represents a change in updating on node added.
static String UPDATE_ON_NODE_REMOVED_PROPERTY
          Property that represents a change in updating on node removed.
static String UPDATE_ON_PARENT_REORDERED_PROPERTY
          Property that represents a change in updating on parent reordered.
static String UPDATE_ON_STATE_ADDED_PROPERTY
          Property that represents a change in updating on state added.
static String UPDATE_ON_STATE_REMOVED_PROPERTY
          Property that represents a change in updating on state removed.
static String UPDATE_ON_STATE_REORDERED_PROPERTY
          Property that represents a change in updating on state reordered.
 
Method Summary
 void addChangeListener(ChangeListener listener)
          Registers the specified listener with this belief updater so it will receive change events whenever this belief updater is notified of any modifications to the Bayesian network.
 void addPropertyChangeListener(PropertyChangeListener listener)
          Registers the specified listener so it will receive property change events.
 void addPropertyChangeListener(PropertyChangeListener listener, String property)
          Registers the specified listener so it will receive property change events for the specified property.
protected  void fireStateChanged()
          Fires a change event to all registered change listeners.
 BayesianNetwork getBayesianNetwork()
          Returns the Bayesian network that this belief updater controls.
 int getBeliefUpdateSettings()
          Returns this belief updater's belief update settings.
 boolean isUpdatingOnAllEvidenceRetracted()
          Returns true if beliefs are updated after all evidence is retracted.
 boolean isUpdatingOnCptEntryChanged()
          Returns true if beliefs are updated after a cpt entry changes.
 boolean isUpdatingOnEdgeAdded()
          Returns true if beliefs are updated after an edge is added.
 boolean isUpdatingOnEdgeRemoved()
          Returns true if beliefs are updated after an edge is removed.
 boolean isUpdatingOnEvidencePosted()
          Returns true if beliefs are updated after evidence is posted.
 boolean isUpdatingOnEvidenceRetracted()
          Returns true if beliefs are updated after evidence is retracted.
 boolean isUpdatingOnNodeAdded()
          Returns true if beliefs are updated after a node is added.
 boolean isUpdatingOnNodeRemoved()
          Returns true if beliefs are updated after a node is removed.
 boolean isUpdatingOnParentReordered()
          Returns true if beliefs are updated after a parent is reordered.
 boolean isUpdatingOnStateAdded()
          Returns true if beliefs are updated after a state is added.
 boolean isUpdatingOnStateRemoved()
          Returns true if beliefs are updated after a state is removed.
 boolean isUpdatingOnStateReordered()
          Returns true if beliefs are updated after a state is reordered.
 void removeChangeListener(ChangeListener listener)
          Unregisters the specified listener with this belief updater so it will no longer receive change events whenever this belief updater is notified of any modifications to the Bayesian network.
 void removePropertyChangeListener(PropertyChangeListener listener)
          Unregisters the specified listener so it will not receive property change events.
 void removePropertyChangeListener(PropertyChangeListener listener, String property)
          Unregisters the specified listener so it will not receive property change events for the specified property.
 void setBeliefUpdateSettings(int settings)
          Sets this belief updater's belief update settings to the specified settings.
 void setUpdateOnAllEvidenceRetracted(boolean update)
          Updates beliefs when evidence is retracted depending on the specified parameter.
 void setUpdateOnAnything(boolean update)
          Updates beliefs when any event occurs depending on the specified parameter.
 void setUpdateOnCptEntryChanged(boolean update)
          Updates beliefs when a cpt entry changes depending on the specified parameter.
 void setUpdateOnEdgeAdded(boolean update)
          Updates beliefs when an edge is added depending on the specified parameter.
 void setUpdateOnEdgeRemoved(boolean update)
          Updates beliefs when an edge is removed depending on the specified parameter.
 void setUpdateOnEvidence(boolean update)
          Updates beliefs when evidence is posted or retracted depending on the specified parameter.
 void setUpdateOnEvidencePosted(boolean update)
          Updates beliefs when evidence is posted depending on the specified parameter.
 void setUpdateOnEvidenceRetracted(boolean update)
          Updates beliefs when evidence is retracted depending on the specified parameter.
 void setUpdateOnNodeAdded(boolean update)
          Updates beliefs when a node is added depending on the specified parameter.
 void setUpdateOnNodeRemoved(boolean update)
          Updates beliefs when a node is removed depending on the specified parameter.
 void setUpdateOnParentReordered(boolean update)
          Updates beliefs when a parent is reordered depending on the specified parameter.
 void setUpdateOnStateAdded(boolean update)
          Updates beliefs when a state is added depending on the specified parameter.
 void setUpdateOnStateRemoved(boolean update)
          Updates beliefs when a state is removed depending on the specified parameter.
 void setUpdateOnStateReordered(boolean update)
          Updates beliefs when a state is reordered depending on the specified parameter.
 void updateBeliefs()
          Updates all beliefs in the Bayesian network.
 void updateBeliefs(boolean forceEvents)
          Updates all beliefs in the Bayesian network and forces belief events to be fired if the specified boolean is true.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UPDATE_ON_ALL_EVIDENCE_RETRACTED_PROPERTY

public static final String UPDATE_ON_ALL_EVIDENCE_RETRACTED_PROPERTY
Property that represents a change in updating on all evidence retracted.

See Also:
Constant Field Values

UPDATE_ON_CPT_ENTRY_CHANGED_PROPERTY

public static final String UPDATE_ON_CPT_ENTRY_CHANGED_PROPERTY
Property that represents a change in updating on a cpt entry changed.

See Also:
Constant Field Values

UPDATE_ON_EDGE_ADDED_PROPERTY

public static final String UPDATE_ON_EDGE_ADDED_PROPERTY
Property that represents a change in updating on edge added.

See Also:
Constant Field Values

UPDATE_ON_EDGE_REMOVED_PROPERTY

public static final String UPDATE_ON_EDGE_REMOVED_PROPERTY
Property that represents a change in updating on edge removed.

See Also:
Constant Field Values

UPDATE_ON_EVIDENCE_POSTED_PROPERTY

public static final String UPDATE_ON_EVIDENCE_POSTED_PROPERTY
Property that represents a change in updating on evidence posted.

See Also:
Constant Field Values

UPDATE_ON_EVIDENCE_RETRACTED_PROPERTY

public static final String UPDATE_ON_EVIDENCE_RETRACTED_PROPERTY
Property that represents a change in updating on evidence retracted.

See Also:
Constant Field Values

UPDATE_ON_NODE_ADDED_PROPERTY

public static final String UPDATE_ON_NODE_ADDED_PROPERTY
Property that represents a change in updating on node added.

See Also:
Constant Field Values

UPDATE_ON_NODE_REMOVED_PROPERTY

public static final String UPDATE_ON_NODE_REMOVED_PROPERTY
Property that represents a change in updating on node removed.

See Also:
Constant Field Values

UPDATE_ON_STATE_ADDED_PROPERTY

public static final String UPDATE_ON_STATE_ADDED_PROPERTY
Property that represents a change in updating on state added.

See Also:
Constant Field Values

UPDATE_ON_STATE_REMOVED_PROPERTY

public static final String UPDATE_ON_STATE_REMOVED_PROPERTY
Property that represents a change in updating on state removed.

See Also:
Constant Field Values

UPDATE_ON_STATE_REORDERED_PROPERTY

public static final String UPDATE_ON_STATE_REORDERED_PROPERTY
Property that represents a change in updating on state reordered.

See Also:
Constant Field Values

UPDATE_ON_PARENT_REORDERED_PROPERTY

public static final String UPDATE_ON_PARENT_REORDERED_PROPERTY
Property that represents a change in updating on parent reordered.

See Also:
Constant Field Values

NODE_REMOVED

public static final int NODE_REMOVED
The integer mask for node removed.


NODE_ADDED

public static final int NODE_ADDED
The integer mask for node added.


EDGE_REMOVED

public static final int EDGE_REMOVED
The integer mask for edge removed.


EDGE_ADDED

public static final int EDGE_ADDED
The integer mask for edge added.


STATE_ADDED

public static final int STATE_ADDED
The integer mask for state added.


STATE_REMOVED

public static final int STATE_REMOVED
The integer mask for state removed.


STATE_REORDERED

public static final int STATE_REORDERED
The integer mask for state reordered.


CPT_ENTRY_CHANGED

public static final int CPT_ENTRY_CHANGED
The integer mask for cpt entry changed.


EVIDENCE_POSTED

public static final int EVIDENCE_POSTED
The integer mask for evidence posted.


EVIDENCE_RETRACTED

public static final int EVIDENCE_RETRACTED
The integer mask for evidence retracted.


ALL_EVIDENCE_RETRACTED

public static final int ALL_EVIDENCE_RETRACTED
The integer mask for all evidence retracted.


PARENT_REORDERED

public static final int PARENT_REORDERED
The integer mask for parent reordered.

Method Detail

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
Registers the specified listener so it will receive property change events.

Parameters:
listener - property change listener.

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener,
                                      String property)
Registers the specified listener so it will receive property change events for the specified property.

Parameters:
listener - property change listener.

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
Unregisters the specified listener so it will not receive property change events.

Parameters:
listener - property change listener.

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener,
                                         String property)
Unregisters the specified listener so it will not receive property change events for the specified property.

Parameters:
listener - property change listener.

addChangeListener

public void addChangeListener(ChangeListener listener)
Registers the specified listener with this belief updater so it will receive change events whenever this belief updater is notified of any modifications to the Bayesian network.

Parameters:
listener - change listener.

removeChangeListener

public void removeChangeListener(ChangeListener listener)
Unregisters the specified listener with this belief updater so it will no longer receive change events whenever this belief updater is notified of any modifications to the Bayesian network.

Parameters:
listener - change listener.

fireStateChanged

protected void fireStateChanged()
Fires a change event to all registered change listeners.


getBayesianNetwork

public BayesianNetwork getBayesianNetwork()
Returns the Bayesian network that this belief updater controls.

Returns:
the Bayesian network that this belief updater controls.

isUpdatingOnAllEvidenceRetracted

public boolean isUpdatingOnAllEvidenceRetracted()
Returns true if beliefs are updated after all evidence is retracted.

Returns:
true if beliefs are updated after all evidence is retracted.

isUpdatingOnCptEntryChanged

public boolean isUpdatingOnCptEntryChanged()
Returns true if beliefs are updated after a cpt entry changes.

Returns:
true if beliefs are updated after a cpt entry changes.

isUpdatingOnEdgeAdded

public boolean isUpdatingOnEdgeAdded()
Returns true if beliefs are updated after an edge is added.

Returns:
true if beliefs are updated after an edge is added.

isUpdatingOnEdgeRemoved

public boolean isUpdatingOnEdgeRemoved()
Returns true if beliefs are updated after an edge is removed.

Returns:
true if beliefs are updated after an edge is removed.

isUpdatingOnEvidencePosted

public boolean isUpdatingOnEvidencePosted()
Returns true if beliefs are updated after evidence is posted.

Returns:
true if beliefs are updated after evidence is posted.

isUpdatingOnEvidenceRetracted

public boolean isUpdatingOnEvidenceRetracted()
Returns true if beliefs are updated after evidence is retracted.

Returns:
true if beliefs are updated after evidence is retracted.

isUpdatingOnNodeAdded

public boolean isUpdatingOnNodeAdded()
Returns true if beliefs are updated after a node is added.

Returns:
true if beliefs are updated after a node is added.

isUpdatingOnNodeRemoved

public boolean isUpdatingOnNodeRemoved()
Returns true if beliefs are updated after a node is removed.

Returns:
true if beliefs are updated after a node is removed.

isUpdatingOnStateAdded

public boolean isUpdatingOnStateAdded()
Returns true if beliefs are updated after a state is added.

Returns:
true if beliefs are updated after a state is added.

isUpdatingOnStateRemoved

public boolean isUpdatingOnStateRemoved()
Returns true if beliefs are updated after a state is removed.

Returns:
true if beliefs are updated after a state is removed.

isUpdatingOnStateReordered

public boolean isUpdatingOnStateReordered()
Returns true if beliefs are updated after a state is reordered.

Returns:
true if beliefs are updated after a state is reordered.

isUpdatingOnParentReordered

public boolean isUpdatingOnParentReordered()
Returns true if beliefs are updated after a parent is reordered.

Returns:
true if beliefs are updated after a parent is reordered.

setUpdateOnAllEvidenceRetracted

public void setUpdateOnAllEvidenceRetracted(boolean update)
Updates beliefs when evidence is retracted depending on the specified parameter.

Parameters:
update - true if beliefs should be updated and false if they should not.

setUpdateOnCptEntryChanged

public void setUpdateOnCptEntryChanged(boolean update)
Updates beliefs when a cpt entry changes depending on the specified parameter.

Parameters:
update - true if beliefs should be updated and false if they should not.

setUpdateOnEdgeAdded

public void setUpdateOnEdgeAdded(boolean update)
Updates beliefs when an edge is added depending on the specified parameter.

Parameters:
update - true if beliefs should be updated and false if they should not.

setUpdateOnEdgeRemoved

public void setUpdateOnEdgeRemoved(boolean update)
Updates beliefs when an edge is removed depending on the specified parameter.

Parameters:
update - true if beliefs should be updated and false if they should not.

setUpdateOnEvidencePosted

public void setUpdateOnEvidencePosted(boolean update)
Updates beliefs when evidence is posted depending on the specified parameter.

Parameters:
update - true if beliefs should be updated and false if they should not.

setUpdateOnEvidenceRetracted

public void setUpdateOnEvidenceRetracted(boolean update)
Updates beliefs when evidence is retracted depending on the specified parameter.

Parameters:
update - true if beliefs should be updated and false if they should not.

setUpdateOnNodeAdded

public void setUpdateOnNodeAdded(boolean update)
Updates beliefs when a node is added depending on the specified parameter.

Parameters:
update - true if beliefs should be updated and false if they should not.

setUpdateOnNodeRemoved

public void setUpdateOnNodeRemoved(boolean update)
Updates beliefs when a node is removed depending on the specified parameter.

Parameters:
update - true if beliefs should be updated and false if they should not.

setUpdateOnStateAdded

public void setUpdateOnStateAdded(boolean update)
Updates beliefs when a state is added depending on the specified parameter.

Parameters:
update - true if beliefs should be updated and false if they should not.

setUpdateOnStateRemoved

public void setUpdateOnStateRemoved(boolean update)
Updates beliefs when a state is removed depending on the specified parameter.

Parameters:
update - true if beliefs should be updated and false if they should not.

setUpdateOnStateReordered

public void setUpdateOnStateReordered(boolean update)
Updates beliefs when a state is reordered depending on the specified parameter.

Parameters:
update - true if beliefs should be updated and false if they should not.

setUpdateOnParentReordered

public void setUpdateOnParentReordered(boolean update)
Updates beliefs when a parent is reordered depending on the specified parameter.

Parameters:
update - true if beliefs should be updated and false if they should not.

setUpdateOnAnything

public void setUpdateOnAnything(boolean update)
Updates beliefs when any event occurs depending on the specified parameter. This method calls all other set methods using the specified parameter.

Parameters:
update - true if beliefs should be updated and false if they should not.

setUpdateOnEvidence

public void setUpdateOnEvidence(boolean update)
Updates beliefs when evidence is posted or retracted depending on the specified parameter. This method calls the setUpdateOnAllEvidenceRetracted, setUpdateOnEvidencePosted, and setUpdateOnEvidenceRetracted methods using the specified parameter.

Parameters:
update - true if beliefs should be updated and false if they should not.

updateBeliefs

public void updateBeliefs()
Updates all beliefs in the Bayesian network. Calling this method is equivalent to calling:
 updateBeliefs(true);
 


updateBeliefs

public void updateBeliefs(boolean forceEvents)
Updates all beliefs in the Bayesian network and forces belief events to be fired if the specified boolean is true. If the specified boolean is false, belief events will not be fired if beliefs didn't change.

Parameters:
forceEvents - true to force belief events to be fired and false not to.

getBeliefUpdateSettings

public int getBeliefUpdateSettings()
Returns this belief updater's belief update settings. The returned integer is the bitwise-OR of the corresponding integers of all enabled update events.

Returns:
this belief updater's belief update settings.

setBeliefUpdateSettings

public void setBeliefUpdateSettings(int settings)
Sets this belief updater's belief update settings to the specified settings. This method will enable belief updating on all events whose corresponding integers are consistent with the specified integer by the bitwise-AND operator.

Parameters:
settings - belief update settings.