gwin.burn_in module

This modules provides classes and functions for determining when Markov Chains have burned in.

class gwin.burn_in.BurnIn(function_names, min_iterations=0)[source]

Bases: object

Class to estimate the number of burn in iterations.

Parameters:
  • function_names (list, optional) – List of name of burn in functions to use. All names in the provided list muset be in the burn_in_functions dict. If none provided, will use no burn-in functions.
  • min_iterations (int, optional) – Minimum number of burn in iterations to use. The burn in iterations returned by evaluate will be the maximum of this value and the values returned by the burn in functions provided in function_names. Default is 0.

Examples

Initialize a BurnIn instance that will use max_posterior and posterior_step as the burn in criteria:

>>> import gwin
>>> burn_in = gwin.BurnIn(['max_posterior', 'posterior_step'])

Use this BurnIn instance to find the burn-in iteration of each walker in an inference result file:

>>> from pycbc.io import InferenceFile
>>> fp = InferenceFile('gwin.hdf', 'r')
>>> burn_in.evaluate(gwin.samplers[fp.sampler_name], fp)
array([11486, 11983, 11894, ..., 11793, 11888, 11981])
evaluate(sampler, fp)[source]

Evaluates sampler’s chains to find burn in.

Parameters:
  • sampler (gwin.sampler) – Sampler to determine burn in for. May be either an instance of a gwin.sampler, or the class itself.
  • fp (InferenceFile) – Open inference hdf file containing the samples to load for determing burn in.
Returns:

  • burnidx (array) – Array of indices giving the burn-in index for each chain.
  • is_burned_in (array) – Array of booleans indicating whether each chain is burned in.

update(sampler, fp)[source]

Evaluates burn in and saves the updated indices to the given file.

Parameters:
  • sampler (gwin.sampler) – Sampler to determine burn in for. May be either an instance of a gwin.sampler, or the class itself.
  • fp (InferenceFile) – Open inference hdf file containing the samples to load for determing burn in.
Returns:

  • burnidx (array) – Array of indices giving the burn-in index for each chain.
  • is_burned_in (array) – Array of booleans indicating whether each chain is burned in.

gwin.burn_in.half_chain(sampler, fp)[source]

Takes the second half of the iterations as post-burn in.

Parameters:
  • sampler (gwin.sampler) – This option is not used; it is just here give consistent API as the other burn in functions.
  • fp (InferenceFile) – Open inference hdf file containing the samples to load for determing burn in.
Returns:

  • burn_in_idx (array) – Array of indices giving the burn-in index for each chain.
  • is_burned_in (array) – Array of booleans indicating whether each chain is burned in. By definition of this function, all values are set to True.

gwin.burn_in.ks_test(sampler, fp, threshold=0.9)[source]

Burn in based on whether the p-value of the KS test between the samples at the last iteration and the samples midway along the chain for each parameter is > threshold.

Parameters:
  • sampler (gwin.sampler) – Sampler to determine burn in for. May be either an instance of a gwin.sampler, or the class itself.
  • fp (InferenceFile) – Open inference hdf file containing the samples to load for determing burn in.
  • threshold (float) – The thershold to use for the p-value. Default is 0.9.
Returns:

  • burn_in_idx (array) – Array of indices giving the burn-in index for each chain.
  • is_burned_in (array) – Array of booleans indicating whether each chain is burned in.

gwin.burn_in.max_posterior(sampler, fp)[source]

Burn in based on samples being within dim/2 of maximum posterior.

Parameters:
  • sampler (gwin.sampler) – Sampler to determine burn in for. May be either an instance of a gwin.sampler, or the class itself.
  • fp (InferenceFile) – Open inference hdf file containing the samples to load for determing burn in.
Returns:

  • burn_in_idx (array) – Array of indices giving the burn-in index for each chain.
  • is_burned_in (array) – Array of booleans indicating whether each chain is burned in.

gwin.burn_in.n_acl(sampler, fp, nacls=10)[source]

Burn in based on ACL.

The sampler is considered burned in if the number of itertions is >= nacls times the maximum ACL over all parameters, as measured from the first iteration.

Parameters:
  • sampler (pycbc.inference.sampler) – Sampler to determine burn in for. May be either an instance of a inference.sampler, or the class itself.
  • fp (InferenceFile) – Open inference hdf file containing the samples to load for determing burn in.
  • nacls (int) – Number of ACLs to use for burn in. Default is 10.
Returns:

  • burn_in_idx (array) – Array of indices giving the burn-in index for each chain. By definition of this function, all chains reach burn in at the same iteration. Thus the returned array is the burn-in index repeated by the number of chains.
  • is_burned_in (array) – Array of booleans indicating whether each chain is burned in. Since all chains obtain burn in at the same time, this is either an array of all False or True.

gwin.burn_in.posterior_step(sampler, fp)[source]

Burn in based on the last time a chain made a jump > dim/2.

Parameters:
  • sampler (gwin.sampler) – Sampler to determine burn in for. May be either an instance of a gwin.sampler, or the class itself.
  • fp (InferenceFile) – Open inference hdf file containing the samples to load for determing burn in.
Returns:

  • burn_in_idx (array) – Array of indices giving the burn-in index for each chain.
  • is_burned_in (array) – Array of booleans indicating whether each chain is burned in. By definition of this function, all values are set to True.

gwin.burn_in.use_sampler(sampler, fp=None)[source]

Uses the sampler’s burn_in function.

Parameters:
  • sampler (gwin.sampler) – Sampler to determine burn in for. Must be an instance of an gwin.sampler that has a burn_in function.
  • fp (InferenceFile, optional) – This option is not used; it is just here give consistent API as the other burn in functions.
Returns:

  • burn_in_idx (array) – Array of indices giving the burn-in index for each chain.
  • is_burned_in (array) – Array of booleans indicating whether each chain is burned in. Since the sampler’s burn in function will run until all chains are burned, all values are set to True.