Questions tagged [scipy-optimize-minimize]
446 questions
0
votes
2 answers
scipy.minimize ValueError: The user-provided objective function must return a scalar value
I had read the documentation and tried to understand how to work with scipy.optimize.minimize(), but I can not.
from scipy.optimize import minimize
def f(x):
return x**2
x0 = [-2.0, -1.0, 0.0, 1.0, 2.0]
res = minimize(f,…

ray_med
- 1
- 2
0
votes
1 answer
Python scipy.minimize
I have a question about python scipy.minimize, I know if
x0 = np.array([0.5, 0])
then I can set the bound like this
bnds = ((0, None), (0, None))
but if my x0 has 1000 terms, and I want each of them to be in range (0,5), how should I set my bound?
0
votes
0 answers
sci.py minimize - constrain function argument
I need to constrain a variable that is argument of optimization below a certain value EQ<1000.
#function that produces the variable is the following:
def fEQ(iEQ, iC, iTATM, index):
if index==0:
return iC[0]
else:
return…

tf_247
- 1
- 1
0
votes
1 answer
Can I send arguments to a constraint function using scipy.optimize.NonlinearConstraint?
I have a bounded optimization problem with nonlinear constraints that I am trying to solve. The nonlinear constraint function requires arguments and this is where I fail to make it work. Below is the structure I follow. How do I send the arguments…

blvb
- 89
- 1
- 8
0
votes
0 answers
How do I fit a multi-linear regression model with a Loss Function using the scipy.minimize function?
I'm currently learning multilinear regression and I'm stuck on this question that wants me to define a function that will "Minimize the average loss calculated from using different theta vectors, and estimate the optimal theta for the model".
from…

user3085496
- 175
- 1
- 2
- 10
0
votes
1 answer
Constraints not working in Optimization using Scipy
I am trying to solve a profit maximization problem. There are a few promotion schemes run by the company. I make an objective function for profit maximization subject to some constraints. I want to make a constraint which says the company cannot run…

Himanshu Singh
- 5
- 2
0
votes
1 answer
Minimize function with scipy
I'm trying to do one task, but I just can't figure it out.
This is my function:
1/(x**1/n) + 1/(y**1/n) + 1/(z**1/n) - 1
I want that sum to be as close to 1 as possible.
And these are my input variables (x,y,z):
test = np.array([1.42, 5.29,…
user14269391
0
votes
0 answers
scipy optimization model returns all nan solutions
I have the code below where I'm trying to calculate the max sharpe ratio solution to the efficient frontier. I'm trying to minimize the volatility and maximize the sharpe ratio (by minimizing the negative of the sharpe ratio). however my…

user3476463
- 3,967
- 22
- 57
- 117
0
votes
1 answer
Scipy Minimize with Linear Constraints Tried to Call Objective Function at nan
I'm running a Python code I wrote that involves using scipy.optimize.minimize method='trust-constr'. The optimization involves a set of linear constraints, which I pass to Python using scipy.optimize.LinearConstraint where I pass in a matrix (the…

J.D.
- 139
- 4
- 14
0
votes
1 answer
How to use the output args of fun as the input args of jac in scipy.optimize.minimize?
I'm working with scipy.optimize library.
In the adjoint variable method, some of the resulted values from the objective function are needed to compute the jacobian.
Is that possible to use them in the jacobian function without using global…

Minsik Seo
- 15
- 2
0
votes
1 answer
scipy.optimize.minimize with constraints does not work as expected
I would like to find optimal solution for the problem discribed in the attached figure https://i.stack.imgur.com/W6fhf.jpg
My code is
from scipy.optimize import minimize
def create_constraints(t, tau, ub):
constraints = [{
'type': 'ineq',
…

dberezin
- 46
- 5
0
votes
0 answers
Linear regression with two datasets which are weighed differently. How to minimize the error?
I am inexperienced with minimization functions and I could not find a solution to my problem. From what I understand I have to have a function to minimize, however the function that I wrote returns errors.
Problem description: I have two datasets,…

Burbs
- 72
- 6
0
votes
1 answer
Pull non-minimized values out of function being minimized with SciPy.optimize.minimize
I am having trouble pulling out values out of a function that I am trying to optimize. The code looks similar to what follows. I want to minimize c by changing x through scipy.optimize.minimize, but am also trying to pull a and b out of the function…
0
votes
1 answer
Determining optimal bins to bin the data
I have X,Y data which i would like to bin according to X values.
However, I would like to determine the optimal number of X bins that satisfy a condition based on the resulting bin intervals and average Y of each bin. For example if i…

Jamal
- 45
- 9
0
votes
0 answers
Finding the minimum using fmin()
I am trying to minimize the "function()" with respect to two parameters. I have done so by creating mesh arrays and used them in the above "function()" to return similar meshed array values. However, upon using "fmin()" to find the minimum, the…

Karthik
- 113
- 1
- 8