How to constrain deterministic sites like we do in RStan

Hi devs.

I’m trying to convert this RStan model into numpyro,

data {
  int<lower=0> N1;  // number of observations (group 1)
  int<lower=0> N2;  // number of observations (group 2)
  vector[N1] y1;  // response time (group 1);
  vector[N2] y2;  // response time (group 2);
}
parameters {
  real<lower=0> mu_1;  // mean of group 1
  real beta;  // difference in means
  real<lower=0> sigma;  // pooled standard deviation
}
transformed parameters {
  real<lower=0> mu_2 = mu_1 + beta; 
}
model {
  y1 ~ normal(mu_1, sigma);
  y2 ~ normal(mu_2, sigma);
  // prior
  mu_1 ~ normal(0.5, 2.5);
  beta ~ normal(0, 2.5);
  sigma ~ student_t(4, 0, 1);
}
generated quantities {
  real y1rep[N1];
  real y2rep[N2];
  for (i in 1:N1) {
    y1rep[i] = normal_rng(mu_1, sigma);
  }
  for (i in 1:N2) {
    y2rep[i] = normal_rng(mu_2, sigma);
  }
}

Here, as you can see we can constrain the transformed parameter mu_2 to be >0, by using real<lower=0> mu_2 = mu_1 + beta;.

In numpyro, this would be

mu_2 = numpyro.deterministic("mu_2", mu_1 + beta)

but this does not ensure that the posterior samples of mu_2 will be >0.

Could you please help me if this behaviour is achievable in numpyro? Thanks!

Do you know how Stan enforces that constraint?