stan-dev / cmdstan

CmdStan, the command line interface to Stan
https://mc-stan.org/users/interfaces/cmdstan
BSD 3-Clause "New" or "Revised" License
212 stars 93 forks source link

report initialization as first draw #547

Open bob-carpenter opened 7 years ago

bob-carpenter commented 7 years ago

Summary:

The first draw in the output summary if warmup is saved should be the initialization.

Description:

It currently doesn't.

Reproducible Steps:

Program:

parameters {
  real y;
}
model {
  y ~ normal(0, 1);
}

Current Output:

Output of

./norm sample save_warmup=1 init=0

is

# stan_version_major = 2
# stan_version_minor = 15
# stan_version_patch = 0
# model = norm_model
# method = sample (Default)
#   sample
#     num_samples = 1000 (Default)
#     num_warmup = 1000 (Default)
#     save_warmup = 1
#     thin = 1 (Default)
#     adapt
#       engaged = 1 (Default)
#       gamma = 0.050000000000000003 (Default)
#       delta = 0.80000000000000004 (Default)
#       kappa = 0.75 (Default)
#       t0 = 10 (Default)
#       init_buffer = 75 (Default)
#       term_buffer = 50 (Default)
#       window = 25 (Default)
#     algorithm = hmc (Default)
#       hmc
#         engine = nuts (Default)
#           nuts
#             max_depth = 10 (Default)
#         metric = diag_e (Default)
#         stepsize = 1 (Default)
#         stepsize_jitter = 0 (Default)
# id = 0 (Default)
# data
#   file =  (Default)
# init = 0
# random
#   seed = 3169738892
# output
#   file = output.csv (Default)
#   diagnostic_file =  (Default)
#   refresh = 100 (Default)
lp__,accept_stat__,stepsize__,treedepth__,n_leapfrog__,divergent__,energy__,y
-0.552707,0.57539,2,1,1,0,0.690883,-1.05139

Expected Output:

First value of y should be 0.

Additional Information:

Provide any additional information here.

Current Version:

v2.15.0

syclik commented 7 years ago

Thanks for tagging this as v3.0.0. I don't think we can change existing behavior because it'll be a off-by-one nightmare everywhere, but if we do split to multiple files, this will be easy.

I just tagged @betanalpha just to see if he has any thoughts.

goedman commented 7 years ago

Thanks Bob and Daniel. I'll create a similar test case for Stan.jl to track this issue and the other outstanding 3.0.0 issue (save-warmups and thinning, #510 ).

Adding this initial value to the saved warmups samples I guess is just for educational purposes, as Chris was using it?

mitzimorris commented 1 year ago

there's an unused argument to all service call methods: init_writer which seems to be intended to capture the initial parameters on the unconstrained scale.

used by CmdStan here: https://github.com/stan-dev/cmdstan/blob/a22802cc10fce329036b164ee9c6bd4cbaa7aebc/src/cmdstan/command.hpp#L189

ignored by services methods here: https://github.com/stan-dev/stan/blob/6d35a762bf56c72fef574302e5af4b9c70703625/src/stan/services/util/initialize.hpp#L209 (but this is after the unconstraining xform - we'd want to output the first draw on the constrained scale).

at this point, we've got enough hooks on the model class that we could hook this up to its own file and output this info.

jucor commented 11 months ago

This would very much help diagnostics, thank you! (See https://discourse.mc-stan.org/t/does-the-init-argument-work-with-cmdstanr/17255/11 for example, or the hour I just spent trying to understand why I didn't find my init values in the warmup 😅)