Java中单变量非线性函数的最小发现 [英] Minimum finding for univariate nonlinear function in Java

查看:141
本文介绍了Java中单变量非线性函数的最小发现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种简单的方法来用Java完成MATLAB的fminsearch()所做的工作.我不需要像fminsearch那样通用,就我而言,我只想找到单变量非线性函数的最小值(函数和参数值最小).我不知道该函数的解析表达式,但是我可以轻松地对其进行评估.

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 minimum (function and parameter values at minimum) of a single-variable nonlinear function. 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?

注意:我看到apache的通用方法似乎有这样的东西(UnivariateOptimizer),但是大多数方法似乎已被弃用,我找不到如何使用它的很好的解释.与此相关的任何提示也都欢迎.

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. Any tips related to that are welcome as well.

谢谢!

推荐答案

Apache Commons Math 是开始使用Java进行数值计算的好地方.通过示例,最好通过 API文档各种类和方法的单元测试源代码.

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.

用户指南中引用的优化类正如您所指出的,已弃用.它们仍然可以被调用,但是最终它们当然会从库中逐步淘汰.由于我不知道的原因,正在进行的优化开发现在是在 optim 而不是 optimization 子包中进行的.

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.

对于单变量函数(局部最优)的最小化, Apache Commons Math 提供了 Brent 方法的实现.

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

这篇关于Java中单变量非线性函数的最小发现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆