org.omegahat.Numerics.Optimizers
Class OptimizerNotifying

java.lang.Object
  |
  +--org.omegahat.Numerics.Optimizers.OptimizerBasic
        |
        +--org.omegahat.Numerics.Optimizers.OptimizerNotifying
All Implemented Interfaces:
OptimizerIterator

public class OptimizerNotifying
extends OptimizerBasic

Optimizer objects that notify listeners during iteration.

Objects can register to be notified after each step in the iteration of the optimizer (and also at initialization and termination of the iteration). The action method of the listener is called with the current model point and also the optimizer object itself as arguments. It can therefore display some information about the iteration but, via the second argument, can also interfere in the optimization.


Field Summary
static int BACKGROUND
           
protected  BackgroundTaskManager backgroundManager
          This manager takes care of the background, or non-blocking, listeners.
static int COMPLETION
           
protected  ConvergenceListenerInt convergence
           
static int INFORMATION
           
static int INITIALIZATION
          symbolic constants to index the array of listeners.
protected  IterationCounterInt iteration
           
static int ITERATION
           
protected  java.util.Vector[] listeners
          An array of objects, each of which is a list of listeners of a particular type.
static int NUM_LISTENER_VECTORS
           
 
Fields inherited from class org.omegahat.Numerics.Optimizers.OptimizerBasic
algorithm, current, objective, state
 
Fields inherited from interface org.omegahat.Numerics.Optimizers.OptimizerIterator
CONTINUE, CONVERGED, EXCEPTION, NUMERIC_PROBLEM, TOO_MANY_STEPS
 
Constructor Summary
OptimizerNotifying(OptimizerAlgorithm fitter)
           
OptimizerNotifying(OptimizerAlgorithm fitter, ModelObjective model, double[] start)
           
OptimizerNotifying(OptimizerAlgorithm fitter, ModelPoint start)
           
 
Method Summary
 void addBackgroundListener(IterationListener l)
           
 void addConvergedListener(IterationListener l)
          A listener to be called only on completion.
 void addInitializationListener(IterationListener l)
          A listener to be called only on initialization.
 void addIterationListener(IterationListener l)
          Add a listener only to be called at each step in the iteration.
 void addListener(java.util.EventListener l)
          Add a listener to the optimizer.
 boolean addListener(java.util.EventListener l, int type)
          A listener added with a computed type, which should be one of the pre-defined static constants in this class.
 void addStepListener(IterationListener l)
          A listener to be called only after each iteration step.
 BackgroundTaskManager backgroundManager()
           
 BackgroundTaskManager backgroundManager(BackgroundTaskManager m)
           
 BackgroundTaskManager backgroundManager(BackgroundTaskManager m, boolean start)
           
 boolean continueIteration(OptimizerAlgorithm opt, ModelPoint values)
          Called after each iteration to test whether to continue.
 ModelPoint eval()
          Carry out the iteration.
 void exchangeListener(java.util.EventListener old, java.util.EventListener current, int type)
          Remove old from the listeners of this type, and add current.
 ConvergenceListenerInt getConvergence()
          Accessor for convergence field
 IterationCounterInt getIteration()
          Accessor for iteration field
 java.util.Vector[] getListeners()
           
 ModelPoint initialize(ModelPoint initialValue)
          Initialize the optimizer with the values supplied.
 ModelPoint initialize(ModelPoint initialValues, IterationCounter l)
          Initialize the iteration.
 void make()
          Make the structures in the object.
 void notifyBackgroundListeners(IterationEvent event)
          Notify all background listeners of the event.
 void notifyInformationListeners(IterationEvent ev)
          Notify all the information listeners of the event.
 void notifyListeners(IterationEvent event)
          Notify all listeners of the given event.
 void notifyListeners(ModelPoint values, int type)
          Notify all listeners of the given type of an IterationEvent containing the specified values for the model.
 ConvergenceListenerInt setConvergence(ConvergenceListenerInt value)
          Accessor for setting convergence field
 IterationCounterInt setIteration(IterationCounterInt value)
          Accessor for setting iteration field
 java.util.Vector[] setListeners(java.util.Vector[] v)
           
 
Methods inherited from class org.omegahat.Numerics.Optimizers.OptimizerBasic
eval, getAlgorithm, getCurrent, getObjective, getState, setAlgorithm, setCurrent, setObjective, setState
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INITIALIZATION

public static final int INITIALIZATION
symbolic constants to index the array of listeners.

COMPLETION

public static final int COMPLETION

ITERATION

public static final int ITERATION

BACKGROUND

public static final int BACKGROUND

INFORMATION

public static final int INFORMATION

NUM_LISTENER_VECTORS

public static final int NUM_LISTENER_VECTORS

listeners

protected java.util.Vector[] listeners
An array of objects, each of which is a list of listeners of a particular type.

backgroundManager

protected BackgroundTaskManager backgroundManager
This manager takes care of the background, or non-blocking, listeners.

iteration

protected IterationCounterInt iteration

convergence

protected ConvergenceListenerInt convergence
Constructor Detail

OptimizerNotifying

public OptimizerNotifying(OptimizerAlgorithm fitter)

OptimizerNotifying

public OptimizerNotifying(OptimizerAlgorithm fitter,
                          ModelPoint start)

OptimizerNotifying

public OptimizerNotifying(OptimizerAlgorithm fitter,
                          ModelObjective model,
                          double[] start)
Method Detail

make

public void make()
Make the structures in the object.

Called from each of the constructors.


initialize

public ModelPoint initialize(ModelPoint initialValues,
                             IterationCounter l)
                      throws java.lang.Exception
Initialize the iteration.

After initializing the fitting algorithm, adds the supplied iteration counter to the listeners. Calling the initializer with a null counter avoids the default control on the number of iterations.


initialize

public ModelPoint initialize(ModelPoint initialValue)
                      throws java.lang.Exception
Initialize the optimizer with the values supplied.

An iteration counter will be installed with a default maximum, unless there is already a counter among the listeners.

Overrides:
initialize in class OptimizerBasic

eval

public ModelPoint eval()
                throws java.lang.Exception
Carry out the iteration.
Overrides:
eval in class OptimizerBasic

notifyListeners

public void notifyListeners(ModelPoint values,
                            int type)
Notify all listeners of the given type of an IterationEvent containing the specified values for the model.

notifyListeners

public void notifyListeners(IterationEvent event)
Notify all listeners of the given event.

notifyInformationListeners

public void notifyInformationListeners(IterationEvent ev)
Notify all the information listeners of the event.

notifyBackgroundListeners

public void notifyBackgroundListeners(IterationEvent event)
Notify all background listeners of the event.

The actual performance of the corresponding tasks is the responsibility of an object of class BackgroundTaskManager.


continueIteration

public boolean continueIteration(OptimizerAlgorithm opt,
                                 ModelPoint values)
Description copied from class: OptimizerBasic
Called after each iteration to test whether to continue.

The basic method only checks the state of the optimizer, which must have been set by some other computation. In the subclass OptimizerNotifier the corresponding method calls all the iteration listeners. By default these include a counter that exits when too many iterations have taken place. The algorithm will likely add listener(s) of its own, to detect successful convergence.

Overrides:
continueIteration in class OptimizerBasic

addListener

public void addListener(java.util.EventListener l)
Add a listener to the optimizer.

The listeners will be called once on startup and again after each iterative step of refinement. In other words, the listener gets to examine the optimization for each step, including the initial one.

The argument can be an instance of: InformationListener, IterationListener, or BackgroundListener.


addIterationListener

public void addIterationListener(IterationListener l)
Add a listener only to be called at each step in the iteration.

If the listener is an IterationCounter and there is currently no iteration counter in this optimizer, make this the iteration property. Similarly if the listener is the first ConvergenceListener, make this the convergence property. (Either property may be set directly, or set to null to reset the property.)


addBackgroundListener

public void addBackgroundListener(IterationListener l)

addInitializationListener

public void addInitializationListener(IterationListener l)
A listener to be called only on initialization.

addConvergedListener

public void addConvergedListener(IterationListener l)
A listener to be called only on completion.

addStepListener

public void addStepListener(IterationListener l)
A listener to be called only after each iteration step.

addListener

public boolean addListener(java.util.EventListener l,
                           int type)
A listener added with a computed type, which should be one of the pre-defined static constants in this class.

exchangeListener

public void exchangeListener(java.util.EventListener old,
                             java.util.EventListener current,
                             int type)
Remove old from the listeners of this type, and add current.

getListeners

public java.util.Vector[] getListeners()

setListeners

public java.util.Vector[] setListeners(java.util.Vector[] v)

backgroundManager

public BackgroundTaskManager backgroundManager()

backgroundManager

public BackgroundTaskManager backgroundManager(BackgroundTaskManager m)

backgroundManager

public BackgroundTaskManager backgroundManager(BackgroundTaskManager m,
                                               boolean start)

getIteration

public IterationCounterInt getIteration()
Accessor for iteration field

setIteration

public IterationCounterInt setIteration(IterationCounterInt value)
Accessor for setting iteration field

getConvergence

public ConvergenceListenerInt getConvergence()
Accessor for convergence field

setConvergence

public ConvergenceListenerInt setConvergence(ConvergenceListenerInt value)
Accessor for setting convergence field