pymc-devs / pymc-devs/pymc

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

Open
#7,654 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

docs hackathon
Dominant language
Python
Stars
9.8k
Forks
2.3k
Avg merge
21h 39m
Merged PRs (30d)
5

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start from the CustomDist documentation example shown in the issue and run it to reproduce the CustomDist_custom_dist_rv error. Check the documented CustomDist API and example context to determine whether the snippet is incomplete or incorrect; done when the published example runs successfully or clearly documents the required correction.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python
Domain
documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.