I thought about the most straight-forward solution to the German tank problem in stan:
data {
int<lower=0> N;
vector[N] y;
}
parameters {
real<lower=0> max_y;
}
model {
for(i in 1:N) {
y[i] ~ uniform(0, max_y);
}
}
I drive it with the following R code:
sample_data<-function(N, max_y) {
runif(N, max=max_y)
}
sampl<-sample_data(40, 1000)
library(rstan)
options(mc.cores = parallel::detectCores())
fit<-rstan::stan(file='~/tmp/tank_problem.stan', data = list(
N=length(sampl), y=sampl
), iter = 10000)
I get thousands of errors like this after the model is compiled:
Rejecting initial value:
Log probability evaluates to log(0), i.e. negative infinity.
Stan can't start sampling from this initial value.
Why does the model fail to sample?
I’ve asked the same problem on https://stats.stackexchange.com/q/415719/10069, but it was put on hold for being off-topic.