493
questions
0
votes
1
answer
33
views
NonlinearConstraint in SciPy Optimize not working with vector bounds?
I asked ChatGPT and it wasn't helpful. Basically I want to implement a constraint on a Transformed vector of X, let's say T(X). How do I do that? Here is my code:
def TransformFunction(X):
...
0
votes
0
answers
77
views
`scipy.optimize.minimize` gives different results on GCP and Mac
SciPy's minimize() gives different results on different machines:
sp.optimize.minimize(cost_function, x_init, bounds=x_bounds, args=args_in, method='SLSQP', options={'maxiter': sim_config['maxiter'], '...
0
votes
1
answer
106
views
SciPy Minimize Constrain Around Internal Parameter, Not Input
EDIT 1: This question has been completely modified for improved clarity and to better state my intent. The original post is at the end.
I think a lot of people are confused by my example code. It was ...
0
votes
1
answer
36
views
Using Preconditioners in scipy.minimize
Can I use Jacobi Preconditioning for the inner CG step in Truncated Newton Conjugate implementation of scipy?
The options for the TNC solver do not include any support for preconditioning. I'm ...
0
votes
1
answer
29
views
BFGS algorithm finding almost good parameters but not converging with scipy.minimize()
I am estimating an Interval Regression model. I wrote my likelihood function (see intreg, STATA) as stated bellow, and compared my results with STATA. I am finding almost exactly (within 0.001) same ...
0
votes
0
answers
23
views
Issue with _make_nonlinear_constraints() and scipy.minimize
I'm currently working on a project that involves multi-fidelity optimization using BoTorch. I'm trying to optimize an acquisition function, but I keep encountering a RuntimeError when I run the ...
1
vote
1
answer
63
views
SciPy Minimization Convergence Problems for Objective Function with Small Values and Numerical Derivatives
I’m having issues with minimization with SciPy for an objective function that returns a small value, and for a problem where I would like to use numerical derivatives in a gradient-based algorithm. ...
1
vote
1
answer
86
views
fit the data with two type of fit combined or any one type fit, whichever is good fit
I have data x and y , want to fit one part with power_fit and other part with negative power_fit settling to zero finally and start from some -20nm with some 5nF values and goes down after that minima ...
2
votes
1
answer
67
views
Defining dynamic constraints for scipy optimize in Python
I wanted to abstract the following function that calculates minimum value of a objective function and values when we can get this minimal value for arbitrary number of g's.
I started with simple case ...
0
votes
1
answer
41
views
Scipy Optimizing with Constraints
I am trying to find the values for my x where the sum of the columns of my data_matrix matches the intial_sums.
However the results are: Variable 0: 1.0 Variable 1: 1.0 Final sums: [0. 4. 0. 2. 0.] ...
0
votes
1
answer
78
views
converting curve_fit to optimize.minimize
I have the following code which functions correctly. However, instead of using the method curve_fit, I want to perform the fitting manually using scipy.optimize.minimze on each element. Is it possible ...
0
votes
1
answer
63
views
maximization of function with constraints
let us consider following code :
from scipy.optimize import minimize
def obj(x):
x1 =x[0]
x2 =x[1]
x3 =x[2]
return (x1*1000+x2*1000+x3*500)
def constr(x):
x1 = x[0]
x2 = x[1]...
0
votes
0
answers
30
views
How can the starting values be vectorized before optimization, where should this be installed, at what point does the back transformation take place?
General goal: I want to optimize parameters from the Rosenbrock function with the minimize function in a Python script. My result is already good but I want to use vectorization for the whole ...
1
vote
1
answer
100
views
Can scipy.optimize Find Optimal Input Values When Multiple Products are Involved?
I'd like to find the optimal values for Input A for Product 1 and for Input A for Product 2 with the aim to maximize Total Output and subject to a given constraint. I've tried using Python's Scipy ...
0
votes
1
answer
84
views
Scipy optimize SLSQP: How is the 'ftol' parameter used?
I am wondering how the 'ftol' paramater in scipy.optimize.minimize(method='SLSQP') is used. In the documentation it just says, that it is the precision goal for the value of f, which could mean ...
0
votes
0
answers
45
views
Line search cannot locate an adequate point after MAXLS scipy.optimize.minimize() LBFGS
I am using scipy.optimize.minimize() from scipy to implement LBFGS method. But I am having the following problem:
Line search cannot locate an adequate point after MAXLS
function and gradient ...
0
votes
1
answer
90
views
Different results for scipy-minimize using SLSQP dependent upon initalized values
I am using scipy.minimize in an attempt to optmize the inputs to my function.
I have a given amount of budget/hours and 6 inputs where I'm trying to get the highest return from the input mix. Each of ...
0
votes
1
answer
63
views
Minimize - eps parameter for each element of array
In scipy.optimize.minimize the eps parameter controls the step size between function evaluations and is applied to all the elements of the optimization vector.
How can I apply a different eps to ...
0
votes
0
answers
103
views
scipy 'minimize' with method='trust-constr' raises ValueError('expected square matrix')
I am trying to solve constrained optimization problems using scipy.optimize.minimize with method='trust-constr'.
My problems typically involve both equality and inequality nonlinear constraints. For ...
1
vote
2
answers
66
views
Fitting two curves with a variable number of parameters using `scipy.optimize.least_squares()`
I'm writing code to fit parameters of related pairs of functions from a family using the scipy.optimize.least_squares() function and it seems that the test parameters are not being passed to the ...
0
votes
0
answers
42
views
Ordering the starting parameter in Scipy Minimizer
Addressing a multi-variable function, Scipy minimizer will start with the smallest value in the initial guess array, regardless of the sort. Assuming that you are using the Nelder-Mead method, is ...
1
vote
1
answer
151
views
How to use scipy.optimize.minimize with x defined through database updates
I have a black box optimization problem I am dealing with. Due to the nature of the black box, the vector (or set of vectors) x cannot be redefined programmatically during optimization. That is to say,...
-1
votes
1
answer
82
views
Use of scipy.optimize
I am using Python in FEA a solver and i have an objective function to minimize. I thought about using scipy.optimize but it doesn't work. No optimization is carried out and no errors either... See ...
1
vote
2
answers
123
views
Why does SciPy minimize return different solutions when minimizing sum of squared error versus root mean squared error?
I am in the process of fitting a curve to data using scipy.optimize.minimize. To do this, I have defined an objective function which returns either the sum of squared error or the root mean squared ...
0
votes
1
answer
65
views
Minimizing of function that has a list of tuples as arguments
I need to minimize a function objective() that takes a list of tuples x as argument.
But there's a catch : the tuples can only be choosen in a predefined set of tuples.
A minimal example would be:
...
0
votes
1
answer
75
views
Trouble with Refinery Optimization Python Script
Trying to write a Python script to determine how much heavy Canadian oil each of the refineries I have listed process per month based on a few constraints I listed regarding their capacities and ...
0
votes
1
answer
61
views
Runtime error in log function is occurring when using minimize from scipy, how should I fix this?
For context I'm using NumPy. I encountered the following warning message in my code
RuntimeWarning: invalid value encountered in log
model = ((-2*r) * np.log(1-s*np.sin(2*np.pi*t/p_orb-phi_orb)))...
4
votes
1
answer
291
views
Why is my scipy.optimize.minimize(method="newton-cg") function stuck on a local maximum?
I want to find the local minimum for a function that depends on 2 variables. For that my plan was to use the scipy.optimize.minimize function with the "newton-cg" method because I can ...
0
votes
2
answers
86
views
Optimize numbers so that the sum of the rounded numbers is equal to zero
Within python3, if I have a dictionary containing for example:
d = {'C1': 0.68759, 'C2': -0.21432, 'H1': 0.49062, 'H2': -0.13267, 'H3': 0.08092, 'O1': -0.8604}
And I have the equation:
n1*d['C1'] + ...
0
votes
0
answers
41
views
Is it possible to put constraint on a variable that is not the subject of optimization but is a calculation byproduct of it?
So, I tried using scipy.optimize.minimize to find the optimal parameter (stiffness and damping: kx1, cx1, kz1, cz1, kx23, cx23, kz23, cz23) that could equate to a certain value (max tension: T_max_1 &...
0
votes
0
answers
212
views
Uncertainty of optimized parameters using the scipy.optimize.minimize
The aim is fitting the following equation by optimizing the K's parameters and knowing L:
Y_fit = (Ka*Kb**L2) / (1 + K11*L + Ka*Kb*L**2)
and Y = experimental points that one want to be fitted using ...
0
votes
1
answer
134
views
Using scipy.optimize.minimize to fit the sum of functions to allow individual decomposition
I have some x, y and y_error data
The ranges and for my data are roughly on orders of
x data: [0,40]
y data: [10^-14, 10^-12]
y_error data: [10^-15, 10^-14]
Plotting this yields the following graph:
...
1
vote
0
answers
33
views
recusive objective function in scipy.minimize - Bellmann equation
I am working on an optimal execution problem in python but I do not know dynamic programming. Therefore I am trying to write down a recursive minimization problem.
v is the arrays of the shares traded ...
1
vote
1
answer
86
views
multiprocessing stuck using scipy.optimize and scikitlearn.dbscan in ubuntu
I am performing an optimization in Python using the 'SLSQP' method of the scipy optimization library. To improve the speed of Jacobian calculations, multiprocessing was applied to the cost function. ...
1
vote
1
answer
51
views
minimize() - iteration time keeps increasing
tried to understand why my optimization is it taking so long, I put time stamps in my code.
the problem is between the stamp just before the return and one in the beginning of the function "start ...
0
votes
1
answer
139
views
Scipy minimize returns an array too big
I am trying to minimize this function but using scipy minimize i expect to get in return an array of the same size of the one in input, that is (92445,) but i get an array of size (92445, 92445) and ...
0
votes
1
answer
48
views
Some problem in package my code into class
My code:
from scipy.optimize import minimize
import numpy as np
class Least_squares:
def __init__(self):
self.d = 2 #decision_demension
self.parameter_sets = np.ones(6) ...
0
votes
1
answer
179
views
Simple optimization problem with scipy.minimize(SLSQP) gives error "positive directional derivative for lineasearch"
I am trying to solve a simple optimization problem but cant get around the error "positive directional derivative for linesearch" and am wondering what is going on here, i dont see anything ...
0
votes
1
answer
491
views
Access OptimizeResult in scipy.optimize.minimize callback function
I am trying to define a callback function to be used when optimizing. I am only interested in the current objective function's value for each iteration.
The documentation suggests, that most optimize ...
0
votes
1
answer
106
views
Solving a constrained linear system of equations using Scipy
I am trying to solve a linear equation (AX=b) where A is an 8x8 matrix, and X and b are 8x1 vectors.
X can be expressed by X=[x1, y1, x2, y2, x3, y3, x4, y4]. However, I have the following 3 ...
0
votes
0
answers
18
views
is it possible to change the fitness with callback feature in scipy minimize while itterate?
I am using Scipy. optimize for my optimization problem. i have two optimisations inner and outer, and i want to implement the fitness of the first optimisation with the second one.
after a good time ...
1
vote
0
answers
67
views
SciPy optimization for FEA truss structure
I am trying to optimize the weight of a truss structure by changing the areas. I have this (shortened/verified code for FEA truss) where x is a array of element areas:
stresses = np.zeros(10)
def FEA(...
0
votes
0
answers
78
views
How to use parallel for loop with scipy L-BFGS-B minimzer in python?
I am trying to do inversion using scipy L-BFGS-B optimizer which uses Pool inside for forward modelling function. In my forward modelling function I have a for loop of a function running over subset ...
1
vote
2
answers
128
views
Writing Objective Function using scipy.optimize.minimize Troubleshoot
I am trying to solve an optimization problem applied to bridges, in the context of a parametric design. The objective function is to try and split precast barriers into a minimum amount of unique ...
0
votes
0
answers
49
views
Scipy.optimize.minimize is not working well with these 3 constraints
I have 4 datasets with the same length (701). The first represents the x values (station). The others the y values: one from a measurement (scannedCSLeft), and the rest are representing the permitted ...
0
votes
1
answer
246
views
constraints are not considered in scipy.optimize.minimize
I want to optimize for 1 parameter only, but as I need constraints, I want to use minimize instead of minimize_scalar.
#get_cl(aircraft,FL,mach,mass = aircraft["mass"]):
cons = [{'type': '...
0
votes
0
answers
170
views
Python Scipy optimize does not respect constraints
Using Python scipy function Optimize/Minimize, constraint is not respected despite the optimization finishing as "Optimization terminated successfully".
from scipy.optimize import minimize
...
0
votes
1
answer
89
views
Unexpected solution when using scipy.optimize.minimize to solve a optimization problem
I'm trying to express the following optimization problem in scipy.
Assuming r is a known array with values:
[0.96366965, 0.93341242, 0.90676733, 0.88186071, 0.8582291, 0.83472442, 0.80977363, 0....
0
votes
0
answers
149
views
Parameter Optimization in python with differential_evolution or minimize from scipy.optimize
I have a function ,calculate_array, which returns a list of values (for e.g 10 values). I want to optimize two input parameters a,b, in this function so that the first element of the list to be ...
0
votes
1
answer
161
views
Scipy minimize - minimum absolute weights but 0 acceptable
I am trying to optimize a portfolio allocation.
I am happy for some weights to be 0 but I do not want to get values that are less than some threshold T. this is on absolute values as negative weights ...