简体   繁体   English

使用python scipy.optimize.basinhopping在exp中溢出

[英]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.

相关问题 使用scipy.optimize.basinhopping时'minimization_failures'的含义? - Meaning of 'minimization_failures' when using scipy.optimize.basinhopping? 了解scipy.optimize.basinhopping的输出 - Understanding the output of scipy.optimize.basinhopping scipy.optimize.basinhopping interval并接受测试合成器 - scipy.optimize.basinhopping interval and accept test syntaces 为什么 scipy.optimize.basinhopping 给出不同的结果 - why scipy.optimize.basinhopping give different results 如何在scipy.optimize.basinhopping中禁用本地最小化过程? - How to disable the local minimization process in scipy.optimize.basinhopping? 基于 scipy.optimize.basinhopping 中的 Levenberg-Marquardt 的自定义最小化器 - Custom minimizer based on Levenberg-Marquardt in scipy.optimize.basinhopping 如何访问从 scipy.optimize.basinhopping(不最小化)返回的 OptimizeResult 实例的 `success` 属性? - How to access `success` attribute of OptimizeResult instance returned from scipy.optimize.basinhopping (NOT minimize)? scipy.optimize.basinhopping 不调用 accept_test。 为什么? - scipy.optimize.basinhopping doesn't call accept_test. Why? Python中scipy / numpy中的exp溢出? - Overflow in exp in scipy/numpy in Python? scipy.optimize.basinhopping。 带参数的对象函数 - scipy.optimize.basinhopping. Object function with argument(s)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM