[英]overflow in exp using python scipy.optimize.basinhopping
I am using scipy.optimize.basinhopping in order to fit a simple exponential function (a exp(-b time)) to real data. 我正在使用scipy.optimize.basinhopping,以使简单的指数函数( exp(-b时间))适合实际数据。 I try to have appropriate initial guesses (for a and b) but in some iterations (for some values basinhopping guesses) "overflow in exp" occurs.
我尝试进行适当的初始猜测(针对a和b),但是在某些迭代中(针对某些值进行跳槽猜测),发生“ exp溢出”。 I know that it is because of a very large answer to be calculated by exp.
我知道这是因为要通过exp计算出很大的答案。 By the way the result is something absolutely wrong.
顺便说一句,结果是绝对错误的。 Is there anyway to ask the code to ignore those error containing guesses in order to prevent wrong results in output?
是否总有要求代码忽略那些包含猜测的错误,以防止输出错误的结果? + time goes from 0 to something around e+06 Thanks for your care and help
+时间从0到e + 06左右。感谢您的关心和帮助
here is my code. 这是我的代码。 after running, I get overflow error for some values for bk, so the resulting value for ret is absolutely wrong, something far far from the correct answer.
运行后,对于bk的某些值,我得到了溢出错误,因此ret的结果值绝对是错误的,与正确答案相距甚远。 :(
:(
def model(bk):
s = 0
realData = data()
modelData = []
modelData.append(realData[0])
for time in range(len(realData) - 1):
x = realData[0] * np.exp((bk[0] * np.exp(bk[1]*time))*time)
y = 1 - realData[0] + x
i = x / y
modelData.append(i)
s+=np.abs(i-realData[time])
return(s)
def optimize():
bk0 = [1,-1]
minimizer_kwargs = {"method" : "BFGS"}
ret = basinhopping(model, bk0, minimizer_kwargs=minimizer_kwargs, niter=100)
print(ret)
optimize()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.