-
Notifications
You must be signed in to change notification settings - Fork 12
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
add no_warnings / quiet option to StanModel$new() #217
Comments
Thanks, @avehtari, for bringing this up.
In my opinion, it's better to handle this at the BridgeStan level since similar use cases might come up in other languages, too. @WardBrian It looks like we could just add a quiet (or whatever) keyword argument to line #33 of More broadly, Aki, you are just looking for automatic differentiation of a statistical model as data changes, right? I was bringing this up at StanCon last year. I'd really like, but don't fully understand the implications, of making data non- |
[edit: Aki didn't say he was making it non-const, just that he was instantiating a bunch of instances of the same Stan class with different data.] As is, Stan model objects are immutable after construction. This automatically guarantees thread safety. As soon as you start allowing a model class to be modified, it's going to have to be synchronized. A motivation would be to do something like stochastic gradient descent. If you could change the data each iteration, you could implement that. This has come up multiple times before, usually around things like wanting access to iteration number, or other things that would store state on the model. I've generally been resistant to that. |
We could definitely do this for each interface, yes. The hardest part is deciding on a name for said argument I think. |
There are many use cases. So far I've used it 1) getting group specific conditional log density in hierarchical models (conditional on hyperparameters, changing data for each group), 2) and doing post-hoc missing data inference (conditional on original model parameters without missing data, changing data is the new observed target y, and get the log density for missing x). It would also be useful 3) in various cross-validation, bootstrap, and covariate importance methods. In 2) I did use a second model where missing x is declared as parameter, but even then ended up not using gradients as slice sampling for 1D is so fast. A Stan discourse thread has code for using adaptive Gauss-Hermite quadrature or slice sampling https://discourse.mc-stan.org/t/post-hoc-prediction-use-samples-from-fitted-model-in-a-prediction-task/34319/13. In the latter code, I did end up passing previous posterior draws as parameters and not data, as the instantiation overhead was dominating the computation time, but I was still passing y as data. |
Relevant discussion about this: |
I propose, from my most to least preferred,
for a signature like I'm also open to other suggestions. |
I do wonder if one day the constructor could have other warnings, and we’d want to be able to silence just some of them, in which case this should be called something like silence_reload_warning |
That's a good thought. In that case though, I'd still think there should be one argument to prevent all warnings, instead of forcing users to type out each individually. |
Sure, so I guess we can go with a general name for now and add a more specific one if the need ever does arise. I can knock this out tomorrow I think |
And if you can't, just ping me and I'll cover it next week. Spring break next week, so I should have enough time. |
There are many use cases where there is a need to call
StanModel$new()
thousands of time with different data. After the second call there is always a warning messagePlease add an option to turn this off. I could use R
suppressWarnings()
, but then I can miss other warnings. For example, if I haveI may miss useful warnings from
to_stan_json()
function, and I would not like to create another variable to store the json before callingStanModelnew()
The text was updated successfully, but these errors were encountered: