I have a super simple model. How do I generate more draws in my new generated quantities. The results are shown at the bottom of this post. It seems like the draws are set at 1000 by default. How can I increase or decrease this number?
stan.py
import cmdstanpy
import os
from cmdstanpy import CmdStanModel
import numpy as np
# naive model
naive_stan = os.path.join("naive_stan", "naive.stan")
out_dir = os.path.join("mean_stan", "out")
mean_model = CmdStanModel(stan_file=naive_stan)
d = np.random.normal(20, 1, size=100)
horizon = 3
cmdstanpy_data = {"horizon": horizon, "T": len(d), "y": d}
mean_fit = mean_model.sample(data=cmdstanpy_data, output_dir=out_dir, chains=1)
new_quantities = mean_model.generate_quantities(
data=cmdstanpy_data, mcmc_sample=mean_fit
)
new_quantities.draws_pd()
naive.stan
data {
int<lower=0> T;
int<lower=0> horizon;
vector[T] y;
}
parameters {
real<lower=0> sigma;
}
model {
y ~ normal(mean(y), sigma);
}
generated quantities {
vector[horizon] forecast;
forecast[1] = student_t_rng(T - 1, y[T], sigma * sqrt(1));
for (h in 2:horizon){
forecast[h] = student_t_rng(T - 1, forecast[h-1], sigma * sqrt(h));
}
}
INFO:cmdstanpy:found newer exe file, not recompiling
INFO:cmdstanpy:compiled model file: /home/user/code/stan/tablespoon/naive_stan/naive
INFO:cmdstanpy:start chain 1
INFO:cmdstanpy:finish chain 1
INFO:cmdstanpy:start chain 1
INFO:cmdstanpy:finish chain 1
forecast[1] forecast[2] forecast[3]
0 21.8522 21.4912 20.8139
1 21.5628 22.9161 22.8557
2 20.1681 19.5121 17.5447
3 20.5012 20.3289 17.0195
4 19.3182 18.3402 17.0739
.. ... ... ...
995 21.0422 19.3333 19.0645
996 19.5252 19.5113 17.7110
997 21.4017 21.5539 22.1827
998 19.9526 20.4000 20.5038
999 21.0860 20.8643 25.2736