简体   繁体   English

scipy.optimize.minimize()中的“ fun”应采用哪种格式?

[英]Which format should the “fun” in scipy.optimize.minimize() have?

I would like to use the scipy.optimize.minimize() function, but I have a small problem : in the official documentation , it is said that the function take as argument an "objective function", without further precision. 我想使用scipy.optimize.minimize()函数,但是我有一个小问题:在官方文档中 ,据说该函数将“目标函数”作为参数,但没有进一步的精度。

So i wanted to know a few things : let's suppose here that the function I want to optimize is f(x_1,y_1,x_2,y_2,...,x_n,y_n) , n not constant. 所以我想知道一些事情:让我们在这里假设我要优化的函数是f(x_1,y_1,x_2,y_2,...,x_n,y_n) ,n不是常数。

1) Is it possible to put other arguments in the function ? 1)是否可以在函数中放置其他参数? for example, f(stuff,x1,...) ? 例如f(stuff,x1,...)

2) As n is not constant, i would rather use a list (something like that : f([x_1,y_1,x_2,y_2,...,x_n,y_n] ). Will scipy understand this ? 2)由于n不是常数,我宁愿使用一个列表(类似这样的东西: f([x_1,y_1,x_2,y_2,...,x_n,y_n] )。

Thank you in advance for answers ! 预先感谢您的答复!

Ok, I've got some elements of answers : 好的,我有一些答案的要素:

As hjpaul said, I used an array to solve my problem, and it works ! 正如hjpaul所说,我使用了一个数组来解决我的问题,并且有效! One should note that if you give him a n-dimensional array, the function will transform it automatically in 1d-array (what blocked me at a moment). 应该注意的是,如果给他一个n维数组,该函数将自动将其转换为1d数组(这使我一时受阻)。

The syntax sp.optimize.minimize(fun,array,other_args_tuple) is probably the best, but using global variable works too. 语法sp.optimize.minimize(fun,array,other_args_tuple)可能是最好的,但是使用全局变量也可以。

Thank you everyone (and especially hpaulj) for your answers. 谢谢大家(尤其是hpaulj)的回答。 I didn't read accurately enough the documentation, that'll teach me ^^ 我没有足够正确地阅读文档,这会教给我^^

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

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