Fix/Freeze Parameter

This question was originally asked by @kpei on Github, but it looks like it never made it to this forum.

I have a similar situation where I’d like to fix a parameter so that the parameter’s values don’t change during fitting, yet I’m unsure how I can do that without making it an observed stochastic random variable. I looked into pm.Bound, but that’s a bit different than what I’m trying to do.

From my understanding, you can only do this by setting them as observed. You can either build a model factory function that allows you to flexibly create models with or without giving the variables as observed, or you have to write the models down separately

1 Like

Ok thank you @lucianopaz, that’s what I figured after reading through the docs.

I believe this can be accomplished by using DiscreteUniform and setting the lower and upper bound to the same value. I’m using the DEMetropolisZ sampler and it works just fine when combined, e.g., with parameters on Normal or Uniform distributions.

with pm.Model() as model:
    param0 = pm.TruncatedNormal('param0', 0, [-1, 1])
    fixed = pm.DiscreteUniform('fixed', lower = 3.14, upper = 3.14)