Questions tagged [scipy-optimize]

Tag used for questions regarding minimizing or maximizing objective functions with python module `scipy.optimize`. Also add more generic tags to your question (`python`, `scipy`)

Module SciPy optimize is used for minimizing (or maximizing) objective functions. It includes solvers for nonlinear problems, linear programming, constrained and nonlinear least-squares, root finding and curve fitting.

1017 questions
0
votes
2 answers

Solve parameter matrix with element-wise constraints using scipy optimize

I have a relatively simple optimisation problem, but am not particularly well-versed in scipy and cannot figure out how to apply the necessary constraints. My objective function is to minimise the absolute distance between a 10-element vector y and…
0
votes
0 answers

ValueError: setting an array element with a sequence with scipy.optimize curve_fit

I was trying to solve a cubic equation and to fit with my experimental data set. But there is some problem in my code regarding curve_fit. Though both function f and del_y defined perfectly (checked using values of parameters ), curve_fit is not…
user74361
  • 9
  • 3
0
votes
0 answers

Scipy TypeError: only size-1 arrays can be converted to Python scalars when using dogleg in optimize, why?

I am using the method dogleg within optimize.minimize tool in Scipy to solve my non-linear 2-equations system. sol = optimize.minimize(self.myF, self.initialWCEC,rZ,jac=self.myJacobian,hess=self.myJHessian,tol=6e-11,…
ndarkness
  • 1,011
  • 2
  • 16
  • 36
0
votes
0 answers

Fitting cosine function to another

Being A and B two cosine data series (same Xvalues, different Yvalues), I want to identify a third cosine function (and its parameters) so that: A(x) = B(x) + C(x) [A is the blue curve, B is the red curve below] I just want to discover which cosine…
mdpoleto
  • 711
  • 2
  • 6
  • 10
0
votes
0 answers

Python: constrained optimization in python - fastest/efficient way?

I have a simple optimization problem in python which I need to re-run quite often (more than 10,000 times). Most of the calculation can be done with numpy and the n-dimensional arrays quite efficient, however, when it comes to the optimization I am…
0
votes
1 answer

SLSQP optimization not converging to unique solution

I am trying simple experiment to learn scipy's SLSQP optimizer. I took the functions: def obj(x): return -1*((x[0]*x[0])+(x[1]*x[1])) It's jacobian as : def jacj(x): return [-2*x[0],-2*x[1]] It's bounds as: bounds=[(0,1),(0,1)] A simple…
0
votes
0 answers

Optimizing using scipy with pandas data frame arguments

I am trying to optimize a function. But this function takes a pandas data frame as an argument. So when I run the code, I get this error: TypeError: 'DataFrame' objects are mutable, thus they cannot be hashed My evaluation function: def…
Parth
  • 2,682
  • 1
  • 20
  • 39
0
votes
0 answers

How can optmize fitting data on thermal profile properly?

I have tried to fit data on the high and low-temperature regime of the thermal profile, but I couldn't fit properly. According to the experiment report, there should be 3 to 4 measurement points on each level however I couldn't manage it till now…
Mario
  • 1,631
  • 2
  • 21
  • 51
0
votes
1 answer

Minimum difference of Numpy arrays

I have two 3-dimensional Numpy arrays of the same size. Their entries are similar, but not quite the same. I would like to shift one array in all three space dimensions, so that the difference between both arrays is minimal. I tried to write a…
putinho
  • 3
  • 2
0
votes
1 answer

Minimize system of nonlinear equation (integral on exponent)

General: I am using maximum entropy to find distribution for on positive integers vectors, I can estimate the mean and variance, and have three equation I am trying to find a and b, The equations: integral(exp(a*x^2+bx+c) from (0 ,…
0
votes
1 answer

how to avoid runtime errors with scipy.optimize.fsolve

Question I am trying to numerically solve a non linear system of algebraic equations using scipy.optimize.fsolve. I solve the system for several different values of its parameters (k1, k2, k3 below). For some values of the parameters fsolve finds…
3sm1r
  • 520
  • 4
  • 19
0
votes
1 answer

Scipy minimisation optimisation row-wise on DataFrame

TYPO FIXEDD I need to perform a minimization optimisation for each timestep in my timeseries. The optimisation sets the price based on values in different columns across the row and a series of inequality constraints. My Dataframe has the following…
0
votes
0 answers

SciPy Optimization for one and two variables

I'm writing this program where I have to do a bunch of optimizations. Some with only 1 variable, some with 2. At first I was using the basinhopping algorithm from the scipy.optimize library, but I figured that the normal minimize algorithm should do…
0
votes
0 answers

Why is scipy.optimize not giving me a correct answer?

(I posted a similar question a few days ago, but I have changed my approach given the answers in the last post and have a different approach) I am trying to use scipy.optimize to solve my optimization problem, but I keep getting an incorrect answer,…
Marco
  • 465
  • 2
  • 7
  • 12
0
votes
1 answer

Determening begin parameters 2D gaussian fit

I'm working on some code which needs to be able to preform a 2d gaussian fitting. I mostly based my code on following question: Fitting a 2D Gaussian function using scipy.optimize.curve_fit - ValueError and minpack.error . Now is problem that I…