gpMCMC#

class gpcam.gpMCMC(log_likelihood_function, prior_function, proposal_distributions=None, args=None)[source]#

This class allows the user to customize an MCMC via user-defined proposal distributions and a prior.

Parameters:
  • log_likelihood_function (callable) – The log of the likelihood to be sampled. Function of the form def likelihood(x,args) that returns a scalar.

  • prior_function (callable) – Function to query for the prior probability of form: func(x, obj), where x is the current vector and obj is this gpMCMC object instance.

  • proposal_distributions (iterable) – A list of object instances of ProposalDistribution.

  • args (Any, optional) – Arguments that will be communicated to all Callables.

trace#

Solution after run_mcmc is executed.

Type:

dict

run_mcmc(*, x0, n_updates=10000, info=False, break_condition=None, run_in_every_iteration=None)[source]#

This function runs the mcmc.

Parameters:
  • x0 (np.ndarray) – Starting point of the mcmc.

  • n_updates (int, optional) – The log of the likelihood to be sampled.

  • info (bool) – Whether to print information about the mcmc iterations.

  • break_condition (callable or string or None) – A break condition that specified when the mcmc is terminated. If None, mcmc will run until n_updates is reached. If a callable is provided, it will get the mcmc object instance as input: def break(obj). The only allowed string is default and in that case the mcmc will be terminated if the mean of the position has not changed significantly in the last 200 iterations.

  • run_in_every_iteration (callable, optional) – A callable that is executed in every iteration. Form: func(obj). Default no-op.

Returns:

trace information – Mean, medians, and variances of the last 1% are presented. All other returns consider the whole trace. The traces x are all the accepted positions in the MCMC.

Return type:

dict

class gpcam.ProposalDistribution(indices, proposal_dist='normal', init_prop_Sigma=None, adapt_callable=None, r_opt=0.234, c_0=10, c_1=0.8, K=10, auto_accept=False, adapt_cov=True, prop_args=None, ID=None)[source]#

Class to define a proposal distribution.

Parameters:
  • indices (iterable of int) – The indices of the parameters that should be drawn from this proposal distribution.

  • proposal_dist (callable, optional) – A callable to calculate the proposal distribution evaluation. It is defined as def name(x, para, obj), where obj is a proposal_distribution object instance. The function should return a new proposal for x. para are all other parameters. Default is a normal distribution with the default init_prop_sigma.

  • init_prop_Sigma (np.ndarray, optional) – If the proposal distribution is normal this is the covariance of the initial proposal distribution. It will be updated if adapt_callable = normal or a callable. While it is optional to provide it, it is highly recommended to do so. A warning will be printed in that case. A good rule of thumb is to orient yourself on the size of your domain. The default is the identity matrix.

  • adapt_callable (Callable or None or string, optional) – A callable to adapt the distribution. The default is None which means the proposal distribution will not be adapted. Use normal (default) for the default adaption procedure for normal distributions. The callable should be defined as def adapt(index, mcmc_obj) and not return anything but update the ProposalDistribution.prop_args attribute. Note, any adapt function will have to be well thought through. Most adapt functions will not lead to a stationary final distributions. Use with caution.

  • auto_accept (bool, optional) – Indicates whether to auto-accept the jump.

  • prop_args (Any, optional) – Arguments that will be available as obj attribute in proposal_dist`and `adapt_callable.