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

Pandas vectorized root finding

Essentially I'm trying to use the brentq method row-wise on a pandas dataframe to get the root of a function that takes as arguments columns and constants as well. Something like the following import pandas as pd import numpy as np from…
AleVis
  • 187
  • 1
  • 1
  • 10
0
votes
1 answer

Maximise function using scipy minimize

I want to optimize my function Strategy2(alpha, beta), which performs a betting strategy on some data, starting with a wallet value of 20,000, and returns a new wallet value. So I need to find the optimum alpha & beta values that maximize the…
0
votes
1 answer

How to provide the proper initial guess and bounds to logistic regression?

I am trying to implement logistic regression using scipy.optimize in python. When I tried using sklearn, I came to know about the beta values that can be used to predict for the given dataset. But when I try to use it in scipy optimize function, the…
python_interest
  • 874
  • 1
  • 9
  • 27
0
votes
1 answer

How to pass sympy expressions to be used with scipy?

I want to solve a systen of non-linear equations created by loops using root from scipy.optimize. I want to create the equations with one method and then solve them with another. I created the equations with sympy and want to solve them with scipy.…
0
votes
0 answers

Gaussian fitting in Python

I am trying to fit some data with Gaussian fit. This data from lateral flow image. The fitted line (red) does not cover data. Please check my code. In the code x is just index. y actually real data. import numpy as np import matplotlib.pyplot as…
Abdullah
  • 47
  • 1
  • 8
0
votes
1 answer

How to evaluate execution time when using scipy.optimize?

I am working on a python script that utilizes the minimize() function from scipy.optimize. The script works fine, but it is relatively slow, and I am trying to figure out how to (a) figure out where the time is being spent) so I can (b) speed it…
0
votes
1 answer

Tensorflow: how to save a model before the end of optimization?

I'm using ScipyOptimizerInterface for training a tensorflow model. (tensorflow 1.13.1) During the process of training, if the loss value is below a threshold, I want the training process to stop and save the model right before the threshold was…
meTchaikovsky
  • 7,478
  • 2
  • 15
  • 34
0
votes
1 answer

Why does scipy.optimize.minimize not find the minimum?

I am looking to find for which (x) the following function is minimal given a parameter dim. This is the function: def func(x, dim): return np.abs(np.abs(np.mean(np.sqrt(np.sum(np.diff( np.random.rand(100000,dim,2)/x, axis=2)**2,…
rul30
  • 463
  • 1
  • 7
  • 17
0
votes
1 answer

Scipy optimize curve_fit gives different plots for same parameters when fitting custom function

I have a problem with fitting a custom function using scipy.optimize in Python and I do not know, why that is happening. I generate data from centered and normalized binomial distribution (Gaussian curve) and then fit a curve. The expected outcome…
My Work
  • 2,143
  • 2
  • 19
  • 47
0
votes
1 answer

Result from function call is not a proper array of floats using scipy.fsolve

I am trying to solve this simple simultaneous equations using scipy's fsolve function: x + 2 = 10 & x^2 = 64. I am expecting 8 as the solution. However I'm getting an error saying "minpack.error: Result from function call is not a proper array of…
Shafin M
  • 91
  • 2
  • 11
0
votes
0 answers

Scipy minimize like Excel Solver

I have big table of data that I read from excel in Python where I perform some calculation my dataframe looks like this but my true table is bigger and more complex but the logic stays the same: with : My_cal_spread=set1+set2 and Errors = abs(…
0
votes
1 answer

Covariance matrix is NoneType in lmfit Python3-6

I want to fit a f(x,y) function using lmfit. Dataset is small and there are many fitting parameters (6 points on x-axis, 11 points on y-axis and 16 unconstrained fitting parameters). Using all defaults from Model.fit I cannot obtain covariance…
Radek D
  • 79
  • 10
0
votes
2 answers

Python3, scipy.optimize: Fit model to multiple datas sets

I have a model which is defined as: m(x,z) = C1*x^2*sin(z)+C2*x^3*cos(z) I have multiple data sets for different z (z=1, z=2, z=3), in which they give me m(x,z) as a function of x. The parameters C1 and C2 have to be the same for all z values. So I…
AA10
  • 207
  • 1
  • 7
0
votes
1 answer

scipy.optimize.minimize returning [inf]

I am trying to call scipy.optimize.minimize to minimize a function poissonNegLogLikelihood, which is defined as follows: def poissonNegLogLikelihood(lam, y): Computes the negative log-likelihood for a Poisson random variable. Inputs: lam -…
gkeenley
  • 6,088
  • 8
  • 54
  • 129
0
votes
1 answer

How to apply Newton Raphson method for polar function in Python?

I have three dimensional function randomly defined by a user Z=f(x,y) def f(x,y): return ((7*x*y)/(np.exp(x**2+y**2))) I converted this function to polar coordinates by substituting: x_c = r*np.cos(theta)+x1; y_c =…
yahya.k
  • 21
  • 4