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

add acceptance rate info to Transition struct #88

Merged
merged 6 commits into from
Feb 16, 2024

Conversation

cnrrobertson
Copy link
Contributor

Solves (at least partially) #40.

@yebai yebai requested a review from cpfiffer September 13, 2023 21:15
src/AdvancedMH.jl Outdated Show resolved Hide resolved
Copy link
Member

@devmotion devmotion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this break Turing? IIRC at some point (and maybe still?) we constructed Transition objects there.

src/AdvancedMH.jl Outdated Show resolved Hide resolved
src/AdvancedMH.jl Outdated Show resolved Hide resolved
docs/src/api.md Outdated Show resolved Hide resolved
src/AdvancedMH.jl Outdated Show resolved Hide resolved
src/MALA.jl Outdated Show resolved Hide resolved
src/MALA.jl Outdated Show resolved Hide resolved
@cnrrobertson
Copy link
Contributor Author

This latest iteration pushes accepted_draws and total_draws to the MHSampler type objects rather than keeping them in the Transition. Note that this required adjusting the constructors (particularly the MALA constructor).

@cnrrobertson
Copy link
Contributor Author

Any thoughts on this since the last changes? I need to go through Turing to find the small adjustments that will be needed to work with this but I want to get any feedback on this implementation before I do.

src/MALA.jl Outdated
@@ -1,11 +1,13 @@
struct MALA{D} <: MHSampler
proposal::D

MALA{D}(proposal::D) where {D} = new{D}(proposal)
accepted_draws :: Int
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember the previous discussion but this design seems a bit surprising to me. I think the number of accepted and total draws is not a property of the sampler but rather of the resulting chain.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the thought here was that samplers have a record of success or failure. This would be useful for implementing delayed rejection or other sample massaging. But that information could probably be retrieved from the vector of transitions along the way.

With that in mind, maybe we can stick with Transition objects just storing whether the sample was accepted or rejected and compute final stats in chain construction or in sampling if needed. I know this PR is already a mess, but I'll revert and make the adjustments.

src/MALA.jl Outdated Show resolved Hide resolved
@Red-Portal
Copy link
Member

Is there any plan to push this forward?

@cpfiffer
Copy link
Member

I personally see no issue with this. If tests pass I say we merge it in.

src/mh-core.jl Outdated Show resolved Hide resolved
@cnrrobertson
Copy link
Contributor Author

Great! My local tests are passing. Any idea why the nightly tests are failing in the CI?

@cpfiffer
Copy link
Member

I'm going to merge this in for now. Test failures are all on nightly. As a side note, we should maybe consider not testing on nightly, or at least permitting failure.

@cpfiffer cpfiffer merged commit db083fc into TuringLang:master Feb 16, 2024
11 of 16 checks passed
@cpfiffer
Copy link
Member

Tbh I'm not terribly concerned with nightly at the moment. Thank you @cnrrobertson for the PR! Sorry it took so long to merge. I'll increment the patch number separately and flag a release.

@devmotion
Copy link
Member

My impression the last time I checked the PR was that AbstractMCMC features such as discard = ..., thinning = ... etc. will break this functionality. But maybe it's fine if your acceptance rate is wrong if you don't perform "vanilla" sampling?

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.

5 participants