Skip to content

Document the role of transforms #7040

Closed
@velochy

Description

@velochy

Describe the issue:

If a transformation is done with an observed variable, it seems to flat out be ignored.

In the example below, the observations are out of the interval given to pm.Normal, but it still fits as if the transformation was not there. Sampling the posterior predictive also ignores the transform, giving values way out of the range.

Transformations are currently not very well documented so I might be misunderstanding something, but having an interval transform keep values within the interval even on observations seems like a sensible expectation so I'm filing this as a bug.

Reproduceable code example:

import pymc as pm
import numpy as np

with pm.Model() as model:
    
    obs = pm.MutableData("obs", np.array([2]*10 + [-2]*10))                
    
    sd = pm.HalfNormal('sd', sigma=2)
    val = pm.Normal('val', mu=0, sigma=sd,    
                     transform=pm.distributions.transforms.Interval(-1,1),
                     observed=obs)
    
    idata = pm.sample()
    pp = pm.sample_posterior_predictive(idata)
    
    pp.posterior_predictive.val.min(), pp.posterior_predictive.val.max()

Error message:

No response

PyMC version information:

PyMC 5.9.2

Context for the issue:

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions