Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maximize a function with many parameters (python)

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.

like image 886
David Avatar asked Jul 23 '13 15:07

David


People also ask

Can a function take multiple parameters in Python?

We can pass multiple arguments to a python function by predetermining the formal parameters in the function definition.

What is the maximum number of arguments a function can take in Python?

In Python, we can define two types of parameters that have variable lengths. They can be considered special types of optional parameters. In other words, there is no limit to the number of arguments that are passed to the parameter when we call this function.

What is the maximum number of arguments acceptable to the range expression?

The range function takes one or at most three arguments, namely the start and a stop value along with a step size.

Can a Python function take unlimited arguments?

Yes. You can use *args as a non-keyword argument. You will then be able to pass any number of arguments. As you can see, Python will unpack the arguments as a single tuple with all the arguments.


1 Answers

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

like image 101
user2357112 supports Monica Avatar answered Oct 31 '22 22:10

user2357112 supports Monica