Skip to content

Forward sampling functions should warn that they ignore Potential in a model #3865

Closed
@AlexAndorra

Description

@AlexAndorra

Description of your problem

As discussed here with @junpenglao, it seems like sample_posterior_predictive cannot account for a Potential in a model with Geometric likelihood:

with pm.Model() as m_bike:
    a = pm.Normal("a", 0.0, 0.5)
    bT = pm.Normal("bT", 0.0, 0.2)

    p = pm.math.invlogit(a + bT * bike_data["temp_std"])

    bike_count = pm.Geometric('bike_count', p, observed=bike_data["count"])
    pm.Potential('constraint', tt.switch(bike_count > 1100, -np.inf, 0.))

    trace_bike_poisson = pm.sample(1000, tune=2000, random_seed=RANDOM_SEED)
    post_samples = pm.sample_posterior_predictive(
        trace_bike_poisson, random_seed=RANDOM_SEED
    )

idata = az.from_pymc3(trace=trace_bike_poisson, posterior_predictive=post_samples)
az.plot_ppc(idata);

This samples perfectly, but the constraint was not applied to PP samples:
Capture d’écran 2020-03-10 à 21 27 48
The data come from Kaggle’s bike-sharing demand contest.

Versions and main components

  • PyMC3 Version: Master
  • Theano Version: 1.0.4
  • Python Version: 3.7.6
  • Operating system:OS X
  • How did you install PyMC3: pip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions