Example #1
0
def test_joint_mean_var_sampler():
    '''run the gibbs sampler on (mu, var) of the gaussian conditioned on data and plots'''

    mean, scale, size = 0, 1, 1000
    data = generate_data(mean, scale, size)
    model = Gaussian_Model(data)
    model.gibbs_sample(num_samples=20000)
    mus = model.get_mus(15000, 10)
    vars = model.get_vars(15000, 10)

    plt.hist(mus)
    plt.hist(vars)
    plt.show()
Example #2
0
def test_mu_sampler():
    '''tests an exact sampler of the mu of the gaussian conditioned on data and known var'''

    mean, scale, size = 0, 1, 10000
    data = generate_data(mean, scale, size)
    model = Gaussian_Model(data)
    mus = []
    for num in xrange(size):
        mus.append(model.sample_mean(np.mean(data), float(10^5), float(1), size))
    error = abs(np.mean(means)-mean)
    print error
    plt.hist(means, bins=1000)
    plt.show()
Example #3
0
def test_var_sampler():
    '''tests an exact sampler of the var of the gaussian conditioned on data and know mu'''

    mean, scale, size = 0, 1, 10000
    data = generate_data(mean, scale, size)
    model = Gaussian_Model(data)
    vars = []
    for num in xrange(size):
        vars.append(model.sample_var(0))
    error = abs(np.mean(vars)-scale*scale)
    print error
    plt.hist(vars, bins=1000)
    plt.show()