com.cra.bnet.learn
Class EmEtaLearningAlgorithm

java.lang.Object
  |
  +--com.cra.bnet.learn.EmEtaLearningAlgorithm

public final class EmEtaLearningAlgorithm
extends Object

The parameterized EM algorithm for learning cpt entries in a Bayesian network. This algorithm is taken from:

 E. Bauer, D. Koller, and Y. Singer. 1997. Update Rules for Parameter Estimation in Bayesian Networks.
 Proceedings of the 13th Annual Conference on Uncertainty in AI (UAI), pages 3-13.
 

This learning algorithm is designed for the case when the structure of the Bayesian network is known, but the nodes of the network are only partially observable (that is, there are nodes for which you do not have data).

Typical use of this class will be something like:

 BayesianNetwork network = ...;
 DataSet data = ...;
 EmEtaParameters parameters = ...;
 EmEtaListener listener = ...;
 EmEtaLearningAlgorithm algorithm = new EmEtaLearningAlgorithm();
 algorithm.setParameters(parameters);
 algorithm.addListener(listener);
 algorithm.learn(data, network, block);
 

Calling the learn method spawns a new thread in which the actual learning algorithm executes. Both the learn and stop methods contain boolean parameters that control when the method will return. If the boolean is false, the method will return immediately. If the boolean is true, the method will not return until the learning algorithm finishes.

The learning algorithm can be stopped prematurely by calling the stop method. This is useful if the algorithm is taking longer than expected and must be terminated. Execution of the algorithm can be temporarily paused using the pause method. Calling the resume method then resumes execution of the algorithm.

Listeners can be registered that wish to receive notifications about the algorithm's status. Events are fired by the learning algorithm thread, so listener methods should complete their work as quickly as possible. Also, listener methods should not perform any GUI-related tasks directly; instead they should use SwingUtilities.invokeAndWait, SwingUtilities.invokeLater, or a similar mechanism to ensure the GUI code is executed on the AWT event dispatch thread.

This learning algorithm uses the initial CPT entries of hidden nodes as a starting point for learning. Therefore, if you have initial rough estimates of the CPT entries for hidden nodes, those would be good to use. Otherwise, you should randomize the CPT entries using either the BayesianNetwork.randomizeCpts or Cpt.randomizeEntries method. You absolutely should not use uniformly distributed CPTS for hidden nodes; this starts the learning algorithm in a bad local maximum and after learning, those CPTS will still be uniformly distributed. You can use uniformly distributed CPTs for observed nodes, because their CPT entries are learned directly from the data.

This class was not designed to be extended, and there should be no reason to do so. Therefore, this class is declared as final. This ensures that clients cannot override any methods and perform unexpected behaviors.


Constructor Summary
EmEtaLearningAlgorithm()
          Creates a new EmEtaLearningAlgorithm object.
EmEtaLearningAlgorithm(EmEtaParameters parameters)
          Creates a new EmEtaLearningAlgorithm that uses the specified parameters.
 
Method Summary
 void addEmEtaListener(EmEtaListener listener)
          Registers the specified listener so that it will receive events from this learning algorithm.
protected  void fireAlgorithmFinished(double delta, int iteration)
          Fires an algorithmFinished event to all listeners.
protected  void fireAlgorithmPaused(double delta, int iteration)
          Fires an algorithmPaused event to all listeners.
protected  void fireAlgorithmResumed(double delta, int iteration)
          Fires an algorithmResumed event to all listeners.
protected  void fireAlgorithmStarted(double delta, int iteration)
          Fires an algorithmStarted event to all listeners.
protected  void fireAlgorithmStopped(double delta, int iteration)
          Fires an algorithmStopped event to all listeners.
protected  void fireIterationFinished(double delta, int iteration)
          Fires an algorithmFinished event to all listeners.
 EmEtaParameters getParameters()
          Returns the parameters that this learning algorithm is using.
 boolean isRunning()
          Returns true if this learning algorithm is currently running and false otherwise.
 void learn(DataSet data, BayesianNetwork network, boolean block)
          Updates the conditional probability tables of the specified Bayesian network using the specified data set.
 void pause()
          Requests this learning algorithm to pause execution.
 void removeEmEtaListener(EmEtaListener listener)
          Unregisters the specified listener so that it will no longer receive events from this learning algorithm.
 void resume()
          Requests this learning algorithm to resume execution.
 void setParameters(EmEtaParameters parameters)
          Sets the parameters used by this learning algorithm to the specified parameters.
 void stop(boolean block)
          Requests this learning algorithm to stop execution.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EmEtaLearningAlgorithm

public EmEtaLearningAlgorithm()
Creates a new EmEtaLearningAlgorithm object.


EmEtaLearningAlgorithm

public EmEtaLearningAlgorithm(EmEtaParameters parameters)
Creates a new EmEtaLearningAlgorithm that uses the specified parameters.

Parameters:
parameters - parameters to use during learning.
Method Detail

addEmEtaListener

public void addEmEtaListener(EmEtaListener listener)
Registers the specified listener so that it will receive events from this learning algorithm.

Parameters:
listener - listener to register.
Throws:
IllegalArgumentException - if listener is null.

getParameters

public EmEtaParameters getParameters()
Returns the parameters that this learning algorithm is using.

Returns:
the parameters that this learning algorithm is using.

isRunning

public boolean isRunning()
Returns true if this learning algorithm is currently running and false otherwise.

Returns:
true if this learning algorithm is currently running and false otherwise.

learn

public void learn(DataSet data,
                  BayesianNetwork network,
                  boolean block)
Updates the conditional probability tables of the specified Bayesian network using the specified data set. This method spawns a new thread in which the learning takes place. If the specified block parameter is true, this method will return after the learning algorithm is finished. If the specified block parameter is false, this method will return immediately.

Parameters:
data - data to use to adjust the cpt's.
network - Bayesian network whose cpt entries are to be learned.
block - whether to block until learning finishes or return immediately.
Throws:
IllegalArgumentException - if either data or network is null.
IllegalStateException - if this learning algorithm is already running.
IllegalStateException - if an InterruptedException is thrown that causes the thread that called this method (with block == true) to prematurely wake up. This should only happen if Thread.interrupt is called on the thread that called this method, which should never happen.

pause

public void pause()
Requests this learning algorithm to pause execution. This method returns immediately.


removeEmEtaListener

public void removeEmEtaListener(EmEtaListener listener)
Unregisters the specified listener so that it will no longer receive events from this learning algorithm.

Parameters:
listener - listener to unregister.

resume

public void resume()
Requests this learning algorithm to resume execution. This method returns immediately.


setParameters

public void setParameters(EmEtaParameters parameters)
Sets the parameters used by this learning algorithm to the specified parameters.

Parameters:
parameters - parameters to use during learning.
Throws:
IllegalArgumentException - if parameters is null.
IllegalStateException - if this learning algorithm is currently running.

stop

public void stop(boolean block)
Requests this learning algorithm to stop execution. If the specified boolean is false, this method will return immediately. If the specified boolean is true, this method will block the thread that called it until the learning algorithm actually stops. If this learning algorithm is paused before calling this method, it is resumed and then stopped.

Parameters:
block - whether to block until learning actually stops or return immediately.
Throws:
IllegalStateException - if an InterruptedException is thrown that causes the thread that called this method (with block == true) to prematurely wake up. This should only happen if Thread.interrupt is called on the thread that called this method, which should never happen.

fireAlgorithmFinished

protected void fireAlgorithmFinished(double delta,
                                     int iteration)
Fires an algorithmFinished event to all listeners.


fireAlgorithmPaused

protected void fireAlgorithmPaused(double delta,
                                   int iteration)
Fires an algorithmPaused event to all listeners.


fireAlgorithmResumed

protected void fireAlgorithmResumed(double delta,
                                    int iteration)
Fires an algorithmResumed event to all listeners.


fireAlgorithmStarted

protected void fireAlgorithmStarted(double delta,
                                    int iteration)
Fires an algorithmStarted event to all listeners.


fireAlgorithmStopped

protected void fireAlgorithmStopped(double delta,
                                    int iteration)
Fires an algorithmStopped event to all listeners.


fireIterationFinished

protected void fireIterationFinished(double delta,
                                     int iteration)
Fires an algorithmFinished event to all listeners.