Skip to content
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

MHState #82

Closed
wants to merge 10 commits into from
Closed

MHState #82

wants to merge 10 commits into from

Conversation

JaimeRZP
Copy link
Member

@JaimeRZP JaimeRZP commented Jul 5, 2023

Creates

struct MHState{TTrans<:Transition}
    "Random number of the state"
    rng::Random.AbstractRNG
    "Index of current iteration."
    i::Int
    "Current [`Transition`](@ref)."
    transition::TTrans
end

which allows the sampling to restart by savign the iteration and rng of the sampler.

@devmotion
Copy link
Member

I'm pretty sure in its current form the PR won't solve the problem - it seems the RNG object is saved in the transition but all subsequent calls of rand with this RNG object (eg in subsequent sampling steps) will mutate the state of the RNG and hence mutate the RNG saved in the transition.

@devmotion
Copy link
Member

I'm pretty sure there was a discussion about saving RNGs in some repo at some point, and IIRC I was arguing that it's a more general problem that should be addressed in AbstractMCMC. For instance, by outputting/saving the RNG after the final step and inxluding it in the chain (deep copied?) if possible. Deep copying the RNG in every sampling step seems a bit wasteful to me and would slow down sampling, and only saving the initial RNG and the step number would mean you always have to rerun the whole sampling if you want to continue sampling - which means it would be as slow as running a single chain with all samples.

@cpfiffer
Copy link
Member

I agree that this won't solve the problem -- this should be done upstream in AbstractMCMC. It'd be nice to store the seeds in each transition (which should be cheap) rather than deep copying the rng.

@JaimeRZP
Copy link
Member Author

Agreed! Closing the PR.
Thanks for the discussion!

@JaimeRZP JaimeRZP closed this Jul 12, 2023
@yebai
Copy link
Member

yebai commented Jul 14, 2023

Related TuringLang/AdvancedHMC.jl#314

@yebai yebai deleted the MHState branch July 14, 2023 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants