MCMC Sampler base classes¶
- class pints.MCMCSampler[source]¶
Abstract base class for (single or multi-chain) MCMC methods.
All MCMC samplers implement the
pints.Loggableandpints.TunableMethodinterfaces.- in_initial_phase()[source]¶
For methods that need an initial phase (see
needs_initial_phase()), this method returnsTrueif the method is currently configured to be in its initial phase. For other methods aNotImplementedErroris returned.
- n_hyper_parameters()¶
Returns the number of hyper-parameters for this method (see
TunableMethod).
- needs_initial_phase()[source]¶
Returns
Trueif 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
Trueif this methods needs sensitivities to be passed in totellalong 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_parametersused 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 aNotImplementedErroris 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 returnsTrueif the method is currently configured to be in its initial phase. For other methods aNotImplementedErroris returned.
- n_hyper_parameters()¶
Returns the number of hyper-parameters for this method (see
TunableMethod).
- classmethod name()¶
Returns this method’s full name.
- needs_initial_phase()¶
Returns
Trueif 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
Trueif this methods needs sensitivities to be passed in totellalong 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_parametersused 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 aNotImplementedErroris returned.
- tell(fx)[source]¶
Performs an iteration of the MCMC algorithm, using the
pints.LogPDFevaluationfxof the pointxspecified byask.For methods that require sensitivities (see
MCMCSamper.needs_sensitivities()),fxshould be a tuple(log_pdf, sensitivities), containing the values returned bypints.LogPdf.evaluateS1().After a successful call,
tell()returns a tuple(x, fx, accepted), wherexcontains the current position of the chain,fxcontains the corresponding evaluation, andacceptedis 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
Noneto 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
logpdfaround the points inx0(the samesigma0is used for each point inx0). Can be specified as a(d, d)matrix (wheredis 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 returnsTrueif the method is currently configured to be in its initial phase. For other methods aNotImplementedErroris returned.
- n_hyper_parameters()¶
Returns the number of hyper-parameters for this method (see
TunableMethod).
- classmethod name()¶
Returns this method’s full name.
- needs_initial_phase()¶
Returns
Trueif 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
Trueif this methods needs sensitivities to be passed in totellalong 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_parametersused 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 aNotImplementedErroris returned.
- tell(fxs)[source]¶
Performs an iteration of the MCMC algorithm, using the
pints.LogPDFevaluationsfxsof the pointsxsspecified byask.For methods that require sensitivities (see
MCMCSamper.needs_sensitivities()), each entry infxsshould be a tuple(log_pdf, sensitivities), containing the values returned bypints.LogPdf.evaluateS1().After a successful call,
tell()returns a tuple(xs, fxs, accepted), wherexcontains the current position of the chain,fxcontains the corresponding evaluation, andacceptedis 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
Noneto indicate an iteration is still in progress.