Metropolis extension #42
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Generalize
metropolis_sample
by introducingmetropolis_sample(update!::Function, -||-)
Now, we can customize how a "metropolis step" looks, typically with the do-syntax (thanks @AntonOresten for the tip). Omitting
update!
is equivalent with the previous behaviour. This enables us to, for instance, fix branch lengths and only sample over topologies withnni_update!
. We can also add parameters to the chain as exemplified below.Example usage
From Phylotrajectories.jl:
this extension called for introducing the
metropolis_step
interfaceDoes a standard metropolis step in an MCMC, i.e. proposes a candidate symmetrically and returns the next
state in the chain, decided by the candidate being rejected or not.
The interface for
metropolis_step
is as followsYou need a
MySampler <: Any
to implementproposal(modifier::MySampler, curr_value)
log_prior(modifier::MySampler, x)
apply_decision(modifier::MySampler, accept::Bool)
An example is given for
BranchlengthSampler
Add
branchlength_update!
&nni_update!
Update can be either an optim or a sampling, determined by the first argument passed in. We still export
branchlength_optim!
andnni_optim!
and they behave identically as before. This separation is made to avoid confusion when we want*_optim!
to sample.