I\'m looking for a simple way to accomplish in Java what MATLAB\'s fminsearch() does. I don\'t need to be as general as fminsearch, in my case I only want to find the minimu
Apache Commons Math is generally a good place to start for numerical computations in Java. Usage is best learnt by example, looking at the API documentation and the unit test source code for the various classes and methods.
The optimization classes that are referenced in the user guide are, as you have noted, deprecated. They can still be called, but eventually they will of course be phased out from the library. For reasons unknown to me, ongoing optimization development is now taking place in the optim rather than the optimization sub-package.
For univariate function (local optimum) minimization, Apache Commons Math provides an implementation of the Brent method. Usage is outlined in the unit tests of the BrentOptimizer
, from which I have copied this excerpt:
@Test
public void testSinMin() {
UnivariateFunction f = new Sin();
UnivariateOptimizer optimizer = new BrentOptimizer(1e-10, 1e-14);
Assert.assertEquals(3 * Math.PI / 2,
optimizer.optimize(new MaxEval(200),
new UnivariateObjectiveFunction(f),
GoalType.MINIMIZE,
new SearchInterval(4, 5)).getPoint(), 1e-8);
Assert.assertTrue(optimizer.getEvaluations() <= 50);
Assert.assertEquals(200, optimizer.getMaxEvaluations());
...
}