xtol 和 ftol 使用 scipy.optimize 的 fmin() 有什么区别? [英] what is the difference between xtol and ftol to use fmin() of scipy.optimize?

查看:56
本文介绍了xtol 和 ftol 使用 scipy.optimize 的 fmin() 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始用一个非常简单的例子来使用函数 fmin,我尝试得到一个向量的值,该向量的乘法值最小:

I'm starting to use the function fmin with a very simple example and I try to get the values ​​of a vector that minimizes the value of their multiplication:

def prueba(x,y):
    print "valor1:",x[0],"\n"
    print "valor2:",x[1],"\n"
    print "valor3:",x[2],"\n"
    print "valor4:",x[3],"\n"
    min=x[0]*x[1]*x[2]*x[3]
    print min
    return min

sal = fmin(prueba,x0=array([1, 2, 3,4]),args="1",retall=1,xtol=0.5,ftol=0.5)#maxfun=1,maxiter=1,retall=1,args="1")

但是如果我不定义 xtol 和 ftol 出现:

but if I dont define xtol and ftol appears:

"Warning: Maximum number of function evaluations has been exceeded."

为此我使用参数xtolftol定义了算法的收敛性,但我仍然不明白它们之间有什么区别,我看起来一样,但如果我删除两者之一,我会再次收到警告.

For this reason I have defined the convergence of the algorithm using the parameters xtol and ftol,but i still don't understand what is the difference between them, I look the same, but if I delete one of the two I get the warning again.

xtolftol 到底有什么区别?,在这种情况下应该使用哪个?.

What exactly is the difference of xtol and ftol?, Which should use in this case?.

我已阅读文档:

其他参数

xtol:数字
xopt 中可接受的收敛相对误差.
ftol : 数字
func(xopt) 中可接受的收敛相对误差.

xtol : number
acceptable relative error in xopt for convergence.
ftol : number
acceptable relative error in func(xopt) for convergence.

我还是不明白

推荐答案

这是我的理解.它类似于 mathworks 函数 fminsearch.他们定义了这些值:

Here's my understanding. It's similar to the mathworks function fminsearch. They define these values:

TolFun:函数值的终止容差TolX:x 上的终止容差

TolFun: Termination tolerance on the function value TolX: Termination tolerance on x

随着搜索以迭代方式进行.x 的值从一次迭代到另一次迭代的差异越来越小,直到它不再重要,您还不如完成.功能容差也是如此.在您的示例中,对 prueba 进行评估,并且其从迭代到迭代的返回值之间的差异越来越小,直到它也无关紧要.你问你应该使用哪个.这可能有点实验方法.过去我经常使用:

As the search proceeds in its iterative fashion. The difference in the values of x from one iteration to another become smaller and smaller, until it doesn't matter any more and you might as well be done. Same goes for the function tolerance. In your example, prueba is evaluated and the difference between its return value from iteration to iteration gets smaller and smaller, until it doesn't matter either. You asked which you should use. This can bit a bit of an experimental approach. In the past I have often used:

xtol = 1e-6;
ftol = 1e-6;

它似乎可以很好地解决许多问题,是一个很好的起点.您可能会发现,如果需要调整,这将是显而易见的.就像可怕的收敛时间.数据拟合度不佳等.希望这会有所帮助.

It seems to scale well to many problems, and is a good place to start. You will likely find that if one needs to be tweaked, it will be obvious. Like horrid convergence times. Poor goodness of fit in the data, etc. Hope this helps.

这篇关于xtol 和 ftol 使用 scipy.optimize 的 fmin() 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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