minimization

Python - Minimizing Chi-squared

老子叫甜甜 提交于 2019-12-06 06:37:02
问题 I have been trying to fit a linear model to a set of stress/strain data by minimizing chi-squared. Unfortunately using the code below is not correctly minimizing the chisqfunc function. It is finding the minimum at the initial conditions, x0 , which is not correct. I have looked through the scipy.optimize documentation and tested minimizing other functions which has worked correctly. Could you please suggest how to fix the code below or suggest another method I can use to fit a linear model

print currently evaluated params during scipy minimization

谁都会走 提交于 2019-12-06 04:12:52
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? 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 after every iteration. For instance, from scipy.optimize import minimize def objective_function(xs): """

Utilizing scipy.optimize.minimize with multiple variables of different shapes

邮差的信 提交于 2019-12-04 19:23:32
I am curious is there is a straightforward method for utilizing scipy.optimize.minimize with multiple variables that take different shapes. For example, let's take a look at a matrix decomposition problem. I apologize, but I will be using latex here in the hope that one day SO will implement it. We can deconstruct the matrix $ A_{n \times m} $ into two matrices $ W_{k \times n} $ and $ H_{k \times m} s.t. A \approx W^TH $ There are numerous methods for solving for W and H , but let this just serve as an example problem. We could solve this problem with scipy.optimize.minimize by first defining

Python - Minimizing Chi-squared

≡放荡痞女 提交于 2019-12-04 11:27:04
I have been trying to fit a linear model to a set of stress/strain data by minimizing chi-squared. Unfortunately using the code below is not correctly minimizing the chisqfunc function. It is finding the minimum at the initial conditions, x0 , which is not correct. I have looked through the scipy.optimize documentation and tested minimizing other functions which has worked correctly. Could you please suggest how to fix the code below or suggest another method I can use to fit a linear model to data by minimizing chi-squared? import numpy import scipy.optimize as opt filename = 'data.csv' data

How to find the nearest points to given coordinates with MATLAB?

孤街醉人 提交于 2019-12-01 22:26:07
问题 I need to solve a minimization problem with Matlab and I'm wondering which is the easiest solution. All the potential solutions that I've been thinking in require lot of programming effort. Suppose that I have a lat/long coordinate point (A,B), what I need is to search for the nearest point to this one in a map of lat/lon coordinates. In particular, the latitude and longitude arrays are two matrices of 2030x1354 elements (1km distance) and the idea is to find the unique indexes in those

z3 minimization and timeout

夙愿已清 提交于 2019-12-01 20:54:05
问题 I try to use the z3 solver for a minimization problem. I was trying to get a timeout, and return the best solution so far. I use the python API, and the timeout option "smt.timeout" with set_option("smt.timeout", 1000) # 1s timeout This actually times out after about 1 second. However a larger timeout does not provide a smaller objective. I ended up turning on the verbosity with set_option("verbose", 2) And I think that z3 successively evaluates larger values of my objective, until the

z3 minimization and timeout

亡梦爱人 提交于 2019-12-01 20:25:56
I try to use the z3 solver for a minimization problem. I was trying to get a timeout, and return the best solution so far. I use the python API, and the timeout option "smt.timeout" with set_option("smt.timeout", 1000) # 1s timeout This actually times out after about 1 second. However a larger timeout does not provide a smaller objective. I ended up turning on the verbosity with set_option("verbose", 2) And I think that z3 successively evaluates larger values of my objective, until the problem is satisfiable: (opt.maxres [0:6117664]) (opt.maxres [175560:6117664]) (opt.maxres [236460:6117664])

Two dimensional Optimization (minimization) in Python (using scipy.optimize)

独自空忆成欢 提交于 2019-12-01 06:08:12
问题 I am trying to optimize (minimize) a two dimensional function E(n,k) defined as follows: error=lambda x,y,w: (math.log(abs(Tformulated(x,y,w))) - math.log(abs(Tw[w])))**2 + (math.atan2(Tformulated(x,y,w).imag,Tformulated(x,y,w).real) - math.atan2(Tw[w].imag,Tw[w].real))**2 where Tformulated is obtained as follows : def Tformulated(n,k,w): z=1j L=1 C=0.1 RC=(w*L)/C n1=complex(1,0) n3=complex(1,0) n2=complex(n,k) FP=1/(1-(((n2-n1)/(n2+n1))*((n2-n3)/(n2+n3))*math.exp(-2*z*n2*RC))) Tform=((2*n2*

Using scipy to minimize a function that also takes non variational parameters

陌路散爱 提交于 2019-12-01 00:18:21
I want to use the scipy.optimize module to minimize a function. Let's say my function is f(x,a) : def f(x,a): return a*x**2 For a fixed a , I want to minimize f(x,a) with respect to x . With scipy I can import for example the fmin function (I have an old scipy: v.0.9.0), give an initial value x0 and then optimize ( documentation ): from scipy.optimize import fmin x0 = [1] xopt = fmin(f, x0, xtol=1e-8) which fails because f takes two arguments and fmin is passing only one (actually, I haven't even defined a yet). If I do: from scipy.optimize import fmin x0 = [1] a = 1 xopt = fmin(f(x,a), x0,

Using scipy to minimize a function that also takes non variational parameters

自作多情 提交于 2019-11-30 18:11:59
问题 I want to use the scipy.optimize module to minimize a function. Let's say my function is f(x,a) : def f(x,a): return a*x**2 For a fixed a , I want to minimize f(x,a) with respect to x . With scipy I can import for example the fmin function (I have an old scipy: v.0.9.0), give an initial value x0 and then optimize (documentation): from scipy.optimize import fmin x0 = [1] xopt = fmin(f, x0, xtol=1e-8) which fails because f takes two arguments and fmin is passing only one (actually, I haven't