【问题标题】:Random sampling from a given distribution从给定分布中随机抽样
【发布时间】:2016-12-07 16:04:54
【问题描述】:

好的,所以我有这两个部分的 CDF

def cdfH1a(x):
    return 0.189497583190681*np.sqrt(2 * np.pi)*sp.erf(np.sqrt(2)* (x/2))
def cdfH1b(x):
    return 0.0141047395886939*np.sqrt(np.pi)*sp.erf(7.07106781186547*x - 14.1421356237309)

我这样做是为了找到经验 CDF

sorted = np.sort(sampleH1)
yVals = np.arange(len(sorted))/float(len(sorted))
plt.plot(sorted, yVals)
plt.show()

但我不知道如何从我的 CDF 中生成 10000 个随机样本(这些样本将被放入 sampleH1)

目前,我正在这样做,但我认为它不正确

sampleH1 = []
for x in sampleH0: 
    sampleH1.append(x + (cdfH1a(x) + cdfH1b(x)))

其中 sampleH0 是来自正态分布 CDF 的 10000 个样本

如果有人能解释一下,那就太好了,谢谢

【问题讨论】:

标签: python numpy math cdf


【解决方案1】:

如果你使用的是 numpy,你可以放弃循环:

sampleH1 = sampleH0 + cdfH1a(sampleH0) + cdfH1b(sampleH0)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-24
    • 2011-05-23
    • 1970-01-01
    相关资源
    最近更新 更多