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 and pints.TunableMethod interfaces.

in_initial_phase()[source]

For methods that need an initial phase (see needs_initial_phase()), this method returns True if the method is currently configured to be in its initial phase. For other methods a NotImplementedError is returned.

n_hyper_parameters()

Returns the number of hyper-parameters for this method (see TunableMethod).

name()[source]

Returns this method’s full name.

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 to tell 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 a NotImplementedError 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.
ask()[source]

Returns a parameter vector to evaluate the LogPDF for.

in_initial_phase()

For methods that need an initial phase (see needs_initial_phase()), this method returns True if the method is currently configured to be in its initial phase. For other methods a NotImplementedError 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 to tell 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 a NotImplementedError is returned.

tell(fx)[source]

Performs an iteration of the MCMC algorithm, using the pints.LogPDF evaluation fx of the point x specified by ask.

For methods that require sensitivities (see MCMCSamper.needs_sensitivities()), fx should be a tuple (log_pdf, sensitivities), containing the values returned by pints.LogPdf.evaluateS1().

After a successful call, tell() returns a tuple (x, fx, accepted), where x contains the current position of the chain, fx contains the corresponding evaluation, and accepted 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 chain i.
  • sigma0 – An optional initial covariance matrix, i.e., a guess of the covariance in logpdf around the points in x0 (the same sigma0 is used for each point in x0). Can be specified as a (d, d) matrix (where d is the dimension of the parameterspace) or as a (d, ) vector, in which case diag(sigma0) will be used.
ask()[source]

Returns a sequence of parameter vectors to evaluate a LogPDF for.

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 returns True if the method is currently configured to be in its initial phase. For other methods a NotImplementedError 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 to tell 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 a NotImplementedError is returned.

tell(fxs)[source]

Performs an iteration of the MCMC algorithm, using the pints.LogPDF evaluations fxs of the points xs specified by ask.

For methods that require sensitivities (see MCMCSamper.needs_sensitivities()), each entry in fxs should be a tuple (log_pdf, sensitivities), containing the values returned by pints.LogPdf.evaluateS1().

After a successful call, tell() returns a tuple (xs, fxs, accepted), where x contains the current position of the chain, fx contains the corresponding evaluation, and accepted 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.