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
3
votes
1 answer

Scipy.optimize.dual_annealing not respecting bounds on variables

scipy.optimize.dual_annealing is not respecting the bounds on variables. I am optimizng a five-variable function; the variables at issue("nu", "vBar") are the third and fifth. python version 3.6.0, scipy version 1.4.1. command: bounds = ( (-1.0…
user18010
  • 31
  • 2
3
votes
0 answers

Running python in Docker gets stuck when multiprocessing pool is used

I am using the scipy.optimize.differential_evolution function inside a Docker container, with the paramater workers=-1 passed to it. This enables parallel processing with the maximum number of CPUs available, using Python's multiprocessing library…
Marnix.hoh
  • 1,556
  • 1
  • 15
  • 26
3
votes
1 answer

Nelder-Mead optimization in python with constraints

Currently, I am looking for a Nelder-Mead optimizer in python that also accepts bounds and constraints for the variables. Scipy has a Nelder-Mead optimizer, but it does not allow any constraints. During my search I came across the package…
Emma
  • 439
  • 5
  • 17
3
votes
1 answer

Can fit curve with scipy minimize but not with scipy curve_fit

I am trying to fit the functiony= 1-a(1-bx)**n to some experimental data using scipy curve_fit. The model only exists for y>0, so I clip the calculated values to enforce this. The code is shown below import numpy as np import scipy.optimize import…
PetGriffin
  • 495
  • 1
  • 4
  • 13
3
votes
1 answer

How to match a Gaussian normal to a histogram?

I'm wondering if there is a good way to match a Gaussian normal to a histogram in the form of a numpy array np.histogram(array, bins). How can such a curve been plotted on the same graph and adjusted in height and width to the histogram?
Sam Sloan
  • 69
  • 5
3
votes
1 answer

Python curve fitting problem with peaked and flat-top (super) gaussian signals

I have a standard gaussian function, that looks like this: def gauss_fnc(x, amp, cen, sigma): return amp * np.exp(-(x - cen) ** 2 / (2 * sigma ** 2)) And I have a fit_gaussian function that uses scipy's curve_fit to fit my gauss_fnc: from…
kalzso
  • 502
  • 2
  • 6
  • 27
3
votes
1 answer

Trying to fit a trig function to data with scipy

I am trying to fit some data using scipy.optimize.curve_fit. I have read the documentation and also this StackOverflow post, but neither seem to answer my question. I have some data which is simple, 2D data which looks approximately like a trig…
user1887919
  • 829
  • 2
  • 9
  • 24
3
votes
1 answer

Python: piecewise polynomial curve fit in the exponential

I want to reproduce a research result where the distribution is piecewise fitted the following way. ln(y_data) = A(x) : 3rd order polynomial for central part of the fit ln(y_data) = B(x) : 1st order polynomial for both tails of the fit So far, I…
3
votes
1 answer

Cannot Import Scipy.Optimize: "No module named 'scipy.optimize._root'"

I opened up a Jupyter notebook on which I was working just a couple of weeks ago and went to re-import the modules I had been using (by running the cell again, with no changes), and encountered an unexpected difficulty when trying to import…
3
votes
3 answers

Curve fitting with nth order polynomial having sine ripples

I'm modeling measurement errors in a certain measuring device. This is how the data looks: high frequency sine ripples on a low frequency polynomial. My model should capture the ripples too. The curve that fits the error should be of the form:…
MorganStark47
  • 154
  • 2
  • 15
3
votes
0 answers

How to speed-up basinhopping global optimization

I'm working on a program that should perform an optimization roughly 6750 times. Now, the problem is that one optimization has a duration of about 3 minutes. This doesn't seem much at first sight, but if I have to perform it 6750 times, I would be…
3
votes
2 answers

Constrained Optimization of battery scheduling in microgrid

Given inputs such as electricity consumption, generation from solar panel, price, (All at a given time t), we have a battery, and we want to evaluate how much it should (dis)/charge at any given time. The Problem can be formulated as follows: Pt =…
usman Farooq
  • 151
  • 1
  • 12
3
votes
1 answer

print chosen method of scipy.optimize.minimize

This is a short question, but google points me every time to the documentation where I can't find the answer. I am using scipy.optimize.minimize. It works pretty good, all things are fine. I can define a method to use, but it works even if I don't…
theother
  • 307
  • 2
  • 16
3
votes
2 answers

Constraints on parameters using scipy differential evolution

I am trying to use differential evolution to optimize availability based on cost. However, I have three unknown parameters (a, b, c) here and I can define the range using bounds. However, I want to define additional constraint as a+b+c <= 10000. I…
2
votes
1 answer

Non-negativity constraint for a state variable in a dynamic optimization program

I am quite the beginner with Python, and I am working on a dynamic optimization program with finite horizon : my reward function is subjected to a capital that accumulate as a function of the control, and to a finite resource that depletes according…
GaL
  • 21
  • 3