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
2
votes
2 answers

How to find root of a function accepting error on f(x) instead of x?

I have a function like e. g.: amountOfCalls = 0 def myFunc(x): global amountOfCalls amountOfCalls+=1 y = x ** 3 + x -5 return y and want to find the root of it (i. e.: find the value of x where f(x) == 0). If I use one of scipy…
1018307
  • 111
  • 1
  • 7
2
votes
1 answer

scipy.optimize.minimize_scalar() adding constraint to helper function result inside objective function?

I have a function func_x() that I am trying to minimize using scipy.optimize.minimize_scalar(). func_x() also calls another function func_y() whose result func_x() uses in part to calculate the final scalar value. I want the optimization to also…
2
votes
1 answer

Scipy curve_fit seams to be working badly. Which python libary for fitting curves is more stable?

I took the example of the official documantation page of scipy optimize curve_fit.(https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.curve_fit.html) and modified the function in the example a little bit and scipy throws a warning…
2
votes
2 answers

Passing numpy array through scipy fitting function

With the fitting function: def conv_gauss(x, constant, c, beta, sigma): return constant * np.exp((x-c)/beta) * math.erfc((x-c)/(np.sqrt(2)*sigma) + sigma/(np.sqrt(2)*beta)) And x and y data: x_data = [5751.0, 5752.0, 5753.0, 5754.0, 5755.0,…
Allentro
  • 406
  • 2
  • 13
2
votes
1 answer

Use GEKKO solver in scipy.optimize

I try to use the scipy.optimze.minimize solver (Nelder-Mead) to optimize my parameters of a GEKKO simulation. Is this possible at all? My idea was to hand over the GEKKO object to the solver, but this leads to a error: TypeError: float() argument…
H Bode
  • 165
  • 7
2
votes
1 answer

Possible bug in SciPy shgo (Unexpected TypeError)

When running the following from scipy.optimize import rosen, rosen_der, rosen_hess bounds = [(0,1.6), (0, 1.6), (0, 1.4), (0, 1.4), (0, 1.4)] result = scipy.optimize.shgo(rosen, bounds, options={'jac':rosen_der,'hess':rosen_hess}) I get TypeError:…
Kvothe
  • 233
  • 1
  • 8
2
votes
0 answers

debugger Spyder stuck in SciPy SLSQP

When not running the debugger in Spyder I have no problem, but when I try to reach a breakpoint with Debug file (ctrl+f5) it stops here, before the breakpoint: ipdb> >…
thijs818
  • 43
  • 4
2
votes
1 answer

How to pass arguments to non-linear constraints in scipy.optimize?

I am trying to use scipy optimization to solve an optimization problem. I have defined the non-linear constraints and fitness functions as shown below in the code. I am able to pass arguments to the fitness function but not to the non-linear…
naseefo
  • 720
  • 1
  • 9
  • 30
2
votes
1 answer

SciPy Curve_fit() doesn't fit curve

I made a random graph, and tried to use SciPy curve_fit to fit the best curve to the plot, but it fails. First, I generated a random exponential decay graph, where A, w, T2 are randomly generated using numpy: def expDec(t, A, w, T2): return A *…
rb3652
  • 425
  • 2
  • 12
2
votes
0 answers

Find interior-point of two intersecting Convex Hulls

Goal: I am trying to calculate the volume of two intersecting convex hulls. One hull is from a large point cloud of varying sizes, the other is a cuboid (block) that is [1m x 1m x 0.5m]. Problem: I am able to use the centroid of the block as the…
2
votes
1 answer

Is it possible to stop scipy.optimize.curve_fit according to the loss function?

I'm trying to minimize the mse between 2 functions with bounds, curve_fit is doing it very well, but I want to stop the computation when the mse between the two functions is lower than 0.1. Here is a simple example code import numpy as np from scipy…
2
votes
0 answers

'numpy.float64' object is not callable while curve-fitting

I'm trying to fit a sinusoidal curve in CSV data to find the maximum of the curve. The data is of the like of Time Voltage Current 0 -0.02500 -1.4 0.38 1 -0.02498 -1.6 0.32 2 -0.02496 -1.8 0.40 3 -0.02494 -1.4 …
2
votes
0 answers

Matlab fmincon equivalent in Python

I have a code in matlab and I want to convert it to python. The matlab code is as follows: options =…
2
votes
1 answer

Analytic Highest Density Interval in Python (preferably for Beta distributions)

I was wondering if anybody knows of a reliable and fast analytic HDI calculation, preferably for beta functions. The definition of the HDI is in this question called "Highest Posterior Density Region". I am looking for a function that has the…
elzurdo
  • 579
  • 1
  • 4
  • 14
2
votes
0 answers

Is there a way to optimize function thresholds with fixed steps?

How can I optimize a function with fixed steps? I have developed a function with five thresholds as entry that I want to optimize. I actually tried to optimize them with different solvers, but the steps that the solver takes are so tiny that the…