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

scipy.optimize.minimize(method=’trust-constr’) doesn't terminate on xtol condition

I have set up an optimization problem with linear equality constraints as follows sol0 = minimize(objective, x0, args=mock_df, method='trust-constr', bounds=bnds, constraints=cons, options={'maxiter': 250, 'verbose':…
12
votes
2 answers

How to choose proper method for scipy.optimize.minimize?

I was wondering how I can choose the best minimization method for scipy.optimize.minimize and how different the results may be? I am trying to minimize the following expression (solve for g): |a1.g.x + a2.g.x^3 - K|
Shannon
  • 985
  • 3
  • 11
  • 25
10
votes
1 answer

How to solve an assignment problem (like Hungarian/linear_sum_assignment) with an edge case in PySpark UDF

I have an assignment problem, and I wanted to ask the SO community the best way to go about implementing this for my spark dataframe (utilizing spark 3.1+). I will first describe the problem and then move to implementation. Here is the problem: I…
8
votes
2 answers

How to compute the Jacobian of a pairwise distance function (`scipy.spatial.pdist`)

Context I am the author and maintainer of netgraph, a python library for creating network visualisations. I am currently trying to optimise a routine that computes a set of N node positions for networks in which each edge has a defined length. An…
Paul Brodersen
  • 11,221
  • 21
  • 38
8
votes
5 answers

No module named 'scipy.spatial.transform._rotation_groups after compile python script with pyinstaller

After days of looking for an answer on internet and, of course, in overflow I make this post. I hope someone could help me. I made a little program that fits some data that I got from chemistry experimentation with a math model using scipy.optimize.…
8
votes
0 answers

How to fix "failed to initialize intent(inout|inplace|cache) array, input not an array" who appears after using fmin_l_bfgs_b?

I'm trying to use scipy.optimize.fmin_l_bfgs_b function in order to minimize my function evaluateFunc(params) which returns an error and the related error gradient. However, when I call the function fmin_l_bfgs_b with this function, it send me this…
7
votes
2 answers

Find the value of variables to maximize return of function in Python

I'd want to achieve similar result as how the Solver-function in Excel is working. I've been reading of Scipy optimization and been trying to build a function which outputs what I would like to find the maximal value of. The equation is based on…
OldSport
  • 137
  • 1
  • 12
7
votes
1 answer

How to determine appropriate values for ftol, xtol and gtol for least_squares optimization?

I'm using least_squares optimization to adjust the output of a numerical model to some measured data. At this stage I'm wondering how to determine appropriate values for the ftol, xtol and gtol parameters as they determine how and where the…
a_guest
  • 34,165
  • 12
  • 64
  • 118
6
votes
1 answer

How does the SLSQP optimization algorithm work?

I am using the SLSQP algorithm in openMDAO, but I am having trouble understanding how it actually works. I am just looking at the common paraboloid example, which has 2 design variables and aims to minimise f, without any constraints. By printing…
6
votes
1 answer

scipy differential evolution setup issue

Below is a very stupid example which is basically a dumbing-down of my real world use case import pandas as pd from scipy.optimize import differential_evolution import time def optimizer_function(x, cost_name): print(cost_name) a =…
Chapo
  • 2,563
  • 3
  • 30
  • 60
6
votes
3 answers

Is there any quadratic programming function that can have both lower and upper bounds - Python

Normally I have been using GNU Octave to solve quadratic programming problems. I solve problems like x = 1/2x'Qx + c'x With subject to A*x <= b lb <= x <= ub Where lb and ub are lower bounds and upper bounds, e.g limits for x My Octave code looks…
euraad
  • 2,467
  • 5
  • 30
  • 51
6
votes
0 answers

scipy.optimize minimize inconsistent results

I am getting some very weird results when running the minimize function from scipy optimize. Here is the code from scipy.optimize import minimize def objective(x): return - (0.05 * x[0] ** 0.64 + 0.4 * x[1] ** 0.36) def constraint(x): …
dimitris_ps
  • 5,849
  • 3
  • 29
  • 55
5
votes
2 answers

How to use scipy's minimize within a class?

I'm new to python so this might be a stupid question, however I couldn't find an answer to this anywhere. I'm trying to find the optimal reaction for a player given the action of another player. The situation is your typical Bertrand price…
5
votes
1 answer

Nonlinear constrained optimization package for Python with direct support of matrix variables

I've been looking around for a nonlinear constrained optimization package for Python (to deal with problems that are NOT necessarily convex) that can directly handle matrix variables. More specifically, I'm dealing with optimization problems where…
5
votes
1 answer

Can I vectorize scipy.interpolate.interp1d

interp1d works excellently for the individual datasets that I have, however I have in excess of 5 million datasets that I need to have interpolated. I need the interpolation to be cubic and there should be one interpolation per subset. Right now I…
1
2 3
67 68