central_limit.py 文件源码

python
阅读 53 收藏 0 点赞 0 评论 0

项目:prml 作者: Yevgnen 项目源码 文件源码
def main():
    fig = plt.figure()
    x = np.linspace(0, 1, 100)
    sizes = [1, 2, 20, 50]
    fig_row, fig_col = 2, 4

    # Mean of i.i.d uniform
    for i, n in enumerate(sizes):
        ax = fig.add_subplot(fig_row, fig_col, i + 1)
        data, gaussian = central_limit(uniform_dist.rvs, n, 1000)
        ax.hist(data, bins=20, normed=True, alpha=0.7)
        plt.plot(x, gaussian.pdf(x), 'r')
        plt.title('n={0}'.format(n))

    # Mean of i.i.d beta(1, 2)
    for i, n in enumerate(sizes):
        ax = fig.add_subplot(fig_row, fig_col, i + fig_col + 1)
        data, gaussian = central_limit(beta_dist(1, 2).rvs, n, 1000)
        ax.hist(data, bins=20, normed=True, alpha=0.7)
        plt.plot(x, gaussian.pdf(x), 'r')
        plt.title('n={0}'.format(n))

    plt.show()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号