Minimum finding for univariate nonlinear function in Java

后端 未结 1 445
广开言路
广开言路 2021-01-14 08:34

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

1条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-14 08:59

    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());
        ...
    }
    

    0 讨论(0)
提交回复
热议问题