Ejemplo n.º 1
0
def test_QM_expected_fail():
    '''input not of type Distribtion'''
    parameters_dict = {
        'a': Normal(0., 1., name='a'),
        'b': 1.  # input should be a Distribution
    }
    with pytest.raises(ValueError):
        QM(parameters_dict)
Ejemplo n.º 2
0
def test_lognormal_code():
    mu = Normal(1.0, 1.2, name='mu')
    sigma = Lognormal(2.1, 2.2, name='sigma')
    model = LognormalQM(mu, sigma)
    code = model.code
    with open(FILLED_TEMPLATES_PATH / 'os_lognormal.stan') as f:
        code_hard_coded = f.read()
    assert code == code_hard_coded
Ejemplo n.º 3
0
def test_normal_code():
    mu = Normal(0., 1., name='mu')
    sigma = Gamma(1., 1.2, name='sigma')
    model = NormalQM(mu, sigma)
    code = model.code
    with open(FILLED_TEMPLATES_PATH / 'os_normal.stan') as f:
        code_hard_coded = f.read()
    assert code == code_hard_coded
Ejemplo n.º 4
0
def test_lognormal_check_domain_expected_fail():
    mu = Normal(1.0, 1.2, name='mu')
    sigma = Lognormal(2.1, 2.2, name='sigma')
    model = LognormalQM(mu, sigma)
    N, q, X = 1000, [0.25, 0.5, 0.75], [-0.1, 1.0, 1.4]  #-0.1 is invalid
    with pytest.raises(ValueError):
        model.sampling(N, q, X)
    with pytest.raises(ValueError):
        model.optimizing(N, q, X)
Ejemplo n.º 5
0
def test_normalQM_print():
    mu = Normal(0., 1., name='mu')
    sigma = Gamma(1., 1., name='sigma')
    model = NormalQM(mu, sigma)
    assert str(
        model
    ) == 'NormalQM(Normal(mu=0.0, sigma=1.0, name="mu"), Gamma(alpha=1.0, beta=1.0, name="sigma"))'
    assert repr(
        model
    ) == 'NormalQM(Normal(mu=0.0, sigma=1.0, name="mu"), Gamma(alpha=1.0, beta=1.0, name="sigma"))'
Ejemplo n.º 6
0
def test_normalQM_template_replacements():
    mu = Normal(0., 1., name='loc')
    sigma = Gamma(1., 1., name='scale')
    model = NormalQM(mu, sigma)
    replacements = model._template_replacements()
    assert replacements['parametersnames'] == 'loc, scale'
    assert replacements['parameters'] == 'real loc;\n    real<lower=0> scale;'
    assert replacements['priors'] == \
            'loc ~ normal(0.0, 1.0);\n    scale ~ gamma(1.0, 1.0);'
    assert replacements['cdf'] == 'normal_cdf'
    assert replacements['lpdf'] == 'normal_lpdf'
    assert replacements['rng'] == 'normal_rng'
Ejemplo n.º 7
0
def lognormal_compiled_model():
    mu = Normal(1., 1., name='mu')
    sigma = Lognormal(1., 1., name='sigma')
    model = LognormalQM(mu, sigma)
    model.compile()
    return  model
Ejemplo n.º 8
0
def normal_compiled_model():
    mu = Normal(0., 1., name='mu')
    sigma = Gamma(1., 1.2, name='sigma')
    model = NormalQM(mu, sigma)
    model.compile()
    return  model