【发布时间】:2013-01-02 13:33:08
【问题描述】:
我正在尝试为观察到的数据找到伽马函数的逆 CDF,以便找到传递函数。整个目的是通过 CDF 匹配 CDFobs(y) = CDFsim(x) 来纠正模拟数据中的偏差。我尝试使用以下抛出和错误的方法来做到这一点。
下图显示了 CDF 和 plot(c) 中的传递函数。我正在尝试复制相同的内容。请帮我完成剧情。
import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import interp1d
import scipy.stats as st
sim = st.gamma(1,loc=0,scale=0.8) # Simulated
obs = st.gamma(2,loc=0,scale=0.7) # Observed
x = np.linspace(0,4,1000)
simpdf = sim.pdf(x)
obspdf = obs.pdf(x)
plt.plot(x,simpdf,label='Simulated')
plt.plot(x,obspdf,'r--',label='Observed')
plt.title('PDF of Observed and Simulated Precipitation')
plt.legend(loc='best')
plt.show()
plt.figure(1)
simcdf = sim.cdf(x)
obscdf = obs.cdf(x)
plt.plot(x,simcdf,label='Simulated')
plt.plot(x,obscdf,'r--',label='Observed')
plt.title('CDF of Observed and Simulated Precipitation')
plt.legend(loc='best')
plt.show()
# Inverse CDF
invcdf = interp1d(obscdf,x)
transfer_func = invcdf(simcdf)
plt.figure(2)
plt.plot(transfer_func,x,'g-')
plt.show()
回溯(最近一次通话最后一次): 文件“/home/bias_correction.py”,第 54 行,在 transfer_func = invcdf(simcdf)
文件“/usr/lib/python2.7/dist-packages/scipy/interpolate/interpolate.py”,第 357 行,在_调用_中 out_of_bounds = self._check_bounds(x_new)
文件“/usr/lib/python2.7/dist-packages/scipy/interpolate/interpolate.py”,第 415 行,在 _check_bounds raise ValueError("x_new 中的值高于插值" ValueError:x_new 中的值超出插值范围。
【问题讨论】:
-
您已经给出了错误消息,但没有给出错误发生的位置。如果您粘贴完整的堆栈跟踪,那么您更有可能得到答案。作为一般建议,当您开始尝试诊断问题时,堆栈跟踪通常是一个很好的地方,因为您可以在自己的代码中找到错误发生的位置。
标签: python interpolation cdf