Giiovanna
Giiovanna

Reputation: 442

Constrained optimization in SciPy

I need, for a simulation, to find the argument (parameters) that maximizes a multivariable function with constraints.

I've seen that scipy.optimize.minimize gives the minimum of a function (and, the maximum of the minus function) of a given function and I can use constraints and bounds. But, reading the doc, I've find out that it returns the minimum value but not the parameter that minimizes it (am I right?)

scipy.optiminize.fmin does give the parameter that minimize the function, but this doesn't accept bounds or contraints.

Looking in numpy, there is a function called argmin but it takes a vector as argument and return the "parameter" that minimizes it.

Is there such a function that, like minimize, accept constraint and, like fmin, return the parameter that minimize the function?

Thanks in advance.

Upvotes: 3

Views: 5440

Answers (2)

Rob Falck
Rob Falck

Reputation: 2704

The returned value of scipy.optimize.minimize is of type Result:

Result contains, among other things, the inputs (x) which minimize f.

Upvotes: 1

Fred Foo
Fred Foo

Reputation: 363477

The new minimize function takes a bounds argument when used with certain optimization algorithms. In older SciPy, you need to call one of these algorithms directly, e.g. fmin_l_bfgs_b.

Upvotes: 1

Related Questions