Maximize a function with many parameters (python)

2020-02-28 02:39发布

first, let me say that I lack experiences with scientific math or statistics - so this might be a very well-known problem, but I don't know where to start.

I have a function f(x1, x2, ..., xn) where I need to guess the x'ses and find the highest value for f. The function has the following properties:

  • the total number or parameters is usually around 40 to 60, so a brute-force approach is impossible.

  • the possible values for each x range from 0.01 to 2.99

  • the function is steady, meaning that a higher f value means that the guess for the parameters is better and vice versa.

So far, I implemented a pretty basic method in python. It initially sets all parameters to 1, randomly guesses new values and checks if the f is higher than before. If not, roll back to the previous values. In a loop with 10,000 iterations this seems to work somehow, but the result is propably far from being perfect.

Any suggestions on how to improve the search for the optimal parameters will be appreciated. When googling this issue things linke MCMC came up, but that seems like a very advanced method and I would need a lot of time to even understand the method. Basic hints or concepts would help me more than elaborated methods and algorithms.

3条回答
孤傲高冷的网名
2楼-- · 2020-02-28 03:08

Don't do it yourself. Install SciPy and use its optimization routines. scipy.optimize.minimize looks like a good fit.

查看更多
在下西门庆
3楼-- · 2020-02-28 03:10

You could always use a list as one parameter unless your task says you cannot do that. A list would make it much easier.

查看更多
兄弟一词,经得起流年.
4楼-- · 2020-02-28 03:14

I think you want to take a look at scipy.optimize (http://docs.scipy.org/doc/scipy-0.10.0/reference/tutorial/optimize.html). A maximization is the minimization of the -1*function.

查看更多
登录 后发表回答