How to put prior knowledge in to student-t model

the model is like this:

with pm.Model() as model_t:
mu = pm.Uniform(‘mu’, 0, 1)
sigma = pm.HalfNormal(‘sigma’, sd = 10)
nu = pm.Exponential(‘nu’, 1/30)
y = pm.StudentT(‘y’, mu=mu, sd=sigma, nu=nu, observed=data)
trace_t = pm.sample(1100)
chain_t = trace_t[100:]

Now I know the prior mu-3*sigma should less than 0.001, how should I put this knowledge in to this model?


You could use a Potential to set the likelihood to -inf whenever the constraint is not satisfied.

1 Like

Hi sammosummo:
I’m sorry I didn’t get your word, could you be more specific? thanks

If you want a hard constraint then you can use Potential like @sammosummo suggested

example code:

with pm.Model() as model_t:
    mu = pm.Uniform('mu', 0, 1)
    sigma = pm.HalfNormal('sigma', sd = 10)
    nu = pm.Exponential('nu', 1/30)
    y = pm.StudentT('y', mu=mu, sd=sigma, nu=nu, observed=data)
    constraint = pm.Potential('constraint', tt.switch(mu - 3*sigma > 0.001, -np.inf, 0))
    trace_t = pm.sample(1000)

In general such hard constraints are not recommended as they have no derivative and jump either side of the boundary.

You don’t need to drop the first 100 samples from trace_t. pm.sample() will already run 1000 burnin steps followed by 1000 samples. What is returned is just the 1000 samples.