minimization

scipy.optimize get's trapped in local minima. What can I do?

对着背影说爱祢 提交于 2021-02-13 17:30:09
问题 from numpy import *; from scipy.optimize import *; from math import * def f(X): x=X[0]; y=X[1] return x**4-3.5*x**3-2*x**2+12*x+y**2-2*y bnds = ((1,5), (0, 2)) min_test = minimize(f,[1,0.1], bounds = bnds); print(min_test.x) My function f(X) has a local minima at x=2.557, y=1 which I should be able to find. The code showed above will only give result where x=1 . I have tried with different tolerance and alle three method: L-BFGS-B, TNC and SLSQP. This is the thread I have been looking at so

How to manually set Initial Solution in CVXPY using CPLEX solver

痴心易碎 提交于 2021-02-11 15:44:00
问题 I am trying to solver the Unit Commitment problem (MIQP problem) by modelling the problem in CVXPY and using the CPLEX solver. I have been successful in getting everything to work with CVXPY using CPLEX. However, this was for a small system. Now I would like to do the same with a much larger system. Side Note: I have successfully solved the MIQP problem in MATLAB using CPLEX. For larger system in MATLAB, I have used an initial solution from a MILP formulation of the problem and limited the

`f0` passed has more than 1 dimension. - fmin_l_bfgs_b

心已入冬 提交于 2021-01-28 11:48:17
问题 I want to find parameters which minimalize a function but I get an error. So far use scipy.optimize.fmin but I want to add bounds for every argument. This is my code def Kou_calibration_full(): i=0 global opt p0 = spo.brute(Kou_error_function, ((0.10,0.31, 0.1),(0.01,2.6, 0.5), (0.1,0.92,0.2), (1.1,20,7),(0.1,20,7)), finish=None) opt = spo.minimize(Kou_error_function, p0, bounds=((0.10,0.31),(0.01,2.6), (0.1,0.92), (1.1,20),(0.1,20))) return opt -----------------------------------------------

How can I optimize a two variable function in R

纵饮孤独 提交于 2020-05-29 11:45:09
问题 I have been trying to optimize the following function, but without success: parametros <- data.frame(ap=c(11.1,7.07,6.3,4.75,4,3.35), fx=c(41.2012,39.3732,25.2912,10.3455,1.2253,0.4017)) xm<-11.2 fxcalc <- function(s,t){(1-(1-(parametros$ap/xm)^(s))^t)*100} suma <- function(s,t){(parametros$fx-fxcalc(s,t))^2} func <- function(s,t){sum(suma(s,t))} Being "func()" the function I am trying to minimize for "s" and "t". Apparently the function "optim()" wouldn't work with more than one variable.

How can I optimize a two variable function in R

与世无争的帅哥 提交于 2020-05-29 11:44:05
问题 I have been trying to optimize the following function, but without success: parametros <- data.frame(ap=c(11.1,7.07,6.3,4.75,4,3.35), fx=c(41.2012,39.3732,25.2912,10.3455,1.2253,0.4017)) xm<-11.2 fxcalc <- function(s,t){(1-(1-(parametros$ap/xm)^(s))^t)*100} suma <- function(s,t){(parametros$fx-fxcalc(s,t))^2} func <- function(s,t){sum(suma(s,t))} Being "func()" the function I am trying to minimize for "s" and "t". Apparently the function "optim()" wouldn't work with more than one variable.

print currently evaluated params during scipy minimization

强颜欢笑 提交于 2020-01-02 18:05:25
问题 I am trying to minimize a function in Python using scipy.optimize.minimize , to determine four distinct parameters. I would like to print the currently evaluated params at each step of the optimisation algorithm, so I can use them to make my initial guess better. How can I do this? 回答1: Use the callback keyword argument. scipy.optimize.minimize can take a keyword argument callback . This should be a function that accepts, as input, the current vector of parameters. This function is called

Scipy selects nan as inputs while minimizing

荒凉一梦 提交于 2020-01-01 19:53:13
问题 I have this objective function (in python) : actions= [...] # some array Na= len(actions) # maximize p0 * qr(s,a0,b0) + ... + pn * qr(s,an,bn) def objective(x): p = x[:Na] # p is a probability distribution b = x[Na:2 * Na] # b is an array of positive unbounded scalars q = np.array([qr(s, actions[a], b[a]) for a in range(0, Na)]) # s is an array rez = - np.dot(p, q) # np stands for numpy library return rez qr and qc are regression trees, these are functions mapping arrays to scalars. I have

Dependency Algorithm - find a minimum set of packages to install

好久不见. 提交于 2019-12-31 10:41:52
问题 I'm working on an algorithm which goal is to find a minimum set of packages to install package "X". I'll explain better with an example: X depends on A and (E or C) A depends on E and (H or Y) E depends on B and (Z or Y) C depends on (A or K) H depends on nothing Y depends on nothing Z depends on nothing K depends on nothing The solution is to install: A E B Y. Here is an image to describe the example: Is there an algorithm to solve the problem without using a brute-force approach? I've

Dependency Algorithm - find a minimum set of packages to install

浪子不回头ぞ 提交于 2019-12-31 10:41:42
问题 I'm working on an algorithm which goal is to find a minimum set of packages to install package "X". I'll explain better with an example: X depends on A and (E or C) A depends on E and (H or Y) E depends on B and (Z or Y) C depends on (A or K) H depends on nothing Y depends on nothing Z depends on nothing K depends on nothing The solution is to install: A E B Y. Here is an image to describe the example: Is there an algorithm to solve the problem without using a brute-force approach? I've

Minimizing SSE using Scipy.optimize minimize

家住魔仙堡 提交于 2019-12-24 12:43:35
问题 I am trying to optimize SSE (sum of squared error) of a function using scipy.optimize . To test with, I created a simple problem as below code. But the optimized parameters output by scipy never makes SSE=0. Can someone help me to understand, where am I going wrong. I tried to cross check with the SSE calculated by my code with the one computed in excel. It matched. Then I used minimize function to minimize that SSE function, the ones computed by Scipy is not matching with the hand calculated