Prevent prior from updating?

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.

3 Likes