-
-
Notifications
You must be signed in to change notification settings - Fork 371
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
RNG in transformed data should use seed #2241
Comments
this is a problem for all of the interfaces. the generated model contains both 2- and 3-arg constructors, e.g., using the above stand code in file "m2241.stan", the file "m2241.hpp",
in cmdstan, in file if a random seed is specified, this should be changed to:
|
made above change cmdstan.
running model with seeds |
closing this as stan issue - will add issue for interfaces. |
Could we change the stan::services functions so that the interfaces don't have to keep track of random seeds in two places? It's actually rather nice (and in keeping with the spirit of the refactor) to use the 2-arg constructor. The interfaces shouldn't have to worry about what RNG is being used (beyond the chain id and the integer random seed), right? |
would it make sense to make the arg to the 3-arg constructor be the integer random seed instead of a boost rng object? |
Now that I look at the code (stan::services::sample code), I worry there might be another concern. Does the random sampling need to vary across chains?
What's the expected behavior here given a fixed seed and multiple chains? |
@mitzimorris , having the third argument be the random seed sounds like a good idea to me. I had originally hoped one could construct the stan_model instance inside the stan::services function call. I imagined changing this
into something approximately like this:
but I have a suspicion that this might exceed the limits of what is allowed with templates. Your solution solves the problem just as well though. It does require the interfaces to remember to pass the random seed in two places -- but that's better than having to worry about the base_rng class AND the random seed in two places. |
we're talking about transformed data block - what do you mean by "sampling"? this is executed once, as part of model's constructor. if the transformed data should be randomized differently across chains, then the interface will need to instantiate the model on a per-chain basis, passing in both the seed and chain.
ran this by @bob-carpenter who says it's a bad idea - suggestion withdrawn. |
I believe we had decided that the randomization should vary across chains; we could change our minds here. In some ways, it makes sense not to vary transformed data RNGs by chain ID---no idea how we'd diagnose convergence otherwise. In other ways, the point of it being random is that you want it to vary. Either way, we want to reuse the RNG for transformed data and then for sampling. What Allen suggests will work. You can indeed do this:
The way templates work is that you get real types substituted for all template parameters before compliation, so that will look just like any other type constructor call. Either way, this preserves the encapsulation of the model not knowing about chain IDs. |
I thought the idea was that we promise deterministic behavior if you set chain ID and we don't promise anything else. If somebody wants to do a simulation study with repeat data used in multiple places they can just pass it in as data. |
The issue is convergence monitoring. I'm just trying to think like Andrew here. If we have different random transformed data across seeds, then we can't monitor convergence with R-hat and our n_eff will be weird. So I think we should actually have the same RNG for the transformed data, independent of seed.
I don't think we're promising anything particularly clearly. Maybe we should.
|
I like your rationale Bob.
…On Tue, May 16, 2017, 12:39 PM Bob Carpenter ***@***.***> wrote:
The issue is convergence monitoring. I'm just trying to think like Andrew
here. If we have different random transformed data across seeds, then we
can't monitor convergence with R-hat and our n_eff will be weird. So I
think we should actually have the same RNG for the transformed data,
independent of seed.
I don't think we're promising anything particularly clearly. Maybe we
should.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#2241 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAfA6TqFo-MMaWXtcBjVip_rI9SY-5bvks5r6dFIgaJpZM4MU5zw>
.
|
I meant independent of chain ID, not independent of seed! So hard to talk about all this precisely with the chain ID acting as a kind of sub-seed (it's used to step the RNG over a bunch of draws).
|
in which case, why not pass in seed instead of RNG to model constructor? |
There are two use cases here. First, having constant transformed data
to ensure that we can use convergence monitoring over parallel
chains. Second, facilitating the sample different data sets and fit
to determine ensemble behavior. Both are valid but being able to
do both would require keeping track of multiple seeds and being
clever about default behavior.
I suggest that we use a common seed right now and at least get
reproducible behavior and then worry about generalizing to include
both behaviors later.
A long answer that reduces to: “what Bob said”.
… On May 16, 2017, at 12:39 PM, Bob Carpenter ***@***.***> wrote:
The issue is convergence monitoring. I'm just trying to think like Andrew here. If we have different random transformed data across seeds, then we can't monitor convergence with R-hat and our n_eff will be weird. So I think we should actually have the same RNG for the transformed data, independent of seed.
I don't think we're promising anything particularly clearly. Maybe we should.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub <#2241 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/ABdNlj66840ru-5usIwOQEGG7M2tsp3Mks5r6dFJgaJpZM4MU5zw>.
|
@mitzimorris Yes, we just need the ID. We can advance all the other RNGs at least one notch (a gazillion draws) so they won't overlap. |
fixed in #2313 |
Summary:
The RNG in the transformed data block is insensitive to seed. It should use the overall seed, but not the chain ID.
Thanks to Jim Savage for reporting.
Reproducible Steps:
Current Output:
In RStan, the following two calls produce exactly the same fit:
as does any seed that's included.
Expected Output:
Different results based on seed.
Additional Information:
The RNG is probably being used before the seed is set in the command interface. We should check how this works post-refactor as I'm testing it in the pre-refactor current-release version.
Current Version:
v2.14.0
The text was updated successfully, but these errors were encountered: