org.omegahat.Numerics.Optimizers
Class BasicOptimizer
java.lang.Object
|
+--org.omegahat.Numerics.Optimizers.BasicOptimizer
- All Implemented Interfaces:
- OptimizerIterator
- Direct Known Subclasses:
- NotifyingOptimizer
- public class BasicOptimizer
- extends java.lang.Object
- implements OptimizerIterator
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
fitter
protected OptimizerAlgorithm fitter
- Misnamed field that stores the encapsulation of the
objective function and the mechanism for determining
the next parameter set, i.e. the move to a position hopefully
closer to the optimum of the objective function.
convergenceChecker
protected ConvergenceChecker convergenceChecker
- An optionally specifed object that can determine whether convergence
has occurred and that the iteration should terminate.
This may be a simple numeric computation, something that stores the history
of the parameters and associated "value" of the operand. It can also
even solicit input from the user either textually or graphically to
determine if an adequate solution has been reached.
numIterations
protected long numIterations
maxNumIterations
protected long maxNumIterations
BasicOptimizer
public BasicOptimizer(OptimizerAlgorithm fitter)
BasicOptimizer
public BasicOptimizer(OptimizerAlgorithm fitter,
ConvergenceChecker convergence)
hasConverged
public boolean hasConverged(OptimizerAlgorithm f,
ParameterSet values)
throws java.lang.Exception
- Test for convergence of the iteration.
The BasicOptimizer class knows nothing about convergence, except that if
someone set the maximum number of iterations and that limit has been exceeded, then
it's time to quit.
handleError
public boolean handleError(java.lang.Throwable e)
eval
public ParameterSet eval()
eval
public ParameterSet eval(ParameterSet initialValues)
- The basic optimization loop.
Calls the algorithm in a loop to compute the next set of parameter values,
by invoking the refine method of the fitter.
The object's hasConverged method is called both before and after calling the
refine method (if this method does a fair amount of work you might want it
to check immediately that it got different parameter values from the previous call).
If the internal convergence test does not break out of the loop, a hook is called, which
does nothing much in this class, but notifies listeners in the subclass NotifyingOptimizer.
Rather than build in hard-coded tests, the structure of this class and its subclasses
allows very general techniques for testing convergence to be added
at three different levels:
- In the algorithm's hasConverged
method, for tests that are intrinsic to the numerical technique;
- By setting a ConvergenceChecker
method in this optimizer object itself that makes a convergence
test directly;
- Through an IterationListener object that is notified, makes a
test, and throws an InterruptedIterationException, which the
eval method will catch (and simply
treat as a break out of the iteration).
It is also possible to throw other exceptions from listeners (or from
errors in the computations, of course). However, the BasicOptimizer
class catches these and ignores them, except for printing an error
message and a stack trace.
completedIteration
public void completedIteration(ParameterSet values)
- Hook method called after each iteration, provided the iteration did not result
in convergence.
The interesting version of this method notifies listeners (see the NotifyingOptimizer class).
addToHistory
public long addToHistory(ParameterSet s)
numIterations
public long numIterations()
numIterations
public long numIterations(long v)
maxNumIterations
public long maxNumIterations()
maxNumIterations
public long maxNumIterations(long n)
fitter
public OptimizerAlgorithm fitter()
fitter
public OptimizerAlgorithm fitter(OptimizerAlgorithm f)
convergenceChecker
public ConvergenceChecker convergenceChecker()
convergenceChecker
public ConvergenceChecker convergenceChecker(ConvergenceChecker c)