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

Fitting cosine squared to points in python

I am trying to fit the cosine squared curve to the data that I have using curve_fit from scipy optimise. BUt unfortunately I am getting a straight line. Hoping that somebody would be able to help me. import pylab as plb import matplotlib.pyplot as…
0
votes
1 answer

How to find roots of an equation where a variable is an output from a function, having target variable as an argument itself?

I am trying to solve an equation for variable 'X' in python where some of the variables in the equation ('ABC, PQR') are output from a function 'calculations'. The problem is, in order to get an output from the function, I need to pass variable X as…
erm0rden
  • 11
  • 3
0
votes
1 answer

Can the objective function have multiple input variables except the optimizable variable?

When use the scipy.optimize, the objective function I tried successfully can only take one variable, scalar or vector. for example, this code works: from scipy import optimize def f(x, a=2, b=-5, c=3): return…
Westack
  • 105
  • 5
0
votes
1 answer

How to fit 2 data sets to 2 reference data sets simultaneously and extract shared parameters

I have got 2 (simulation) data sets and 2 (experimental) reference data sets. As the simulation was performed numerically, no method/function is known, just the simulation data is available. The 2 data sets share parameters that I want to extract by…
Shudras
  • 117
  • 2
  • 8
0
votes
1 answer

Minimization of known cost function without knowing original function

I am trying to fit one function to another function by adjusting two parameters. But I dont know the form of this function. I have only cost function because for computation of this function is used LAMMPS (molecular dynamics). I need some tool…
n5ver
  • 5
  • 5
0
votes
1 answer

How to use minimize from scipy correctly with multible variables?

I have five variables that I would like to subject to scipy.optimize.minimize in order to find the solution I am seeking in terms of A, B, C, D, and E. First, I imported minimize from scipy and defined the initial guesses (based on lab experiments,…
0
votes
1 answer

Minimal example of multivariate minimization

so I'm trying to write a minimal working example of scipy.optimize.minimize with more than just one example. Basically, my example works for a lambda-function of one variable but as soon as I add another one, It crashes. lamX = lambda x:…
0
votes
1 answer

Why do scipy.optimize error bars on parameters extend outside bounds

I was reviewing Getting standard errors on fitted parameters using the optimize.leastsq method in python as I want to use optimize.least_squares to fit some data, however I have bounds (for physical reasons) on my parameters, e.g. parameter A must…
0
votes
0 answers

Chisquare test give wrong result. Should I reject proposed distribution?

I want to fit poission distribution on my data points and want to decide based on chisquare test that should I accept or reject this proposed distribution. I only used 10 observations. Here is my code #Fitting function: def Poisson_fit(x,a): …
jerry
  • 385
  • 6
  • 18
0
votes
1 answer

TypeError with scipy.optimize when minimizing Cost func

I want to optimize 9 variables in W((1×9)matrix) by using scipy.optimize. from scipy.optimize import minimize def func(W): W = W.reshape(1,9) #(1,9) Y = df0.values.reshape(49,1) #(49,1) X = df1.values.reshape(49,1) #(49,9) Z =…
0
votes
0 answers

Scipy.optimize.minimize ignores the bounds I specify while optimizing a black box function

I am trying to minimize a function of 76 parameters. I want every parameter value to be between 0 and 5. The default algorithm LBFGS failed to find an optima. So, I tried the TNC algorithm and while it achieves a good objective function value, the…
Sanit
  • 80
  • 9
0
votes
0 answers

pasing arguments in global optimization in scipy.optimize

I am trying to solve an optimization problem with scipy global optimization. I am using differential evolution. code def objective(x,*args): x = np.append(x,args) res = MLmodel.predict(x) return res fun_history = [] x_values =…
chink
  • 1,505
  • 3
  • 28
  • 70
0
votes
0 answers

TypeError: Improper input parameters were entered

I trying to use the fsolve function from scipy.optimize library to solve a non-linear equation changing the parameteres of the equation, but when I run the code, I receive the following error message: TypeError: Improper input parameters were…
0
votes
1 answer

Allocate resources in the fairest way possible

Working on a personal project, I have encountered a problem that I'll try to generalize here. Given a list of resources of different value (e.g. resources = [1, 0.8, 1.5, 0.8, 1.2...]), I want to share them among a group of N people in a way that is…
user2891462
  • 3,033
  • 2
  • 32
  • 60
0
votes
0 answers

Termination conditions of scipy.optimize.minimize

I am using scipy library for an optimization problem. My optimization code: result = minimize(objective,x0,args=(a,b,c),method='nelder-mead',options={'xtol': 1e-8, 'disp': True}) I am using nelder-mead simplex solver as I am solving an…
chink
  • 1,505
  • 3
  • 28
  • 70