Questions tagged [scipy-optimize-minimize]

446 questions
0
votes
0 answers

Issue using scipy.optimize.minimine in python

I have been trying to work on a code that allows the user to perform a neural net analysis with the number of layers and number of nodes per layer of the user's choice. While working on the code, however, I have stumbled in on a bit of a problem. I…
0
votes
0 answers

Scipy minimization failing with inequality constraints or bounds

I am trying to use scipy.optimize to solve a minimizaiton problem but getting failures on using an inequality constraint or a bound. Looking for any suggestions regarding proper usage of constraints vs bounds, and if any other algorithm would be…
0
votes
0 answers

ValueError in Scipy.Optimize Linprog

I am trying to solve a problem using scipy's linprog function, but running the program I get the following error: File "C:\...\anaconda3\lib\site-packages\scipy\optimize\_linprog_util.py", line 339, in _clean_inputs elif (len(bounds) == 2 and…
0
votes
1 answer

Python scipy.optimize.minimize IndexError with [0,0] but not with .item()

I found that scipy.optimize.minimize works when I use .item() to retrieve a value from an numpy array in the objective function, but it fails when I retrieve by indexing [0,0]: def sigmoid(Z): return 1 / (1 + np.exp(-Z)) def hyp_log(X, theta): …
0
votes
0 answers

Asking about a ValueError using SciPy Linprog

I am trying to solve a problem using scipy's linprog function, but running the program I get the following error: File "C:\...\anaconda3\lib\site-packages\scipy\optimize\_linprog_util.py", line 339, in _clean_inputs elif (len(bounds) == 2 and…
LEO HDZ
  • 21
  • 4
0
votes
1 answer

Strange working of the python minimize procedure

Working with 'scipy.optimize.minimize' I'm having strange using of the minimize procedure. Below is test code to show my results: import numpy as np import pandas as pd from scipy.optimize import minimize def SES(good, a, h): print('good is :…
Roman Kazmin
  • 931
  • 6
  • 18
0
votes
1 answer

How to make function that outputs multiple minima of a function which takes arrays as input?

a1 = [array] #shape = (m,) a2 = [array] #shape = (n,) a = func(a1,a2) # func returns an array of shape = (n, m) # a is an array of shape = (n, m) a_sol = [] # empty list for i in a1: f = lambda x: float(func(np.array(i), np.array(x))) res =…
0
votes
1 answer

Using lambda to change minimize_scalar to maximize in Python

I'm trying to maximize a (scalar) function in Python using scipy.minimize_scalar. Thought it would be more elegant to use lambda instead of defining a new function that's the negative of the given function. Unfortunately, it's giving a TypeError.…
J.D.
  • 139
  • 4
  • 14
0
votes
1 answer

scipy.optimize.minimize stops at x0

I'm trying to use scipy.optimize.minimize to do simulated method of moments estimation. Here is my code: import numpy as np from scipy.optimize import minimize import matplotlib as plt n = 10000 c = np.tile(np.random.normal(size=(n,1)),(1,2)) k =…
ZCB
  • 1
  • 1
0
votes
1 answer

Can we use constraints in scipy.optimize.curvefit and how to use minimize?

To summarize: My post is quite long but my two questions are: Can we use eq or ineq constraints in optimize.curvefit? How to use minimize with initial guesses far from the optimal ones? Some details: I have been trying to use…
0
votes
1 answer

scipy.optimize.minimize can't find least square solution

My intention was to solve the l1 error fitting problem using scipy.optimize as suggested in L1 norm instead of L2 norm for cost function in regression model, but I keep getting the wrong solution, so I debugged using least square which we know how…
0
votes
1 answer

Scipy Optimize Minimize missing 1 required positional argument

I'm trying to learn how to use scipy.optimize.minimize. I'm going to need it for functions of two variables with around a thousand terms each; so I came up with an easy example first: from scipy.optimize import minimize def test_function(x,y): …
J.D.
  • 139
  • 4
  • 14
0
votes
1 answer

Scipy.Minimize, how to share the same objects among objective function and constraints?

The objective function is def obj(w): a = f(w) return g(a) The constraint function is def cons(w): a = f(w) return a - 1 The function f(w) in both obj(w) and cons(w) is calculation heavy. How to calculate f(w) just once for every…
Tony
  • 81
  • 3
0
votes
0 answers

scipy.optimize.minimize giving partially incorrect result

I am trying to find regression model parameters using Maximum Likelihood Estimation. I have assumed that the error term follows a normal distribution. My code goes like this.. def lik(parameter): m=parameter[0] b=parameter[1] sigma=parameter[2] for…
Kiran
  • 1
0
votes
0 answers

Optimization problem with non-convex function using Scipy. Not initial guess

I need to optimize the objective function (minimize). The sum of x1+x2+x3 = 1 (This is my unique constranint). Following this, the bounds of the x1,x2,x3 has to be between (+0,<1). Positive values, but less than 1. I dont have any initial guess. In…