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

Search for the optimal value of x for a given y

Please help me find an approach to solving the following problem: Let X is a matrix X_mxn = (x1,…,xn), xi is a time series and a vector Y_mx1. To predict values ​​from Y_mx1, let's train some model, let linear regression. We get Y = f (X). Now we…
-1
votes
1 answer

Why do numerical optimizers minimize rather than maximize?

I'm thinking about optim() in R or optimize() in Python's scipy. Both can minimize a function, and both can maximize a function by minimizing the inverted function. My question is: why are both coded to minimize rather than maximize? Is it just down…
invictus
  • 1,821
  • 3
  • 25
  • 30
-1
votes
1 answer

curve_fit spherical nested variogram

I'd like to fit a spherical formula with 2 structures, but I cant find a way to do it. "ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()" on the last line. My goal is to fit experimental data…
Vnc J
  • 47
  • 6
-1
votes
1 answer

Minimize a function that takes a matrix of size (2, n)

TLDR: I need a minimzation implementation for functions with matricial variable I have the following cost function: def loss_price(params): A_grid, S_grid = params print(A_grid, S_grid) res = 0. i = 0 …
-1
votes
2 answers

constraint on sum of abs(w) in scipy optimizer

I would like to put an upper limit on the sum of abs(w) in a scipy optimization problem. This can be done in a linear program by using dummy variables, e.g. y > w, y > -w, sum(y) < K, but I cannot figure out how to formulate it in the scipy…
Henry
  • 200
  • 8
-1
votes
1 answer

scipy minimize build model

I have a nonlinear problem that I am trying to solve with scipy minimize. The thing is that for now I am trying to pose the first constraint (with only that one the problem is linear) and I am having problems. To contextualize, the case is that I…
-1
votes
1 answer

Why does this IndexError occur?

Why does this error occur: root = optimize.newton(func=fa,x0=del_dsoil_trys[i]) Traceback (most recent call last): .... ..... File "", line 3, in v_can v_cans[i+1] = np.sqrt(2*Eks[i]/(yf*m_d*1000)) IndexError:…
henrybish
  • 3
  • 3
-1
votes
2 answers

Outputting results of loop of a loop

I am iteratively solving this implicit equation using fsolve within a for loop over a range of values of the independent variable, V. I also want to vary I_L and run the for loop over each value and generate an individual text files. I know how to…
-1
votes
1 answer

Optimization function yields wrong results

im trying to replicate a certain code from yuxing Yan's python for finance. I am at a road block because I am getting very high minimized figures(in this case stock weights, which ca be both +(long) and (-short) after optimization with fmin(). can…
-1
votes
1 answer

Implementing linear equation in curve-fitting function

my professor sent us this code to use as a defacto for fitting curves or whatever function you would like to fit. even though is written into the function that the type of function is linear I can't see no equation to express that in the function…
-1
votes
1 answer

Is there any out of the box newton like solver that allows bounds (and a supplied jacobian and hessian)

Is there any out of the box newton like solver that allows bounds on the input parameters (and a supplied expression for the jacobian and hessian). I am basically exactly looking for "trust-constr" in SciPy, except that one does not seem to work at…
Kvothe
  • 233
  • 1
  • 8
-1
votes
2 answers

Fitting two functions sharing same parameters to data

Assume that I have two functions describing one phenomena in the same range (x-axis). Both are sharing same parameters, but also can have their own. How can I fit them or minimize the errors to experimental data using SciPy or Lmfit >>AT ONCE<
Mimi
  • 95
  • 1
  • 10
-1
votes
3 answers

Problem Data Fitting with Square Root function

I try to fit this experimental data with a square root function, using python and the module scipy.optimize. The code for plotting and fitting looks like this. def curve(x, a, b): return np.sqrt(a+b*x) xaxis = np.linspace(30, 1400,…
-1
votes
2 answers

loop of ufunc does not support argument 0 of type float which has no callable exp method

I am having trouble with an optimization that used to work with a previous version of python... I have a function fp = lambda c, x: (c[0])+ (c[1]*((1- np.exp(-x/c[4]))/(x/c[4])))+ (c[2]*((((1-np.exp(-x/c[4]))/(x/c[4])))- (np.exp(-x/c[4]))))+…
-1
votes
1 answer

How to solve for roots given a summation of a function of an unknown and a variable?[Scipy][Root-finding]

I am trying to solve for the following equation, however, there is very little documentation on the SciPy reference guide so I am not sure how to go about doing it. I have an array of 10 uniform random variables, let's call it X. I have the…
skidjoe
  • 493
  • 7
  • 16
1 2 3
67
68