scipy-optimize

How to learn or find weight vector and remove outliers for all data point using Constrained np.polyfit or curve_fit?

橙三吉。 提交于 2020-04-30 09:19:07
问题 I am trying to fit a exponential decay to some experimental data and using polyfit in numpy. Also, fit itself is weighted, that is every data point has some weight associated with it and the polyfit function can find that optimal weights ? Referred: Constrained np.polyfit So final output would be coefficient value and the weight vector for every associated data points. Also I want to constrain M parameter between 0.9 to 1 and N to -0.001 to -0.009 Data: t(x) rate(y) 0 0.950 1 0.940 2 0.931 3

custom made regression using average absolute deviation

久未见 提交于 2020-03-04 16:41:49
问题 Following this post, I now have serious doubts if R-squared or F-test are good indications of a good linear fit into some data with random noise. Hence, I want to develop a custom made regression function so I can both learn how it works and maybe improve upon the existing tools. Consider these randomly generated ndarrays x and y : import numpy as np np.random.seed(42) x = np.random.rand(30) * 10 y = 1.5 * x + 0.3 + (np.random.rand(30) - 0.5) * 3.5 now I can define the average/mean absolute

passing a function with multiple independent variables and multiple arguments to scipy optimize minimize

戏子无情 提交于 2020-03-03 13:59:36
问题 Following this question, I want to make my question as specific as possible focusing on the part that I can not solve. Consider a very simple function of: def foo(x, y, a, b, c): return a * x**4 + b * y**2 + c now I want to use the scipy.optimize.minimize or any of other existing functions to find the x and y (i.e., parameters) to minimize foo given the constants a , b , and c (i.e., args). If I had only one parameter and multiples arguments then from this page I could do: def foo(x, *args):

Constrained Optimization of battery scheduling in microgrid

ⅰ亾dé卋堺 提交于 2020-03-03 11:55:21
问题 Given inputs such as electricity consumption, generation from solar panel, price, (All at a given time t), we have a battery, and we want to evaluate how much it should (dis)/charge at any given time. The Problem can be formulated as follows: Pt = price of electricity at time t Lt = consumption of electricity at time t Zt = charge of battery at time t (how much is in the battery) St = Electricity generated from solar generator at time t Qt = amount the battery (dis)/charges at time t the

Constrained Optimization of battery scheduling in microgrid

浪尽此生 提交于 2020-03-03 11:52:05
问题 Given inputs such as electricity consumption, generation from solar panel, price, (All at a given time t), we have a battery, and we want to evaluate how much it should (dis)/charge at any given time. The Problem can be formulated as follows: Pt = price of electricity at time t Lt = consumption of electricity at time t Zt = charge of battery at time t (how much is in the battery) St = Electricity generated from solar generator at time t Qt = amount the battery (dis)/charges at time t the

fitting step function with variation in the step location with scipy optimize curve_fit

风格不统一 提交于 2020-02-05 05:21:05
问题 I am trying to fit x y data which look something like x = np.linspace(-2, 2, 1000) a = 0.5 yl = np.ones_like(x[x < a]) * -0.4 + np.random.normal(0, 0.05, x[x < a].shape[0]) yr = np.ones_like(x[x >= a]) * 0.4 + np.random.normal(0, 0.05, x[x >= a].shape[0]) y = np.concatenate((yl, yr)) plt.scatter(x, y, s=2, color='k') I'm using a variation of the Heaviside step function def f(x, a, b): return 0.5 * b * (np.sign(x - a)) and fitting with popt, pcov = curve_fit(f, x, y, p0=p) where p is some

How to pass sympy expressions to be used with scipy?

ⅰ亾dé卋堺 提交于 2020-01-25 06:53:09
问题 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. My real code has too many loops and every time root from scipy iterates those loops. This is a very simplified version of what I tried. I made the equations with sympy symbols and then I used lambdify to take the equations out of sympy but the

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

Scipy TypeError: only size-1 arrays can be converted to Python scalars when using dogleg in optimize, why?

时间秒杀一切 提交于 2019-12-11 18:04:28
问题 I am using the method dogleg within optimize.minimize tool in Scipy to solve my non-linear 2-equations system. sol = optimize.minimize(self.myF, self.initialWCEC,rZ,jac=self.myJacobian,hess=self.myJHessian,tol=6e-11, method='dogleg',options={'gtol':1e-12}) I have defined my own hessian and Jacobian functions in order to use this method. They look like def myJacobian(self,WCEC): jacF = numpy.array([[- k - (k**2*EC*WC*(Rs - rZ))/50,- (k**2*EC**2*(Rs - rZ))/100 - (Cmax**2*w**2*(Rs - rZ))/100],