本文介绍了将2D参数传递到numpy.optimize.fmin错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个函数PushLogUtility(p,w,f),我希望针对固定的p(9xk列表)和w(2xk)列表优化w.r.t f(2xk)列表.

I currently have a function PushLogUtility(p,w,f) that I am looking to optimise w.r.t f (2xk) list for fixed p (9xk list) and w (2xk) list.

我正在使用scipy.optimize.fmin函数,但是由于f是二维的,因此我会遇到错误.我已经编写了以前的函数LogUtility(p,q,f),它传递了一维输入,并且可以正常工作.

I am using the scipy.optimize.fmin function but am getting errors I believe because f is 2-dimensional. I had written a previous function LogUtility(p,q,f) passing a 1-dimensional input and it worked.

似乎有一个选择是将pwf写入一维列表,但这将是耗时且可读性差的.有什么方法可以使fmin使用2D输入优化功能吗?

One option it seems is to write the p, w and f into 1-dimensional lists but this would be time-consuming and less readable. Is there any way to make fmin optimise a function with a 2D input?

推荐答案

似乎实际上不可能将2D列表传递给numpy.optimize.fmin.但是,使输入f变平并不是什么大问题,虽然它使代码更难看,但现在可以进行优化了.

It seems it is in fact impossible to pass a 2D list to numpy.optimize.fmin. However flattening the input f was not that much of a problem and while it makes the code slightly uglier, the optimisation now works.

有趣的是,我还在Matlab中对优化进行了编码,该优化的确将2D输入输入到其fminsearch函数中.这两个程序都给出相同的输出(y).

Interestingly I also coded the optimisation in Matlab which does take 2D inputs to its fminsearch function. Both programs give the same output (y).

这篇关于将2D参数传递到numpy.optimize.fmin错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 04:04