繁体   English   中英

python 非线性回归:function 的选择取决于参数

[英]python non-linear regression: choosing of function depended on param

我目前正在使用“scipy.optimize.curve_fit”

在我拟合的方程(分段)中,“ theta ”首先由参数之一(“ D ”)计算,然后方程的选择取决于“ theta ”(因此,取决于“ D ”)。 但是,似乎 scipy 将参数作为列表或其他输入,因此它没有为每个“ D ”单独选择正确的方程。 相反,它要求我使用“theta.any()”或“theta.all()”,这不是我想要的。

有没有可以做我想做的模块?

非常感谢,

克里斯托弗

import numpy as np from scipy.optimize import curve_fit def MahonOldham(t,D:'m^2/s',c:'mM'): n=1 F=96485 #A s / mol pi=3.14 a=12.5*10**-6 # m D*=10**-10 theta=D*t/a**2 if theta <=1.281: #HERE..: factor=1/(np.sqrt(pi*theta))+1+np sqrt(theta/(4*pi))-3*theta/25+(3*theta**(3/2))/226 I=n*pi*F*c*D*a*factor #nA else factor=4/pi+8/np sqrt(pi**5*theta)+25*theta**(-3/2)/2792-theta**(-5/2)/3880-theta**(-7/2)/4500 I=n*pi*F*c*D*a*factor #nA return I*10**9

这是你想要的模块,你只需要适应它的API。 The function curve_fit passes to your function arrays for D and c rather than single values, so you need to vectorize MahonOldham (and, please, rename to mahon_oldham , PEP8).

特别是用np.where替换if语句:

 I = np.where( theta <= 1.281, 1/(np.sqrt..., # first case 4/pi+8/np(..., # second case )

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM