MCMC Sampler base classes¶
-
class
pints.
MCMCSampler
[source]¶ Abstract base class for (single or multi-chain) MCMC methods.
All MCMC samplers implement the
pints.Loggable
andpints.TunableMethod
interfaces.-
in_initial_phase
()[source]¶ For methods that need an initial phase (see
needs_initial_phase()
), this method returnsTrue
if the method is currently configured to be in its initial phase. For other methods aNotImplementedError
is returned.
-
n_hyper_parameters
()¶ Returns the number of hyper-parameters for this method (see
TunableMethod
).
-
needs_initial_phase
()[source]¶ Returns
True
if this method needs an initial phase, for example an adaptation-free period for adaptive covariance methods, or a warm-up phase for DREAM.
-
needs_sensitivities
()[source]¶ Returns
True
if this methods needs sensitivities to be passed in totell
along with the evaluated logpdf.
-
set_hyper_parameters
(x)¶ Sets the hyper-parameters for the method with the given vector of values (see
TunableMethod
).Parameters: x – An array of length n_hyper_parameters
used to set the hyper-parameters.
-
set_initial_phase
(in_initial_phase)[source]¶ For methods that need an initial phase (see
needs_initial_phase()
), this method toggles the initial phase algorithm. For other methods aNotImplementedError
is returned.
-
-
class
pints.
SingleChainMCMC
(x0, sigma0=None)[source]¶ Abstract base class for MCMC methods that generate a single markov chain, via an ask-and-tell interface.
Extends
MCMCSampler
.Parameters: - x0 – An starting point in the parameter space.
- sigma0 – An optional (initial) covariance matrix, i.e., a guess of the
covariance of the distribution to estimate, around
x0
.
-
in_initial_phase
()¶ For methods that need an initial phase (see
needs_initial_phase()
), this method returnsTrue
if the method is currently configured to be in its initial phase. For other methods aNotImplementedError
is returned.
-
n_hyper_parameters
()¶ Returns the number of hyper-parameters for this method (see
TunableMethod
).
-
name
()¶ Returns this method’s full name.
-
needs_initial_phase
()¶ Returns
True
if this method needs an initial phase, for example an adaptation-free period for adaptive covariance methods, or a warm-up phase for DREAM.
-
needs_sensitivities
()¶ Returns
True
if this methods needs sensitivities to be passed in totell
along with the evaluated logpdf.
-
replace
(current, current_log_pdf, proposed=None)[source]¶ Replaces the internal current position, current LogPDF, and proposed point (if any) by the user-specified values.
This method can only be used once the initial position and LogPDF have been set (so after at least 1 round of ask-and-tell).
This is an optional method, and some samplers may not support it.
-
set_hyper_parameters
(x)¶ Sets the hyper-parameters for the method with the given vector of values (see
TunableMethod
).Parameters: x – An array of length n_hyper_parameters
used to set the hyper-parameters.
-
set_initial_phase
(in_initial_phase)¶ For methods that need an initial phase (see
needs_initial_phase()
), this method toggles the initial phase algorithm. For other methods aNotImplementedError
is returned.
-
tell
(fx)[source]¶ Performs an iteration of the MCMC algorithm, using the
pints.LogPDF
evaluationfx
of the pointx
specified byask
.For methods that require sensitivities (see
MCMCSamper.needs_sensitivities()
),fx
should be a tuple(log_pdf, sensitivities)
, containing the values returned bypints.LogPdf.evaluateS1()
.After a successful call,
tell()
returns a tuple(x, fx, accepted)
, wherex
contains the current position of the chain,fx
contains the corresponding evaluation, andaccepted
is a boolean indicating whether the last evaluated sample was added to the chain.Some methods may require multiple ask-tell calls per iteration. These methods can return
None
to indicate an iteration is still in progress.
-
class
pints.
MultiChainMCMC
(chains, x0, sigma0=None)[source]¶ Abstract base class for MCMC methods that generate multiple markov chains, via an ask-and-tell interface.
Extends
MCMCSampler
.Parameters: - chains (int) – The number of MCMC chains to generate.
- x0 – A sequence of starting points. Can be a list of lists, a 2-dimensional
array, or any other structure such that
x0[i]
is the starting point for chaini
. - sigma0 – An optional initial covariance matrix, i.e., a guess of the covariance
in
logpdf
around the points inx0
(the samesigma0
is used for each point inx0
). Can be specified as a(d, d)
matrix (whered
is the dimension of the parameterspace) or as a(d, )
vector, in which casediag(sigma0)
will be used.
-
current_log_pdfs
()[source]¶ Returns the log pdf values of the current points (i.e. of the most recent points returned by
tell()
).
-
in_initial_phase
()¶ For methods that need an initial phase (see
needs_initial_phase()
), this method returnsTrue
if the method is currently configured to be in its initial phase. For other methods aNotImplementedError
is returned.
-
n_hyper_parameters
()¶ Returns the number of hyper-parameters for this method (see
TunableMethod
).
-
name
()¶ Returns this method’s full name.
-
needs_initial_phase
()¶ Returns
True
if this method needs an initial phase, for example an adaptation-free period for adaptive covariance methods, or a warm-up phase for DREAM.
-
needs_sensitivities
()¶ Returns
True
if this methods needs sensitivities to be passed in totell
along with the evaluated logpdf.
-
set_hyper_parameters
(x)¶ Sets the hyper-parameters for the method with the given vector of values (see
TunableMethod
).Parameters: x – An array of length n_hyper_parameters
used to set the hyper-parameters.
-
set_initial_phase
(in_initial_phase)¶ For methods that need an initial phase (see
needs_initial_phase()
), this method toggles the initial phase algorithm. For other methods aNotImplementedError
is returned.
-
tell
(fxs)[source]¶ Performs an iteration of the MCMC algorithm, using the
pints.LogPDF
evaluationsfxs
of the pointsxs
specified byask
.For methods that require sensitivities (see
MCMCSamper.needs_sensitivities()
), each entry infxs
should be a tuple(log_pdf, sensitivities)
, containing the values returned bypints.LogPdf.evaluateS1()
.After a successful call,
tell()
returns a tuple(xs, fxs, accepted)
, wherex
contains the current position of the chain,fx
contains the corresponding evaluation, andaccepted
is an array of booleans indicating whether the last evaluated sample was added to the chain.Some methods may require multiple ask-tell calls per iteration. These methods can return
None
to indicate an iteration is still in progress.