Пример #1
0
def test_prior_predictive(crossed_data):
    crossed_data["count"] = (crossed_data["Y"] -
                             crossed_data["Y"].min()).round()
    # New default priors are too wide for this case... something to keep investigating
    model = Model(
        "count ~ threecats + continuous + dummy",
        crossed_data,
        family="poisson",
        automatic_priors="mle",
    )
    model.fit(tune=0, draws=2)
    pps = model.prior_predictive(draws=500)

    keys = ["Intercept", "threecats", "continuous", "dummy"]
    shapes = [(1, 500), (1, 500, 2), (1, 500), (1, 500)]

    for key, shape in zip(keys, shapes):
        assert pps.prior[key].shape == shape

    assert pps.prior_predictive["count"].shape == (500, 120)
    assert pps.observed_data["count"].shape == (120, )

    pps = model.prior_predictive(draws=500, var_names=["count"])
    assert pps.groups() == ["prior_predictive", "observed_data"]

    pps = model.prior_predictive(draws=500, var_names=["Intercept"])
    assert pps.groups() == ["prior"]
Пример #2
0
def test_prior_predictive(crossed_data):
    crossed_data["count"] = (crossed_data["Y"] - crossed_data["Y"].min()).round()
    model = Model("count ~ threecats + continuous + dummy", crossed_data, family="poisson")
    model.fit(tune=0, draws=2)
    pps = model.prior_predictive(draws=500)

    keys = ["Intercept", "threecats", "continuous", "dummy"]
    shapes = [(1, 500), (1, 500, 2), (1, 500), (1, 500)]

    for key, shape in zip(keys, shapes):
        assert pps.prior[key].shape == shape

    assert pps.prior_predictive["count"].shape == (1, 500, 120)
    assert pps.observed_data["count"].shape == (120,)

    pps = model.prior_predictive(draws=500, var_names=["count"])
    assert pps.groups() == ["prior_predictive", "observed_data"]

    pps = model.prior_predictive(draws=500, var_names=["Intercept"])
    assert pps.groups() == ["prior"]