Constraints on sampled parameters

I have a model written in Stan that I am trying to test with pyro. Unfortunately it tends to run into some problems with HMC - namely some initial proposal values tend to explode and producing invalid values (overflow).

The model is for an eQTL effect size, described here in detail, but the main problem part is this:

beta ~ normal(0, 1); // actually, it's a normal mixture prior, but for simplicity
if (indicator[i] == 0) {
  mu[i] = 0;
} else if (indicator[i] == 1) {
  mu[i] = log1p(exp(beta)) - log(2);
} else if (indicator[i] == 2) {
  mu[i] = beta;

Now in Stan I can constrain beta to be in the range [-10, 10], which easily covers the plausible range of effect sizes and prevents any overflow/underflow. However, sample statements in Pyro don’t allow these , so beta will get one proposal that’s a large value (eg, 139533), and then fail with OverflowError.

Is there a way to enforce a constraint here?

1 Like


Ah, numpyro. My having missed this in the documentation suddenly makes much more sense.

sorry i was assuming you were using numpyro, which has better/faster support for hmc than pyro.

Well, it wasn’t clear to me why one would prefer numpyro, and when I try to port code I’ve run into fairly inscrutable errors.