|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object
|
+--org.omegahat.Numerics.Optimizers.OptimizerBasic
|
+--org.omegahat.Numerics.Optimizers.Optimizer
The standard optimizer class. Objects from this class iterate by calling the initialize, refine, and wrapup methods of an OptimizerAlgorithm object.
Each iteration is preceded by notifying all the listeners registered with the optimizer object. By default, this includes a DefaultListener that checks the number of iterations and some standard numeric conditions for convergence.
This class extends OptimizerBasic, which provides the iteration, but does not implement event listeners for control. If you want to handle control by a mechanism other than listeners, subclass that class or otherwise implement the OptimizerIterator interface.
| Field Summary | |
static int |
BACKGROUND
|
protected BackgroundTaskManager |
backgroundManager
This manager takes care of the background, or non-blocking, listeners. |
static int |
COMPLETION
|
protected java.util.EventListener |
defaultListener
|
static int |
INFORMATION
|
static int |
INITIALIZATION
symbolic constants to index the array of listeners. |
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 | |
Optimizer(OptimizerAlgorithm fitter)
|
|
Optimizer(OptimizerAlgorithm fitter,
ModelObjective model,
double[] start)
|
|
Optimizer(OptimizerAlgorithm fitter,
ModelPoint start)
|
|
| Method Summary | |
void |
addBackgroundListener(IterationListener l)
|
void |
addConvergedListener(IterationListener l)
A listener to be called only on completion. |
void |
addInformationListener(IterationListener l)
Add an information listener to be called on each step in the iteration. |
void |
addInitializationListener(IterationListener l)
A listener to be called only on initialization. |
void |
addIterationListener(IterationListener l)
Add a listener to be called at each step in the iteration with the option of controlling the convergence. |
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. |
java.util.EventListener |
createDefaultListener()
This must be a separate method so as to allow people to override it. |
java.util.EventListener |
dropListener()
Drop the last iteration listener added. |
java.util.EventListener |
dropListener(java.util.EventListener l)
Drop this listener object. |
ModelPoint |
eval()
Carry out the iteration. |
java.util.EventListener |
getDefaultListener()
Accessor for defaultListener field |
java.util.Vector[] |
getListeners()
|
boolean |
hasListener(java.util.EventListener l,
int type)
Check whether this object is a listener of the given type. |
ModelPoint |
initialize(ModelPoint initialValue)
Initialize the optimizer with the values supplied. |
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. |
java.util.EventListener |
setDefaultListener()
Initialize the default listener to an object from the DefaultListener class. |
java.util.EventListener |
setDefaultListener(java.util.EventListener value)
Accessor for setting defaultListener 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 |
public static final int INITIALIZATION
public static final int COMPLETION
public static final int ITERATION
public static final int BACKGROUND
public static final int INFORMATION
public static final int NUM_LISTENER_VECTORS
protected java.util.Vector[] listeners
protected BackgroundTaskManager backgroundManager
protected java.util.EventListener defaultListener
| Constructor Detail |
public Optimizer(OptimizerAlgorithm fitter)
public Optimizer(OptimizerAlgorithm fitter,
ModelPoint start)
public Optimizer(OptimizerAlgorithm fitter,
ModelObjective model,
double[] start)
| Method Detail |
public void make()
Called from each of the constructors. Sets up the listener structures and adds a DefaultListener object to the iteration listeners.
public ModelPoint initialize(ModelPoint initialValue)
Iteration listeners that implement CounterListener will have their count reset to 0.
Note that this method does not call the initializer of the optimization algorithm. Whether the algorithm should be reset between one iteration and the next is a matter of strategy, and should not be forced on the user. To reset the algorithm, use getAlgorithm().initialize(initialValue, opt)
initialize in class OptimizerBasicpublic java.util.EventListener createDefaultListener()
public ModelPoint eval()
throws java.lang.Exception
eval in class OptimizerBasic
public void notifyListeners(ModelPoint values,
int type)
public void notifyListeners(IterationEvent event)
public void notifyInformationListeners(IterationEvent ev)
public void notifyBackgroundListeners(IterationEvent event)
The actual performance of the corresponding tasks is the responsibility of an object of class BackgroundTaskManager.
public boolean continueIteration(OptimizerAlgorithm opt,
ModelPoint values)
OptimizerBasicThe 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.
continueIteration in class OptimizerBasicpublic void addListener(java.util.EventListener l)
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.
public void addIterationListener(IterationListener l)
public void addInformationListener(IterationListener l)
public void addBackgroundListener(IterationListener l)
public void addInitializationListener(IterationListener l)
public void addConvergedListener(IterationListener l)
public void addStepListener(IterationListener l)
public boolean addListener(java.util.EventListener l,
int type)
public boolean hasListener(java.util.EventListener l,
int type)
public java.util.EventListener dropListener(java.util.EventListener l)
public java.util.EventListener dropListener()
Returns the listener dropped, or null if there were none.
When called after creating a standard optimizer (one that is an instance of
class OptimizerBasic or its extensions),
this drops the default listener, which checks for the number of iterations and
some default convergence conditions.
public java.util.EventListener getDefaultListener()
defaultListener fieldpublic java.util.EventListener setDefaultListener(java.util.EventListener value)
defaultListener fieldpublic java.util.EventListener setDefaultListener()
public java.util.Vector[] getListeners()
public java.util.Vector[] setListeners(java.util.Vector[] v)
public BackgroundTaskManager backgroundManager()
public BackgroundTaskManager backgroundManager(BackgroundTaskManager m)
public BackgroundTaskManager backgroundManager(BackgroundTaskManager m,
boolean start)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||