pymc-devs / pymc-devs/pymc-examples

UpdatingPriors

Open
#382 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
398
Forks
325
Avg merge
9d 15m
Merged PRs (30d)
1

Description

updating_priors:
[Notebook url] (https://docs.pymc.io/en/v3/pymc-examples/examples/pymc3_howto/updating_priors.html):
For the following code section, to get to the posterior trace, I had to change to trace.posterior.alpha.mean(axis=0), etc.
I am not sure if this is correct. Check the code:

for _ in range(10):
    # generate more data
    X1 = np.random.randn(size)
    X2 = np.random.randn(size) * 0.2
    Y = alpha_true + beta0_true * X1 + beta1_true * X2 + np.random.randn(size)
    model = Model()
    with model:
        # Priors are posteriors from previous iteration
        alpha = from_posterior("alpha", trace.posterior.alpha.mean(axis=0)) #CA
        beta0 = from_posterior("beta0", trace.posterior.beta0.mean(axis=0)) #CA
        beta1 = from_posterior("beta1", trace.posterior.beta1.mean(axis=0)) #CA
        # Expected value of outcome
        mu = alpha + beta0 * X1 + beta1 * X2
        # Likelihood (sampling distribution) of observations
        Y_obs = Normal("Y_obs", mu=mu, sigma=1, observed=Y)
        # draw 10000 posterior samples
        trace = sample(1000)
        traces.append(trace)

But, I got the following error on trace = sample(1000):

SamplingError: Initial evaluation of model at starting point failed!
Starting values:
{'alpha_interval__': array(nan), 'beta0_interval__': array(nan), 'beta1_interval__': array(nan)}

Initial evaluation results:
{'alpha': nan, 'beta0': nan, 'beta1': nan, 'Y_obs': nan}

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 with the updating_priors notebook linked in the issue and run the code around the repeated sampling loop. Inspect the posterior trace values and dimensions used by from_posterior, then verify that the example reaches sampling without NaN initial values and that the notebook produces valid updated traces.

Written by the indexing model from the issue text.

Assessment

Tech stack
jupyter-notebook, python
Domain
machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.