Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: TruncatedNormal does not support data imputation #6999

Closed
twiecki opened this issue Nov 7, 2023 · 0 comments · Fixed by #7001
Closed

BUG: TruncatedNormal does not support data imputation #6999

twiecki opened this issue Nov 7, 2023 · 0 comments · Fixed by #7001
Labels

Comments

@twiecki
Copy link
Member

twiecki commented Nov 7, 2023

Describe the issue:

Posterior sampling over a Normal with observed nans works, while the same doesn't work with a TruncatedNormal.

Reproduceable code example:

import pymc as pm

with pm.Model():
    mu1 = pm.TruncatedNormal("mu1", mu=1, sigma=2, lower=0)
    pm.Normal("x1", mu=mu1, sigma=.5, observed=np.array([.1, .2, .5, np.nan, np.nan]))
    pm.sample() # works

    mu2 = pm.TruncatedNormal("mu2", mu=1, sigma=2, lower=0)
    pm.TruncatedNormal("x2", mu=mu2, sigma=.5, lower=0, observed=np.array([.1, .2, .5, np.nan, np.nan]))
    pm.sample() # does not work

Error message:

<details>

SamplingError                             Traceback (most recent call last)
Cell In[155], line 8
      6 mu2 = pm.TruncatedNormal("mu2", mu=1, sigma=2, lower=0)
      7 pm.TruncatedNormal("x2", mu=mu2, sigma=.5, lower=0, observed=np.array([.1, .2, .5, np.nan, np.nan]))
----> 8 pm.sample()

File ~/micromamba/envs/pymc5/lib/python3.11/site-packages/pymc/sampling/mcmc.py:706, in sample(draws, tune, chains, cores, random_seed, progressbar, step, nuts_sampler, initvals, init, jitter_max_retries, n_init, trace, discard_tuned_samples, compute_convergence_checks, keep_warning_stat, return_inferencedata, idata_kwargs, nuts_sampler_kwargs, callback, mp_ctx, model, **kwargs)
    704 ip: Dict[str, np.ndarray]
    705 for ip in initial_points:
--> 706     model.check_start_vals(ip)
    707     _check_start_shape(model, ip)
    709 # Create trace backends for each chain

File ~/micromamba/envs/pymc5/lib/python3.11/site-packages/pymc/model/core.py:1702, in Model.check_start_vals(self, start)
   1699 initial_eval = self.point_logps(point=elem)
   1701 if not all(np.isfinite(v) for v in initial_eval.values()):
-> 1702     raise SamplingError(
   1703         "Initial evaluation of model at starting point failed!\n"
   1704         f"Starting values:\n{elem}\n\n"
   1705         f"Logp initial evaluation results:\n{initial_eval}\n"
   1706         "You can call `model.debug()` for more details."
   1707     )

SamplingError: Initial evaluation of model at starting point failed!
Starting values:
{'mu1_interval__': array(-0.22790012), 'x1_unobserved': array([1.02430783, 0.49541385]), 'mu2_interval__': array(0.51429339), 'x2_unobserved_interval__': array([-inf, -inf])}

Logp initial evaluation results:
{'mu1': -1.48, 'x1_unobserved': -0.74, 'mu2': -0.79, 'x2_unobserved': -inf, 'x1_observed': -2.53, 'x2_observed': -12.71}
You can call `model.debug()` for more details.
PyMC version information:

5.8.0

Context for the issue:

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant