Scan logprob fails when unvalued stochastic outputs are returned
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 42/100
Research direction
Start with the Python reproduction in the issue, focusing on the two CustomDist definitions and their pytensor.scan outputs. Run it and compare logp1 with logp2; done means unvalued stochastic outputs no longer cause the two equivalent models to produce different log probabilities.
Written by the indexing model from the issue text.
Description
Description
Found by @lucianopaz
import numpy as np
import pymc as pm
import pytensor
import pytensor.tensor as pt
from pymc.pytensorf import collect_default_updates
steps = 4
def ar_dist1(rho, sigma, size):
def ar_step(x_tm1, rho, sigma):
eps_t = pm.Normal.dist(sigma=sigma)
mu = x_tm1 * rho
x = mu + eps_t
return x, collect_default_updates([x])
ar_innov, _ = pytensor.scan(
fn=ar_step,
outputs_info=[{"initial": pt.zeros(()), "taps": [-1]}],
non_sequences=[rho, sigma],
n_steps=steps,
strict=True,
)
return ar_innov
def ar_dist2(rho, sigma, size):
def ar_step(x_tm1, rho, sigma):
eps_t = pm.Normal.dist(sigma=sigma)
mu = x_tm1 * rho
x = mu + eps_t
return [x, eps_t], collect_default_updates([x])
[ar_innov, _], _ = pytensor.scan(
fn=ar_step,
outputs_info=[{"initial": pt.zeros(()), "taps": [-1]}, None],
non_sequences=[rho, sigma],
n_steps=steps,
strict=True,
)
return ar_innov
with pm.Model() as m:
rho = 0.1
sigma = 0.1
observed = np.arange(steps)
pm.CustomDist(
"ar_dist1",
rho,
sigma,
dist=ar_dist1,
observed=observed,
)
pm.CustomDist(
"ar_dist2",
rho,
sigma,
dist=ar_dist2,
observed=observed,
)
logp1, logp2 = m.compile_logp(sum=False)({})
np.testing.assert_allclose(logp1, logp2)
"""
AssertionError:
Not equal to tolerance rtol=1e-07, atol=0
Mismatched elements: 2 / 4 (50%)
Max absolute difference: 58.
Max relative difference: 0.12928641
x: array([ 1.383647, -48.616353, -179.116353, -390.616353])
y: array([ 1.383647, -48.616353, -198.616353, -448.616353])
"""
- Dominant language
- Python
- Stars
- 9.8k
- Forks
- 2.3k
- Avg merge
- 21h 39m
- Merged PRs (30d)
- 5
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from pymc-devs/pymc
-
Difficulty 1/5 Under an hour Newbie friendliness 95/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
docs
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
bancolombia/sentinel#23 ·
-
test md OpenCI
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
bug client
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100