Prevent prior from updating?

Hi all,

I am currently setting up a model in which I intend to use a normally distributed parameter which interacts with other parameters to come to certain observed results.

However, for this known normally distributed parameter, I would like to be able to set a prior that does not update during sampling, but just samples from the initially set distribution for this prior. I don’t have observed samples from this prior but could easily generate some, but then I run into shape mismatch errors. Is there no simple option where you could just set observed=True or sth similar which shows pymc3 that this should be an observed variable rather than a FreeRV?

So you want a stochastic node in your model? Check out http://deeplearning.net/software/theano/library/tensor/shared_randomstreams.html

Hi @junpenglao ,

Thank you for your response.
I would like to set a parameter used in my model to a certain normal distribution with known mu and sigma, which should not change due to the observed data outcome. Now this tends to happen if I naively set this prior within the pymc3 model I set up.

Are there any examples where someone uses theano shared random streams to do this within a pymc3 model?

Thanks!

A simple example goes like this:

import numpy as np
import pymc3 as pm
import theano.tensor as tt

true_mu, true_sigma = 5., 2.
y_obs = np.random.randn(50) * true_sigma + true_mu

with pm.Model() as m:
    mu = pm.Normal('mu', 0., 100.)
    sigma = pm.HalfCauchy('sigma', 5.)
    y = pm.Normal('y', mu, sigma, observed=y_obs)
    trace = pm.sample()

pm.summary(trace)

srng = tt.shared_randomstreams.RandomStreams(seed=234)

with pm.Model() as m:
    mu = pm.Deterministic('mu', srng.normal(avg=4.9, std=.1))
    sigma = pm.HalfCauchy('sigma', 5.)
    y = pm.Normal('y', mu, sigma, observed=y_obs)
    trace = pm.sample()

pm.summary(trace)

In the second model, there is only 1 free parameter sigma, and mu always follows the same distribution.

2 Likes