stan-dev / cmdstanpy

CmdStanPy is a lightweight interface to Stan for Python users which provides the necessary objects and functions to compile a Stan program and fit the model to data using CmdStan.
BSD 3-Clause "New" or "Revised" License
153 stars 69 forks source link

Variation Inference output not read properly if eta (stepsize) != 1 #268

Closed ro-joshi closed 4 years ago

ro-joshi commented 4 years ago

Summary:

The output csv from variational inference is not properly read if eta (stepsize) is not equal to 1.

Description:

The line here: https://github.com/stan-dev/cmdstanpy/blob/master/cmdstanpy/utils.py#L564 requires that eta = 1 in order to read the output csv. However, eta can take on different values (e.g. 0.1, etc.), that can be set by the user or adaptively determined by the ADVI algorithm. See https://mc-stan.org/rstan/reference/stanmodel-method-vb.html for comparison.

Current Version:

0.9.5

mitzimorris commented 4 years ago

thanks for reporting - do you have an example CSV file or snippet you could share?

ro-joshi commented 4 years ago

Thanks for taking a look, snippet below. I cut off columns and rows in the brackets <> for clarity

# stan_version_major = 2
# stan_version_minor = 23
# stan_version_patch = 0
# model = factor_model
# method = variational
#   variational
#     algorithm = meanfield (Default)
#       meanfield
#     iter = 10000 (Default)
#     grad_samples = 1 (Default)
#     elbo_samples = 100 (Default)
#     eta = 1 (Default)
#     adapt
#       engaged = 1 (Default)
#       iter = 50 (Default)
#     tol_rel_obj = 0.01 (Default)
#     eval_elbo = 100 (Default)
#     output_samples = 1000 (Default)
# id = 0 (Default)
# data
#   file = /tmp/tmpkx56q518/3b3icq7l.json
# init = 2 (Default)
# random
#   seed = 41822
# output
#   file = /tmp/tmpkx56q518/factor-202008052035-1-y1qwu9eq.csv
#   diagnostic_file =  (Default)
#   refresh = 100 (Default)
# num_threads = 1
lp__,log_p__,log_g__,phi,<...further columns...>
# Stepsize adaptation complete.
# eta = 0.1
0,0,0,2.84783,1.50599,1.0663,<...further columns...>
0,-1.45135e+06,-6556.27,2.62732,<...further columns...>
<...further rows...>
mitzimorris commented 4 years ago

fixed by https://github.com/stan-dev/cmdstanpy/pull/283, closing