Looking directly at the BOBYQA code , it actually seems that the problem is that you did not explicitly specify any bounds on the variables. Line 2401 ( setup method) is read as follows:
boundDifference[i] = upperBound[i] - lowerBound[i];
In the doOptimze method doOptimze before calling setup boundaries are set using the following methods:
final double[] lowerBound = getLowerBound(); final double[] upperBound = getUpperBound();
These methods are defined in BaseMultivariateOptimizer as follows:
public double[] getLowerBound() { return lowerBound == null ? null : lowerBound.clone(); }
(and similarly for getUpperBound() ). But lowerBound and upperBound in BaseMultivariateOptimizer are set only if the optimization data in the optimize call contains boundary information. If no borders are specified in the optimize call, you should get a NullPointerException .
Looking at the BOBYQA test code , it seems that this should be enough if you add the following argument to the optimize call:
SimpleBounds.unbounded(point.length)
Having said that, I also donβt think that you can completely solve your problem using any of the nonlinear optimizers in Apache Commons Math, since, as far as I can tell, none of these optimizers can handle linear or nonlinear constraints. I recommend that you instead take a look at, for example, the Michael Powell COBYLA2 algorithm. I ported the original FORTRAN code of this algorithm to Java, and you can find the code here and.
source share