495 questions
Best practices
0
votes
1
replies
25
views
Best Way to Adapt `scipy.optimize.minimize` to Accept Multi-Dimensional Arrays
import numpy as np
from scipy.optimize import minimize
x = np.linspace(-5, 5, 100)
def function_to_minimize(*args):
function = 0
for j in range(0, 4):
a_j = args[j][0]
b_j ...
0
votes
1
answer
101
views
Why does scipy.optimize.minimize() show an error about the number of array dimensions not matching when using constraints?
I am trying to "minimize" using SLSQP in scipy module. With a lot of difficulty, I am trying to implement some constraints. I am encountering some strange error, thus unable to debug. My ...
1
vote
0
answers
121
views
Fitting with Maximum likelihood estimation in python returns initial parameters
I would like to use minimize from scipy.optimize to fit my data with a specific function:
I defined this log likelihood to this aim:
def log_likelihood(theta, freq, CPSD, CPSD_err):
'''
This ...
1
vote
0
answers
51
views
Interdependent bounds in scipy minimize
Say I have a function f(x,y,z) I want to minimize using scipy.optimize.minimize. I want to minimize it subject to the constraint x < y < z.
I don't think I can use the bounds argument to do this ...
0
votes
2
answers
65
views
Scipy Minimize with boolean decision matrix
I have a distance matrix between 2 sets of points ( sets A & B ). Each A point is associated with an equal number of B points ( if possible ).
I want to minimize the standard deviation of average ...
1
vote
1
answer
91
views
Applying scipy.minimize to Pandas dataframe with parameters
I have a function defined by f(x_0, x_1) = a(x_1 - x_0^2)^2 + (b - x_0)^2, where a and b are some parameters:
def f(x):
return a*(x[1]-x[0]**2)**2+(b-x[0])**2
where x=np.array([x_0,x_1]) is a numpy ...
0
votes
0
answers
108
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
129
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
0
answers
82
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 ...
2
votes
1
answer
106
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
158
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
0
answers
32
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 ...
0
votes
1
answer
229
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
1
answer
243
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
0
answers
173
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 ...
0
votes
0
answers
55
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
votes
1
answer
112
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 ...
0
votes
1
answer
92
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:
...
1
vote
1
answer
111
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)))...
0
votes
2
answers
93
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
1
answer
204
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
1
answer
142
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. ...
0
votes
1
answer
230
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
324
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
182
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 ...