Skip to content

BUG: data as observed in RV #7649

@williambdean

Description

@williambdean

Describe the issue:

Example:

pymc-labs/pymc-marketing#1383 (comment)

Reproduceable code example:

import numpy as np
import pymc as pm

seed = sum(map(ord, "Scaling the likelihood depended variables doesn't work in PyMC"))
rng = np.random.default_rng(seed)

true_mu = 100
true_sigma = 30

n_obs = 10
coords = {
    "date": np.arange(n_obs),
}

dist = pm.Normal.dist(mu=true_mu, sigma=true_sigma, shape=n_obs)
data = pm.draw(dist, random_seed=rng)

scaling = data.max()

with pm.Model(coords=coords) as model:
    mu = pm.Normal("mu")
    sigma = pm.HalfNormal("sigma")

    target = pm.Data("target", data, dims="date")
    scaled_target = target / scaling

    pm.Normal("observed", mu=mu, sigma=sigma, observed=scaled_target)

Error message

            if not is_valid_observed(observed):
>               raise TypeError(
                    "Variables that depend on other nodes cannot be used for observed data."
                    f"The data variable was: {observed}"
                )
E               TypeError: Variables that depend on other nodes cannot be used for observed data.The data variable was: True_div.0

PyMC version information:

5.20.0

Context for the issue:

Would like to define my scaling within the model definition

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