[math] Callback interface for Optimizer

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[math] Callback interface for Optimizer

ole ersoy
Hi,

Just thought I'd share a concrete callback interface that I think this may work well for optimizers in general, even though I'm just working on Levenberg Marquardt ATM.  The interface is pasted below, but roughly here's how it works.

//Create an instance of an observer implementation.
OptimizationObserver observer = new ObserverImplementation();
//Drop it into the optimizer that implements Optimizer
Optimizer optimizer = new WhateverOptimizer(observer, problem);
//Fire it up (Note void return type)
optimizer.start(10000 = number of allotted iterations);

Wait for the success, end, or error to be communicated through the Observer.notify() method per the optimizer.status field which is an instance of the OptimizationProtocol interface and that is implemented by an enum specific to the optimizer.

If the optimizer converges, then the Optimizer.status field is set to success (Protocol.SUCCESS), and the optimizer is passed back via the OptimizationObserver.notify(Optimizer optimizer) method.  The optimum result can be retrieved per the interface double[] Optimizer.getResult().  If the optimizer does not converge then optimizer status is set to Protocol.END before the optimizer is passed back to the observer.  If there's an error, then the status is set to indicate the error code (Protocol.ERROR__TOO_SMALL_COST_RELATIVE_TOLERANCE).  Here's the observer interface.

public interface OptimizationObserver {

     /**
      * Called when optimizer converges (Protocol.SUCCESS), ends (Protocol.END),
      * or encounters an error.
      *
      * @param optimizer
      */
     void notify(Optimizer optimizer);
}

So within the implemented notify method we would do something like:

{
    if (optimizer.getStatus == Protocol.SUCCESS) {
    //Champagne!!
    Number[] result = optimizer.getResult();
}
    else if (optimizer.getStatus == Protocol.END) {
    //Do another round of iterations?
    optimizer.start(10000);
    //or
    //Just use the result - It's 90% optimal.
    Number[] result = optimizer.getResult();
}
    else if (optimizer.getStatus == Protocol.BLACKHOLE_ERROR) {
    //This is bad - Throw in the towel
}

Thoughts?

Cheers,
Ole

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]