Skip to content

DOC: pymc.CustomDist example does not work in the documentation #7654

Open
@helios1014

Description

@helios1014

Issue with current documentation:

When trying to run the following example code from the PYMC.CustomDist documentation, I get the error message "Core implementation of CustomDist_custom_dist_rv{"()->()"} not implemented":

from typing import Optional, Tuple

import numpy as np
import pymc as pm
from pytensor.tensor import TensorVariable

def logp(value: TensorVariable, mu: TensorVariable) -> TensorVariable:
    return -(value - mu)**2

def random(
    mu: np.ndarray | float,
    rng: Optional[np.random.Generator] = None,
    size : Optional[Tuple[int]]=None,
) -> np.ndarray | float :
    return rng.normal(loc=mu, scale=1, size=size)

with pm.Model():
    mu = pm.Normal('mu', 0 , 1)
    pm.CustomDist(
        'custom_dist',
        mu,
        logp=logp,
        random=random,
        signature="()->()",
        observed=np.random.randn(100, 3),
        size=(100, 3),
    )
    prior = pm.sample_prior_predictive(10)

Idea or request for content:

I do not know enough about PYMC to determine if this is a bug, my leaving something out, or the code not being correctly written in the documentation. If it is a bug, I will gladly report it as such. If if is not, please let me know what the correction is.

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