@jsocolar pointed out that if you initialize an offset-multiplier style non-centered parameters to a really small value you get problems sampling. @jsocolar’s example showed the same problems for me, but when I tried to duplicate it with a manual offset-multiplier implementation, I did not get the problem.
It seems like something not-so-good is going on here.
Here is the offset-multiplier model
parameters{
real<lower = 0> sigma;
real<multiplier=sigma> x;
}
model{
sigma ~ std_normal();
x ~ normal(0, sigma);
}
Here is the manual offset-multiplier model:
parameters{
real<lower = 0> sigma;
real x_raw;
}
transformed parameters {
real x = x_raw * sigma;
}
model{
sigma ~ std_normal();
x ~ normal(0, sigma);
target += log(sigma);
}
Code to run them is
library(tidyverse)
library(cmdstanr)
mod1 = cmdstan_model("mod1.stan")
inits_chain_1 = list(sigma = 1e-20)
fit1 = mod1$sample(chains = 1, init = list(inits_chain_1), iter_sampling = 1000)
fit1$summary()
mod2 = cmdstan_model("mod2.stan")
fit2 = mod2$sample(chains = 1, init = list(inits_chain_1), iter_sampling = 1000)
fit2$summary()
You get output like this for the build-in offset-multiplier:
> fit1$summary()
# A tibble: 3 x 10
variable mean median sd mad q5 q95 rhat ess_bulk
<chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 lp__ -9.01e+38 -9.01e+38 0 0 -9.01e+38 -9.01e+38 NA NA
2 sigma 3.12e-20 3.12e-20 0 0 3.12e-20 3.12e-20 NA NA
3 x -1.33e+ 0 -1.33e+ 0 0 0 -1.33e+ 0 -1.33e+ 0 NA NA
# … with 1 more variable: ess_tail <dbl>
And the output with a custom offset-multiplier looks like:
> fit2$summary()
# A tibble: 4 x 10
variable mean median sd mad q5 q95 rhat ess_bulk ess_tail
<chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 lp__ -1.57 -1.24 0.987 0.761 -3.64 -0.563 1.00 292. 430.
2 sigma 0.821 0.703 0.594 0.591 0.0667 2.02 1.00 437. 366.
3 x_raw 0.0115 0.0396 0.983 1.01 -1.64 1.59 1.00 523. 660.
4 x 0.00698 0.0104 0.967 0.547 -1.66 1.51 1.00 492. 503.
This is pretty repeatable that the custom code doesn’t have a problem with inits but the built in does.
I’m not quite sure where the problem is or what the difference is – posting here if someone knows. @jsocolar said this was happening in a realistic setting (and so figuring out it was a problem probably wasn’t fun or easy and so it’d be nice to fix this if it is fixable or at least know what is the difference)