org.omegahat.Numerics.Optimizers
Class OptimizerBasic

java.lang.Object
  |
  +--org.omegahat.Numerics.Optimizers.OptimizerBasic
All Implemented Interfaces:
OptimizerIterator
Direct Known Subclasses:
Optimizer, OptimizerNotifying

public class OptimizerBasic
extends java.lang.Object
implements OptimizerIterator

The basic iterative optimizer, using an OptimizerAlgorithm for iteration and a ModelObjective to define the particular model to optmize.

The eval method performs the basic iteration by calling the algorithm to refine the current model estimate.

Although this class is not technically abstract, it must either have an algorithm that sets the state of the optimizer when convergence takes place or the actual optimizer must itself come from a class that puts some limits on the iteration, since the continueIteration method of this class does nothing but check the state.


Field Summary
protected  OptimizerAlgorithm algorithm
          The numerical method used to refine the model, by improving the value computed by theobjective.
protected  ModelPoint current
          The current model estimate.
protected  ModelObjective objective
           
protected  int state
           
 
Fields inherited from interface org.omegahat.Numerics.Optimizers.OptimizerIterator
CONTINUE, CONVERGED, EXCEPTION, NUMERIC_PROBLEM, TOO_MANY_STEPS
 
Constructor Summary
OptimizerBasic(OptimizerAlgorithm algorithm)
          Create an optimizer with a given algorithm, but initially no specific model to fit.
OptimizerBasic(OptimizerAlgorithm algorithm, ModelObjective model, double[] start)
          Define the model separately from parameters and objective.
OptimizerBasic(OptimizerAlgorithm algorithm, ModelPoint start)
          Create a complete optimizer with an algorithm and initialize it with a starting point (including the model objective).
 
Method Summary
 boolean continueIteration(OptimizerAlgorithm opt, ModelPoint values)
          Called after each iteration to test whether to continue.
 ModelPoint eval()
          The basic optimization loop, which iterates to compute the next set of parameter values, by repeatedly invoking the refine method of the fitter.
 ModelPoint eval(ModelPoint initialValue)
          Evaluate the optimization, using the argument as the initial values.
 OptimizerAlgorithm getAlgorithm()
          Accessor for algorithm field
 ModelPoint getCurrent()
          Accessor for current field
 ModelObjective getObjective()
          Accessor for objective field
 int getState()
          Accessor for state field
 ModelPoint initialize(ModelPoint initialValue)
          Initialize the iteration.
 OptimizerAlgorithm setAlgorithm(OptimizerAlgorithm value)
          Accessor for setting algorithm field
 ModelPoint setCurrent(ModelPoint value)
          Accessor for setting current field
 ModelObjective setObjective(ModelObjective value)
          Accessor for setting objective field
 int setState(int value)
          Accessor for setting state field
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

algorithm

protected OptimizerAlgorithm algorithm
The numerical method used to refine the model, by improving the value computed by theobjective.

This defines, following the OptimizerAlgorithm interface, a method refine which will be called iteratively by the eval method of the optimizer object.


objective

protected ModelObjective objective

state

protected int state

current

protected ModelPoint current
The current model estimate.
Constructor Detail

OptimizerBasic

public OptimizerBasic(OptimizerAlgorithm algorithm)
Create an optimizer with a given algorithm, but initially no specific model to fit.

OptimizerBasic

public OptimizerBasic(OptimizerAlgorithm algorithm,
                      ModelPoint start)
Create a complete optimizer with an algorithm and initialize it with a starting point (including the model objective).

The model definition in start will be used throughout the iteration.


OptimizerBasic

public OptimizerBasic(OptimizerAlgorithm algorithm,
                      ModelObjective model,
                      double[] start)
Define the model separately from parameters and objective.
Method Detail

getAlgorithm

public OptimizerAlgorithm getAlgorithm()
Accessor for algorithm field

setAlgorithm

public OptimizerAlgorithm setAlgorithm(OptimizerAlgorithm value)
Accessor for setting algorithm field

getObjective

public ModelObjective getObjective()
Accessor for objective field

setObjective

public ModelObjective setObjective(ModelObjective value)
Accessor for setting objective field

getState

public int getState()
Accessor for state field
Specified by:
getState in interface OptimizerIterator

setState

public int setState(int value)
Accessor for setting state field
Specified by:
setState in interface OptimizerIterator

getCurrent

public ModelPoint getCurrent()
Accessor for current field

setCurrent

public ModelPoint setCurrent(ModelPoint value)
Accessor for setting current field

initialize

public ModelPoint initialize(ModelPoint initialValue)
Initialize the iteration.

Evaluates the model for the supplied initial values (and may throw an exception doing so), then calls the fitting algorithm's initialize method.


eval

public ModelPoint eval()
                throws java.lang.Exception
The basic optimization loop, which iterates to compute the next set of parameter values, by repeatedly invoking the refine method of the fitter.

An exception may be thrown by the refine method, causing an exception from eval().


eval

public ModelPoint eval(ModelPoint initialValue)
                throws java.lang.Exception
Evaluate the optimization, using the argument as the initial values.

continueIteration

public boolean continueIteration(OptimizerAlgorithm opt,
                                 ModelPoint values)
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.

Specified by:
continueIteration in interface OptimizerIterator