Skip to content

sample_posterior_predictive does not consider changes in "ConstantData" and "Constant coords" #6876

Open
@ricardoV94

Description

@ricardoV94

Description

The existing checks assume the same model is used between sample and sample_posterior_predictive, in which case the only variable that can be changed are mutable ones.

However if one wants to sample in a new model (as described in https://www.pymc-labs.io/blog-posts/out-of-model-predictions-with-pymc/), they have to artificially use mutable variables even if they never intend to change them after definition:

import pymc as pm

with pm.Model() as m:
    x = pm.ConstantData("x", [0, 0, 0, 0, 0, 0])
    b = pm.Normal("b", x)
    y = pm.Normal("y", b.sum(), observed=0)
    idata = pm.sample()

with pm.Model() as pred_m:
    x = pm.ConstantData("x", [0, 0, 0])
    # x = pm.MutableData("x", [0, 0, 0])  # This works fine
    b = pm.Normal("b", x)
    y = pm.Normal("y", b.sum(), observed=0)
    idata = pm.sample_posterior_predictive(idata, predictions=True,)  # Fails because b isn't resampled

A similar thing happens for variables whose dims are changed. If they were defined in coords_mutable it will resample correctly, but not if they were defined as vanilla "constant" coords

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