Maximize a function with many parameters (python)

David picture David · Jul 23, 2013 · Viewed 22.8k times · Source

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.

Answer

user2357112 supports Monica picture user2357112 supports Monica · Jul 23, 2013

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