View source: R/pmcmc_control.R
pmcmc_control | R Documentation |
Control for the pmcmc. This function constructs a list of options
and does some basic validation to ensure that the options will
work well together. Do not manually change the values in this
object. Do not refer to any argument except n_steps
by position
as the order of the arguments may change in future.
pmcmc_control(
n_steps,
n_chains = 1L,
n_threads_total = NULL,
n_workers = 1L,
rerun_every = Inf,
rerun_random = FALSE,
use_parallel_seed = FALSE,
save_state = TRUE,
save_restart = NULL,
save_trajectories = FALSE,
progress = FALSE,
nested_step_ratio = 1,
nested_update_both = FALSE,
filter_early_exit = FALSE,
restart_match = FALSE,
n_burnin = NULL,
n_steps_retain = NULL,
adaptive_proposal = NULL,
path = NULL
)
n_steps |
Number of MCMC steps to run. This is the only required argument. |
n_chains |
Optional integer, indicating the number of chains
to run. If more than one then we run a series of chains and
merge them with |
n_threads_total |
The total number of threads (i.e., cores)
the total number of threads/cores to use. If |
n_workers |
Number of "worker" processes to use to run chains
in parallel. This must be at most |
rerun_every |
Optional integer giving the frequency at which
we should rerun the particle filter on the current "accepted"
state. The default for this ( |
rerun_random |
Logical, controlling the behaviour of
rerunning (when |
use_parallel_seed |
Logical, indicating if seeds should be
configured in the same way as when running workers in parallel
(with |
save_state |
Logical, indicating if the state should be saved
at the end of the simulation. If |
save_restart |
An integer vector of time points to save
restart information for; this is in addition to |
save_trajectories |
Logical, indicating if the particle
trajectories should be saved during the simulation. If |
progress |
Logical, indicating if a progress bar should be
displayed, using |
nested_step_ratio |
Either integer or 1/integer, which specifies the
ratio of fixed:varied steps in a nested pMCMC. For example |
nested_update_both |
If |
filter_early_exit |
Logical, indicating if we should allow the particle filter to exit early for points that will not be accepted. Only use this if your log-likelihood never increases between steps. This will the the case where your likelihood calculation is a sum of discrete normalised probability distributions, but may not be for continuous distributions! |
restart_match |
Logical, indicating whether the restart state saved from the particle filter should match the trajectory saved, otherwise the restart state will be randomly drawn from the states of the particle filter after filtering to the restart time point. |
n_burnin |
Optionally, the number of points to discard as burnin. This happens separately to the burnin in pmcmc_thin or pmcmc_sample. See Details. |
n_steps_retain |
Optionally, the number of samples to retain from
the |
adaptive_proposal |
Optionally, control over an adaptive
proposal (adaptive_proposal_control). Alternatively
|
path |
Optional path to save partial pmcmc results in, when
using workers. If not given (or |
pMCMC is slow and you will want to parallelise it if you possibly
can. There are two ways of doing this which are discussed in some
detail in vignette("parallelisation", package = "mcstate")
.
A pmcmc_control
object, which should not be modified
once created.
Generally it may be preferable to thin the chains after generation using pmcmc_thin or pmcmc_sample. However, waiting that long can create memory consumption issues because the size of the trajectories can be very large. To avoid this, you can thin the chains at generation - this will avoid creating large trajectory arrays, but will discard some information irretrivably.
If either of the options n_burnin
or n_steps_retain
are provided,
then we will subsample the chain at generation.
If n_burnin
is provided, then the first n_burnin
(of
n_steps
) samples is discarded. This must be at most n_steps
If n_steps_retain
is provided, then we evenly sample out of
the remaining samples. The algorithm will try and generate a
sensible set here, and will always include the last sample of
n_steps
but may not always include the first post-burnin
sample. An error will be thrown if a suitable sampling is not
possible (e.g., if n_steps_retain
is larger than n_steps - n_burnin
If either of n_burnin
or n_steps_retain
is provided, the
resulting samples object will include the full set of parameters
and probabilities sampled, along with an index showing how they
relate to the filtered samples.
mcstate::pmcmc_control(1000)
# Suppose we have a fairly large node with 16 cores and we want to
# run 8 chains. We can use all cores for a single chain and run
# the chains sequentially like this:
mcstate::pmcmc_control(1000, n_chains = 8, n_threads_total = 16)
# However, on some platforms (e.g., Windows) this may only realise
# a 50% total CPU use, in which case you might benefit from
# splitting these chains over different worker processes (2-4
# workers is likely the largest useful number).
mcstate::pmcmc_control(1000, n_chains = 8, n_threads_total = 16,
n_workers = 4)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.