Questions tagged [scipy-optimize-minimize]
446 questions
4
votes
1 answer
Scipy.optimize.minimize is not giving the minimum value even though it sees that value
I am using scipy.optimize.minimize to find optimal parameters for my objective function.
My code :
import numpy as np
from scipy.optimize import minimize
from scipy.optimize import Bounds
bounds =…

chink
- 1,505
- 3
- 28
- 70
4
votes
0 answers
scipy.optimize How do I constrain x values to integers inside my minimize function?
I am trying to use minimize function from scipy.optimize
From the documentation I was able to set bounds for x (For example: [0,12]). However I'm unable to figure out how to set them as integers.
ans = minimize(lambda x:…

ThReSholD
- 668
- 10
- 15
4
votes
4 answers
cannot import minimize in scipy
I am working with scipy trying to test out the Nelder-Mead simplex algorithm. I am exactly following the example code shown here: http://docs.scipy.org/doc/scipy/reference/tutorial/optimize.html
This line causes an error:
from scipy.optimize import…

Tim Sotman
- 43
- 1
- 1
- 3
3
votes
0 answers
The most effective way to find global maximum of a function with a lot of parameters? (500+)
I'm trying to find global maximum of a Python function with a lot of parameters (500+). Unfortunately I'm unable to make a derivative of this function - what the function does is basically it loops several times over np.array of shape ~ (150000,50)…

pepazdepa
- 117
- 8
3
votes
1 answer
3D array minimization (optimization)
Suppose I have the following 5x5x5 3D array, consisting of binary values:
space = [
[[0,1,0,0,1], [1,0,0,1,0], [0,1,0,1,1], [0,0,0,1,1], [0,1,1,0,1]],
[[1,1,1,0,1], [0,0,0,1,0], [0,0,1,1,1], [0,0,0,1,1], [0,1,0,0,0]],
[[0,1,0,1,0], [1,1,0,0,0],…

Coto TheArcher
- 367
- 3
- 13
3
votes
1 answer
How to hide `delta_grad == 0.0` warning in scipy.optimize.minimize?
I have a loop that executes several hundred optimizations using scipy.optimize.minimize. Unfortunately, I keep getting this annoying warning:
C:\Users\Leonidas\Anaconda3\lib\site-packages\scipy\optimize\_hessian_update_strategy.py:186: UserWarning:…

Leonidas
- 613
- 1
- 6
- 23
3
votes
0 answers
How to find optimum of a function with restriction to the sum of the input values in scipy?
I have a linear function for two input value according the following (params has been computed already):
def objective(x):
return x[0] * params[0] + x[1] * params[1] + params[2]
Now I want to calculate the optimum (minimum) of the function with…

Fredrik
- 411
- 1
- 3
- 14
3
votes
1 answer
Scipy minimize returns a higher value than minimum
As a part of multi-start optimization, I am running differential evolution (DE), the output of which I feed as initial values to scipy minimization with SLSQP (I need constraints).
I am testing testing the procedure on the Ackley function. Even in…

user64150
- 59
- 5
3
votes
1 answer
Can scipy.optimize.minimize(..., method='SLSQP', ...) use multiple cores?
I am using scipy.optimize.minimize for nonlinear constrained optimization.
I tested two methods (trust-constr, SLSQP).
On a machine (Ubuntu 20.04.1 LTS) where proc gives 32,
scipy.optimize.minimize(..., method='trust-constr', ...) uses multiple…

ChangYong Oh
- 31
- 1
3
votes
1 answer
Maximize objective using scipy (by kelly criterium)
I have the following two pandas dataframes: new & outcome
new = pd.DataFrame([[5,5,1.6],[0.22,0.22,0.56]]).T
new.index = ['Visitor','Draw','Home']
new.columns = ['Decimal odds', 'Win prob']
new['Bet amount'] = np.zeros((len(new),1))
With output:
…

Herwini
- 371
- 1
- 19
3
votes
2 answers
Python scipy.minimize: overflow encountered in double_scalars and invalid value encountered in double_scalars
I built a custom EST (Exponential Smoothing) Model. First I define a function which includes the Parameter definitions which are passed to a second function doing the computation and returning the forecasting Errors. These are then squared and…

MatthiasHerp
- 271
- 3
- 9
3
votes
1 answer
SciPy Optimizer gives result that do not satisfy constraints
I am using scipy.optimize.minimize to solve a problem, but the result given by the package violates the constraint.
The case is mad simple where only one objective function and only one constraint are given. Here is the code:
import math
…

Wilson
- 125
- 8
3
votes
0 answers
scipy minimize not exploring all sample space during optimization
I want to optimize only two parameters alpha and beta of a function and I am using scipy.optimize.minimize function with TNC algorithm. The objective function is mean square error of observed versus predicted. Both alpha and beta can vary between…

Ather Cheema
- 416
- 2
- 14
3
votes
1 answer
How does scipy.optimize.minimize take the derivative of the loss function?
I am trying to figure out how the scipy.optimize.minimize works in machine learning. So far i understand that you pass it a loss function, so that it can find the parameter values that gives you the lowest loss. But as far as i understand, it first…

Magnus
- 31
- 3
3
votes
0 answers
non linear optimization with incomplete gamma function in constraint in scipy
I want to solve the following optimization problem with scipy (python3):
where I[.,.] is the "incomplete gamma function" (scipy.special.gammainc)
I followed the scipy optimization guide and came up with this code:
from scipy.special import…

Andreas Ziegler
- 347
- 2
- 12