简体   繁体   English

Java中单变量非线性函数的最小发现

[英]Minimum finding for univariate nonlinear function in Java

I'm looking for a simple way to accomplish in Java what MATLAB's fminsearch() does. 我正在寻找一种简单的方法来用Java完成MATLAB的fminsearch()所做的事情。 I don't need to be as general as fminsearch, in my case I only want to find the minimum (function and parameter values at minimum) of a single-variable nonlinear function. 我不需要像fminsearch那样通用,就我而言,我只想找到单变量非线性函数的最小值(函数和参数值最小)。 I don't know the analytical expression of the function, but I can evaluate it easily. 我不知道该函数的解析表达式,但是我可以轻松对其进行评估。

Do you know of a library that performs this, or of an easy algorithm I could re-implement? 您知道执行此操作的库,还是可以重新实现的简单算法?

Note: I saw that apache's common-math seems to have something like this (UnivariateOptimizer), but most of the methods seem to be deprecated and I couldn't find a good explanation how to use it. 注意:我看到apache的通用方法似乎有这样的东西(UnivariateOptimizer),但是大多数方法似乎已被弃用,我找不到如何使用它的很好的解释。 Any tips related to that are welcome as well. 也欢迎与此相关的任何提示。

Thanks! 谢谢!

Apache Commons Math is generally a good place to start for numerical computations in Java. 通常, Apache Commons Math是开始使用Java进行数值计算的好地方。 Usage is best learnt by example, looking at the API documentation and the unit test source code for the various classes and methods. 通过示例,通过查看API文档以及各种类和方法的单元测试源代码 ,可以最佳地了解用法。

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. 为了使单变量函数(局部最优)最小化, Apache Commons Math提供了Brent方法的实现。 Usage is outlined in the unit tests of the BrentOptimizer , from which I have copied this excerpt: BrentOptimizer单元测试中概述了用法,我复制了以下摘录:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM