-
-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
generate_quantities
handles save_warmup=True
"wrong".
#1011
Comments
Also, here is an MWE: Stan parameters {
real x;
}
model {
x ~ normal(0,1);
}
generated quantities{
real y = x;
} Python import cmdstanpy
model = cmdstanpy.CmdStanModel(stan_file='gq.stan')
fit = model.sample(save_warmup=True, iter_sampling=1, chains=1)
gq = model.generate_quantities(dict(), fit)
print(gq.sample_plus_quantities[['x', 'y']]) Output
|
is this a problem with CmdStanPy or CmdStan? |
Hm, whether it's a problem with CmdStanPy or CmdStan is a matter of perspective or of what's expected. CmdStan just takes the first CmdStanPy joins the first There are three options to fix this:
Finally, and I think this should be the preferred way to fix this:
I believe there are also issues if Edit: Or actually, provide parameters to CmdStan(Py) whether or not to generate gqs for the warmup draws. |
not quite. my bad - read CmdStan code more carefully - CmdStan only uses the post-warmup draws. cmdstan/src/cmdstan/command.hpp Lines 269 to 290 in c83ae03
I'll check on what CmdStanPy is doing - it sounds like that's where add'l config is needed. |
No, I checked. It uses the first |
if you look at the code - line 285 is going to advance the stream reader to the adaptation message - past warmup samples. then line 289 reads the post-warmup draws. |
Slightly extended MWE from above, same Stan file import cmdstanpy
model = cmdstanpy.CmdStanModel(stan_file='gq.stan')
fit = model.sample(save_warmup=True, iter_sampling=1, chains=1)
print(fit.draws_pd(inc_warmup=True)['x'])
gq = model.generate_quantities(dict(), fit)
print(gq.sample_plus_quantities[['x', 'y']]) Output:
Maybe some version is out of date, let me check. Edit: Wait, how do I check and what do I have to check? CmdStan's version I guess? |
Ah. I had a mini heart attack. I changed the cmdstanpath to use the version that I downloaded from github, and suddenly it worked. So I thought I was wrong and wasted your time, but actually I already fixed the bug in my CmdStan code. This is the header of my csv file, does this confirm that everything is up to date?
Can you run the MWE and confirm that x!=y? |
this is fubar and you are right. eating words. in CmdStan 2.26.1:
model b2.stan:
and run this with file
simple sanity check:
so far so good, but - first draw of
first draw of
looks like the Stan csv reader isn't doing what it should be doing. will investigate. |
Okay, good, my worst fears are vanquished. I did think that the reader was supposed to read all of the samples, but I only looked so far into it. (I think there might be an additional issue in handling the thinning parameter, but I haven't tried yet) |
many thanks. probably never properly unit tested. will fix. (but have to write grant proposal first) - you're welcome to try - the question is - why doesn't |
answer to above question: therefore, two options: a) use all draws a) is a whole lot easier. given that by default, warmup draws are not saved, if warmup draws are present, then that's a deliberate choice, and standalone GQ should use all draws. also, this would avoid problems with thinning as well. |
Yes, that sounds reasonable. BTW, I have only looked at the adaptation-reading code shortly, but it looks like it stops reading as soon it encounters a non-comment line. Ie reading of the adaptation does not seem to work when warmup draws have been saved. But I have made no tests and my understanding is very shallow. |
right, and that's what gave me the impression that the
it's not your understanding that's shallow - it's the code. no comments. haven't checked out the unit tests - probably not enough of them, either. |
going with option a) then, draws in the (off topic, but noted here: if CmdStanPy wants to get fancier, it could - I suggest we don't and push back on Python users to do their own data munging) |
Yes, I would not want to deal with data wrangling in C... |
Summary:
If
save_warmup=True
,generate_quantities
takes the firstnum_samples
warmup and samples to generate the gqs.https://github.com/stan-dev/cmdstan/blob/develop/src/cmdstan/command.hpp
Has to be changed into something that handles this differently, also incorporating the thinning parameter.
Current Version:
v2.26.1
The text was updated successfully, but these errors were encountered: