如何编写scipy.optimize.minimize()的参数 [英] how to write the scipy.optimize.minimize()'s parameter

查看:785
本文介绍了如何编写scipy.optimize.minimize()的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用scipy.optimize.minimize()获得最小值,它是x,y

I am using scipy.optimize.minimize() to get the minimum value and it's x,y

    def fun(self):
    cols=self.maintablewidget.columnCount()-1
    for k in range(3,cols):
        for i in range(1,k):
            d=string.atof(self.maintablewidget.item(i-1,k-1).text())
            xi=string.atof(self.xytablewidget.item(i-1,0).text())
            yi=string.atof(self.xytablewidget.item(i-1,1).text())
            f=lambda x,y: np.sum((np.sqrt((x-xi)**2+(y-yi)**2)-d)**2)

        res=optimize.minimize(f,0,0)#I do not know how to give the optimize.minimize's parameter
        print(res['x'][0])
        print(res['x'],res['fun'])

我不知道如何给出optimize.minimize的参数.有人可以向我解释我该怎么做吗?

I do not know how to give the optimize.minimize's parameter. Can someone explain to me how I can do this?

推荐答案

看看

Take a look at the documentation. Essentially if your function depends on two parameters, you need to pass them as x[0] and x[1] instead of x and y. So in the end you function will depend on a single vector parameter x.For example:

f = lambda x: np.sum((np.sqrt((x[0]-xi)**2+(x[1]-yi)**2)-d)**2)
res = optimize.minimize(f, (initial_x, initial_y))

最小值将在res.x中,并将具有向量[x, y]的形式.

The minimum will be in res.x and will have the form of a vector [x, y].

这篇关于如何编写scipy.optimize.minimize()的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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