Esempio n. 1
0
def test_mh_2d_2chains_non_concatenated():
    target = Distributions.MultivariateNormal([0., 0.]).pdf
    x = MetropolisHastings(dimension=2, pdf_target=target, concatenate_chains=False, n_chains=2, random_state=123,
                           nsamples=60)
    assert [[round(float(x.samples[-1][0][0]), 3), round(float(x.samples[-1][0][1]), 3)],
            [round(float(x.samples[-1][1][0]), 3), round(float(x.samples[-1][1][1]), 3)]] == [[1.767, 1.465],
                                                                                              [-0.064, -0.533]]
Esempio n. 2
0
def test_mmh_2d_joint_proposal():
    target = Distributions.MultivariateNormal([0., 0.]).pdf
    proposal = Distributions.JointIndependent(marginals=[Distributions.Normal(scale=0.2),
                                                         Distributions.Normal(scale=0.2)])
    x = ModifiedMetropolisHastings(dimension=2, pdf_target=target, n_chains=1, proposal=proposal, random_state=123,
                                   nsamples=10)
    assert [round(float(x.samples[-1][0]), 3), round(float(x.samples[-1][1]), 3)] == [-0.783, -0.195]
Esempio n. 3
0
def test_mh_2d_seed():
    target = Distributions.MultivariateNormal([0., 0.]).pdf
    x = MetropolisHastings(pdf_target=target, seed=[0., 0.], n_chains=1, random_state=123, nsamples=10)
    assert [round(float(x.samples[-1][0]), 3), round(float(x.samples[-1][1]), 3)] == [-0.406, -1.217]
Esempio n. 4
0
def test_mh_2d_2chains():
    target = Distributions.MultivariateNormal([0., 0.]).pdf
    x = MetropolisHastings(dimension=2, pdf_target=target, n_chains=2, random_state=123, nsamples=60)
    assert [round(float(x.samples[-1][0]), 3), round(float(x.samples[-1][1]), 3)] == [-0.064, -0.533]
Esempio n. 5
0
def test_mh_2d_nsamples_check():
    target = Distributions.MultivariateNormal([0., 0.]).pdf
    x = MetropolisHastings(dimension=2, pdf_target=target, n_chains=2, random_state=123, nsamples=60)
    assert x.nsamples_per_chain + x.samples_counter == 90
Esempio n. 6
0
def test_mh_2d_burn_jump():
    target = Distributions.MultivariateNormal([0., 0.]).pdf
    x = MetropolisHastings(dimension=2, log_pdf_target=target, burn_length=10, jump=2, n_chains=1,
                           random_state=123, nsamples=10)
    assert x.iterations_number == 30