def test_gamma_code(): alpha = Gamma(1.0, 1.2, name='alpha') beta = Gamma(2.1, 2.2, name='beta') model = GammaQM(alpha, beta) code = model.code with open(FILLED_TEMPLATES_PATH / 'os_gamma.stan') as f: code_hard_coded = f.read() assert code == code_hard_coded
def test_gamma_check_domain_expected_fail(): alpha = Gamma(1.0, 1.2, name='alpha') beta = Gamma(2.1, 2.2, name='beta') model = GammaQM(alpha, beta) 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)
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
def test_weibull_code(): alpha = Gamma(1.0, 1.2, name='alpha') sigma = Weibull(2.1, 2.2, name='sigma') model = WeibullQM(alpha, sigma) code = model.code with open(FILLED_TEMPLATES_PATH / 'os_weibull.stan') as f: code_hard_coded = f.read() assert code == code_hard_coded
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"))'
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'
def gamma_compiled_model(): alpha = Gamma(1., 1., name='alpha') beta = Gamma(1., 1., name='beta') model = GammaQM(alpha, beta) model.compile() return model
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