Skip to content

add acceptance rate info to Transition struct - #88

Merged
just-cameron merged 6 commits into
TuringLang:masterfrom
cnrrobertson:track_acceptance
Feb 16, 2024
Merged

add acceptance rate info to Transition struct#88
just-cameron merged 6 commits into
TuringLang:masterfrom
cnrrobertson:track_acceptance

Conversation

@cnrrobertson

Copy link
Copy Markdown
Contributor

Solves (at least partially) #40.

@yebai
yebai requested a review from just-cameron September 13, 2023 21:15
Comment thread src/AdvancedMH.jl Outdated

@devmotion devmotion left a comment

Copy link
Copy Markdown
Member

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.

Comment thread src/AdvancedMH.jl Outdated
Comment thread src/AdvancedMH.jl Outdated
Comment thread docs/src/api.md Outdated
Comment thread src/AdvancedMH.jl Outdated
Comment thread src/MALA.jl Outdated
Comment thread src/MALA.jl Outdated
@cnrrobertson

Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread src/MALA.jl Outdated
proposal::D

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

Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread src/MALA.jl Outdated
@Red-Portal

Copy link
Copy Markdown
Member

Is there any plan to push this forward?

@just-cameron

Copy link
Copy Markdown
Member

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

Comment thread src/mh-core.jl Outdated
@cnrrobertson

Copy link
Copy Markdown
Contributor Author

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

@just-cameron

Copy link
Copy Markdown
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.

@just-cameron
just-cameron merged commit db083fc into TuringLang:master Feb 16, 2024
@just-cameron

Copy link
Copy Markdown
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
Copy Markdown
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