Backends
Backends are used to store sampler information as it runs.
Regular Backend
- class eryn.backends.Backend(store_missing_leaves=nan, dtype=None)
Bases:
objectA simple default backend that stores the chain in memory
- Parameters:
store_missing_leaves (double, optional) – Number to store for leaves that are not used in a specific step. (default:
np.nan)dtype (dtype, optional) – Dtype to use for data storage. If None, program uses np.float64. (default:
None)
- accepted
Number of accepted steps for within-model moves. The shape is (ntemps, nwalkers).
- Type:
2D int np.ndarray
- betas
Inverse temperature latter at each step. Shape is (nsteps, ntemps). This keeps track of adjustable temperatures.
- Type:
2D double np.ndarray
- blobs
Stores extra blob information returned from likelihood function. Shape is (nsteps, ntemps, nwalkers, nblobs).
- Type:
4D double np.ndarray
- branch_names
List of branch names.
- Type:
list of str
- chain
Dictionary with branch_names as keys. The values are 5D double np.ndarray arrays with shape (nsteps, ntemps, nwalkers, nleaves_max, ndim). These are the locations of walkers over the MCMC run.
- Type:
dict
- dtype
Dtype to use for data storage.
- Type:
dtype
- inds
Keys are branch_names. Values are 4D bool np.ndarray of shape (nsteps, ntemps, nwalkers, nleaves_max). This array details which leaves are used in the current step. This is really only relevant for reversible jump.
- Type:
dict
- initiailized
If
True, backend object has been initialized.- Type:
bool
- iteration
Current index within the data storage arrays.
- Type:
int
- log_prior
Log of the prior values. Shape is (nsteps, nwalkers, ntemps).
- Type:
3D double np.ndarray
- log_like
Log of the likelihood values. Shape is (nsteps, nwalkers, ntemps).
- Type:
3D double np.ndarray
- move_info
Dictionary containing move info.
- Type:
dict
- move_keys
List of keys for
move_info.- Type:
list
- nbranches
Number of branches.
- Type:
int
- ndims
Dimensionality of each branch.
- Type:
dict
- nleaves_max
Maximum allowable leaves for each branch.
- Type:
dict
- nwalkers
The size of the ensemble (per temperature).
- Type:
int
- ntemps
Number of rungs in the temperature ladder.
- Type:
int
- reset_args
Arguments to reset backend.
- Type:
tuple
- reset_kwargs
Keyword arguments to reset backend.
- Type:
dict
- rj
If True, reversible-jump techniques are used.
- Type:
bool
- rj_accepted
Number of accepted steps for between-model moves. The shape is (ntemps, nwalkers).
- Type:
2D int np.ndarray
- store_missing_leaves
Number to store for leaves that are not used in a specific step.
- Type:
double
- reset_base()
Allows for simple reset based on previous inputs
- reset(nwalkers, ndims, nleaves_max=1, ntemps=1, branch_names=None, nbranches=1, rj=False, moves=None, **info)
Clear the state of the chain and empty the backend
- Parameters:
nwalkers (int) – The size of the ensemble (per temperature).
ndims (int, list of ints, or dict) – The number of dimensions for each branch. If
dict, keys should be the branch names and values the associated dimensionality.nleaves_max (int, list of ints, or dict, optional) – Maximum allowable leaf count for each branch. It should have the same length as the number of branches. If
dict, keys should be the branch names and values the associated maximal leaf value. (default:1)ntemps (int, optional) – Number of rungs in the temperature ladder. (default:
1)branch_names (str or list of str, optional) – Names of the branches used. If not given, branches will be names
model_0, …,model_nfornbranches. (default:None)nbranches (int, optional) – Number of branches. This is only used if
branch_names is None. (default:1)rj (bool, optional) – If True, reversible-jump techniques are used. (default:
False)moves (list, optional) – List of all of the move classes input into the sampler. (default:
None)**info (dict, optional) – Any other key-value pairs to be added as attributes to the backend.
- has_blobs()
Returns
Trueif the model includes blobs
- get_value(name, thin=1, discard=0, slice_vals=None, temp_index=None, branch_names=None)
Returns a requested value to user.
This function helps to streamline the backend for both basic and hdf backend.
- Parameters:
name (str) – Name of value requested.
thin (int, optional) – Take only every
thinsteps from the chain. (default:1)discard (int, optional) – Discard the first
discardsteps in the chain as burn-in. (default:0)slice_vals (indexing np.ndarray or slice, optional) – Ignored for non-HDFBackend.
temp_index (int, optional) – Integer for the desired temperature index. If
None, will return all temperatures. (default:None)branch_names (str or list, optional) – Specific branch names requested. (default:
None)
- Returns:
Values requested.
- Return type:
dict or np.ndarray
- get_chain(**kwargs)
Get the stored chain of MCMC samples
- Parameters:
thin (int, optional) – Take only every
thinsteps from the chain. (default:1)discard (int, optional) – Discard the first
discardsteps in the chain as burn-in. (default:0)slice_vals (indexing np.ndarray or slice, optional) – This is only available in
eryn.backends.hdfbackend. If provided, slice the array directly from the HDF5 file with slice =slice_vals.thinanddiscardwill be ignored if slice_vals is notNone. This is particularly useful if files are very large and the user only wants a small subset of the overall array. (default:None)temp_index (int, optional) – Integer for the desired temperature index. If
None, will return all temperatures. (default:None)
- Returns:
- MCMC samples
The dictionary contains np.ndarrays of samples across the branches.
- Return type:
dict
- get_autocorr_thin_burn()
Return the discard and thin values based on the autocorrelation length.
The
discardis determined as 2 times the maximum correlation length among parameters. Thethinis determined using 1/2 times the minimum correlation legnth among parameters.- Returns:
- Information on thin and burn
(discard, thin)
- Return type:
tuple
- get_inds(**kwargs)
Get the stored chain of MCMC samples
- Parameters:
thin (int, optional) – Take only every
thinsteps from the chain. (default:1)discard (int, optional) – Discard the first
discardsteps in the chain as burn-in. (default:0)slice_vals (indexing np.ndarray or slice, optional) – This is only available in
eryn.backends.hdfbackend. If provided, slice the array directly from the HDF5 file with slice =slice_vals.thinanddiscardwill be ignored if slice_vals is notNone. This is particularly useful if files are very large and the user only wants a small subset of the overall array. (default:None)temp_index (int, optional) – Integer for the desired temperature index. If
None, will return all temperatures. (default:None)
- Returns:
- The
indsassociated with the MCMC samples. The dictionary contains np.ndarrays of
indsacross the branches indicated which leaves were used at each step.
- The
- Return type:
dict
- get_nleaves(**kwargs)
Get the number of leaves for each walker
- Parameters:
thin (int, optional) – Take only every
thinsteps from the chain. (default:1)discard (int, optional) – Discard the first
discardsteps in the chain as burn-in. (default:0)slice_vals (indexing np.ndarray or slice, optional) – This is only available in
eryn.backends.hdfbackend. If provided, slice the array directly from the HDF5 file with slice =slice_vals.thinanddiscardwill be ignored if slice_vals is notNone. This is particularly useful if files are very large and the user only wants a small subset of the overall array. (default:None)temp_index (int, optional) – Integer for the desired temperature index. If
None, will return all temperatures. (default:None)
- Returns:
- nleaves on each branch.
- The number of leaves on each branch associated with the MCMC samples
within each branch.
- Return type:
dict
- get_blobs(**kwargs)
Get the chain of blobs for each sample in the chain
- Parameters:
thin (int, optional) – Take only every
thinsteps from the chain. (default:1)discard (int, optional) – Discard the first
discardsteps in the chain as burn-in. (default:0)slice_vals (indexing np.ndarray or slice, optional) – This is only available in
eryn.backends.hdfbackend. If provided, slice the array directly from the HDF5 file with slice =slice_vals.thinanddiscardwill be ignored if slice_vals is notNone. This is particularly useful if files are very large and the user only wants a small subset of the overall array. (default:None)temp_index (int, optional) – Integer for the desired temperature index. If
None, will return all temperatures. (default:None)
- Returns:
The chain of blobs.
- Return type:
double np.ndarray[nsteps, ntemps, nwalkers, nblobs]
- get_log_like(**kwargs)
Get the chain of log Likelihood values evaluated at the MCMC samples
- Parameters:
thin (int, optional) – Take only every
thinsteps from the chain. (default:1)discard (int, optional) – Discard the first
discardsteps in the chain as burn-in. (default:0)slice_vals (indexing np.ndarray or slice, optional) – This is only available in
eryn.backends.hdfbackend. If provided, slice the array directly from the HDF5 file with slice =slice_vals.thinanddiscardwill be ignored if slice_vals is notNone. This is particularly useful if files are very large and the user only wants a small subset of the overall array. (default:None)temp_index (int, optional) – Integer for the desired temperature index. If
None, will return all temperatures. (default:None)
- Returns:
The chain of log likelihood values.
- Return type:
double np.ndarray[nsteps, ntemps, nwalkers]
- get_log_prior(**kwargs)
Get the chain of log Prior evaluated at the MCMC samples
- Parameters:
thin (int, optional) – Take only every
thinsteps from the chain. (default:1)discard (int, optional) – Discard the first
discardsteps in the chain as burn-in. (default:0)slice_vals (indexing np.ndarray or slice, optional) – This is only available in
eryn.backends.hdfbackend. If provided, slice the array directly from the HDF5 file with slice =slice_vals.thinanddiscardwill be ignored if slice_vals is notNone. This is particularly useful if files are very large and the user only wants a small subset of the overall array. (default:None)temp_index (int, optional) – Integer for the desired temperature index. If
None, will return all temperatures. (default:None)
- Returns:
The chain of log prior values.
- Return type:
double np.ndarray[nsteps, ntemps, nwalkers]
- get_log_posterior(temper: bool = False, **kwargs)
Get the chain of log posterior values evaluated at the MCMC samples
- Parameters:
temper (bool, optional) – Apply tempering to the posterior values. (default:
False)thin (int, optional) – Take only every
thinsteps from the chain. (default:1)discard (int, optional) – Discard the first
discardsteps in the chain as burn-in. (default:0)slice_vals (indexing np.ndarray or slice, optional) – This is only available in
eryn.backends.hdfbackend. If provided, slice the array directly from the HDF5 file with slice =slice_vals.thinanddiscardwill be ignored if slice_vals is notNone. This is particularly useful if files are very large and the user only wants a small subset of the overall array. (default:None)temp_index (int, optional) – Integer for the desired temperature index. If
None, will return all temperatures. (default:None)
- Returns:
The chain of log prior values.
- Return type:
double np.ndarray[nsteps, ntemps, nwalkers]
- get_betas(**kwargs)
Get the chain of inverse temperatures
- Parameters:
thin (int, optional) – Take only every
thinsteps from the chain. (default:1)discard (int, optional) – Discard the first
discardsteps in the chain as burn-in. (default:0)slice_vals (indexing np.ndarray or slice, optional) – This is only available in
eryn.backends.hdfbackend. If provided, slice the array directly from the HDF5 file with slice =slice_vals.thinanddiscardwill be ignored if slice_vals is notNone. This is particularly useful if files are very large and the user only wants a small subset of the overall array. (default:None)temp_index (int, optional) – Integer for the desired temperature index. If
None, will return all temperatures. (default:None)
- Returns:
The chain of temperatures.
- Return type:
double np.ndarray[nsteps, ntemps]
- get_a_sample(it)
Access a sample in the chain
- Parameters:
it (int) – iteration of State to return.
- Returns:
eryn.state.Stateobject containing the sample from the chain.- Return type:
- Raises:
AttributeError – Backend is not initialized.
- get_last_sample()
Access the most recent sample in the chain
- Returns:
eryn.state.Stateobject containing the last sample from the chain.- Return type:
- get_autocorr_time(discard=0, thin=1, all_temps=False, multiply_thin=True, **kwargs)
Compute an estimate of the autocorrelation time for each parameter
- Parameters:
discard (int, optional) – Discard the first
discardsteps in the chain as burn-in. (default:0)thin (int, optional) – Use only every
thinsteps from the chain. The returned estimate is multiplied bythinso the estimated time is in units of steps, not thinned steps. (default:1)all_temps (bool, optional) – If True, calculate autocorrelation across all temperatures. If False, calculate autocorrelation across the minumum temperature chain (usually
T=1). (default:False)multiply_thin (bool, optional) – into the autocorrelation length. (default:
True)
Other arguments are passed directly to
emcee.autocorr.integrated_time().- Returns:
- autocorrelation times
The dictionary contains autocorrelation times for all parameters as 1D double np.ndarrays as values with associated
branch_namesas keys.
- Return type:
dict
- get_evidence_estimate(discard=0, thin=1, return_error=True, method='therodynamic', **ss_kwargs)
Get an estimate of the evidence
This function gets the sample information and uses
thermodynamic_integration_log_evidence()orstepping_stone_log_evidence()to compute the evidence estimate.- Parameters:
discard (int, optional) – Discard the first
discardsteps in the chain as burn-in. (default:0)thin (int, optional) – Use only every
thinsteps from the chain. The returned estimate is multiplied bythinso the estimated time is in units of steps, not thinned steps. (default:1)return_error (bool, optional) – If True, return the error associated with the log evidence estimate. (default:
True)method (string, optional) – Method to compute the evidence. Available methods are the ‘thermodynamic’ and ‘stepping-stone’ (default:
thermodynamic)
- Returns:
- Evidence estimate
If requesting the error on the estimate, will receive a tuple:
(logZ, dlogZ). Otherwise, just a double value of logZ.
- Return type:
double or tuple
- get_gelman_rubin_convergence_diagnostic(discard=0, thin=1, doprint=True, **psrf_kwargs)
The Gelman - Rubin convergence diagnostic. A general approach to monitoring convergence of MCMC output of multiple walkers. The function makes a comparison of within-chain and between-chain variances. A large deviation between these two variances indicates non-convergence, and the output [Rhat] deviates from unity.
Based on a. Brooks, SP. and Gelman, A. (1998) General methods for monitoring convergence of iterative simulations. Journal of Computational and Graphical Statistics, 7, 434-455 b. Gelman, A and Rubin, DB (1992) Inference from iterative simulation using multiple sequences, Statistical Science, 7, 457-511.
- Parameters:
C (np.ndarray[nwalkers, nsamples, ndim]) – The parameter traces. The MCMC chains.
doprint (bool, optional) – Flag to print the results on screen.
- discard (int, optional): Discard the first
discardsteps in the chain as burn-in. (default:
0)- thin (int, optional): Use only every
thinsteps from the chain. The returned estimate is multiplied by
thinso the estimated time is in units of steps, not thinned steps. (default:1)
doprint (bool, optional): Flag to print a table with the results, per temperature.
- Returns
- dict:
Rhat_all_branches: Returns an estimate of the Gelman-Rubin convergence diagnostic
Rhat, per temperature, stored in a dictionary, per branch name.
- dict:
- property shape
The dimensions of the ensemble
- Returns:
- Shape of samples
Keys are
branch_namesand values are tuples with shapes of individual branches: (ntemps, nwalkers, nleaves_max, ndim).
- Return type:
dict
- grow(ngrow, blobs)
Expand the storage space by some number of samples
- Parameters:
ngrow (int) – The number of steps to grow the chain.
blobs (None or np.ndarray) – The current array of blobs. This is used to compute the dtype for the blobs array.
- get_move_info()
Get move information.
- Returns:
Keys are move names and values are dictionaries with information on the moves.
- Return type:
dict
- save_step(state, accepted, rj_accepted=None, swaps_accepted=None, moves_accepted_fraction=None)
Save a step to the backend
- Parameters:
state (State) – The
Stateof the ensemble.accepted (ndarray) – An array of boolean flags indicating whether or not the proposal for each walker was accepted.
rj_accepted (ndarray, optional) – An array of the number of accepted steps for the reversible jump proposal for each walker. If
self.rjis True, then rj_accepted must be an array withrj_accepted.shape == accepted.shape. Ifself.rjis False, then rj_accepted must be None, which is the default.swaps_accepted (ndarray, optional) – 1D array with number of swaps accepted for the in-model step. (default:
None)moves_accepted_fraction (dict, optional) – Dict of acceptance fraction arrays for all of the moves in the sampler. This dict must have the same keys as
self.move_keys. (default:None)
- get_info(discard=0, thin=1)
Get an output info dictionary
This dictionary could be used for diagnostics or plotting.
- Parameters:
discard (int, optional) – Discard the first
discardsteps in the chain as burn-in. (default:0)thin (int, optional) – Use only every
thinsteps from the chain. The returned estimate is multiplied bythinso the estimated time is in units of steps, not thinned steps. (default:1)
- Returns:
- Information for diagnostics
Dictionary that contains much of the information for diagnostic checks or plotting.
- Return type:
dict
HDF Backend
- class eryn.backends.HDFBackend(filename, name='mcmc', read_only=False, dtype=None, compression=None, compression_opts=None, store_missing_leaves=nan)
Bases:
BackendA backend that stores the chain in an HDF5 file using h5py
Note
You must install h5py to use this backend.
- Parameters:
filename (str) – The name of the HDF5 file where the chain will be saved.
name (str, optional) – The name of the group where the chain will be saved. (default:
"mcmc")read_only (bool, optional) – If
True, the backend will throw aRuntimeErrorif the file is opened with write access. (default:False)dtype (dtype, optional) – Dtype to use for data storage. If None, program uses np.float64. (default:
None)compression (str, optional) – Compression type for h5 file. See more information in the h5py documentation. (default:
None)compression_opts (int, optional) –
Compression level for h5 file. See more information in the h5py documentation. (default:
None)store_missing_leaves (double, optional) – Number to store for leaves that are not used in a specific step. (default:
np.nan)
- property initialized
Check if backend file has been initialized properly.
- open(mode='r')
Opens the h5 file in the proper mode.
- Parameters:
mode (str, optional) – Mode to open h5 file.
- Returns:
Opened file.
- Return type:
H5 file object
- Raises:
RuntimeError – If backend is opened for writing when it is read-only.
- reset(nwalkers, ndims, nleaves_max=1, ntemps=1, branch_names=None, nbranches=1, rj=False, moves=None, **info)
Clear the state of the chain and empty the backend
- Parameters:
nwalkers (int) – The size of the ensemble
ndims (int, list of ints, or dict) – The number of dimensions for each branch. If
dict, keys should be the branch names and values the associated dimensionality.nleaves_max (int, list of ints, or dict, optional) – Maximum allowable leaf count for each branch. It should have the same length as the number of branches. If
dict, keys should be the branch names and values the associated maximal leaf value. (default:1)ntemps (int, optional) – Number of rungs in the temperature ladder. (default:
1)branch_names (str or list of str, optional) – Names of the branches used. If not given, branches will be names
model_0, …,model_nfornbranches. (default:None)nbranches (int, optional) – Number of branches. This is only used if
branch_names is None. (default:1)rj (bool, optional) – If True, reversible-jump techniques are used. (default:
False)moves (list, optional) – List of all of the move classes input into the sampler. (default:
None)**info (dict, optional) – Any other key-value pairs to be added as attributes to the backend. These are also added to the HDF5 file.
- property nwalkers
Get nwalkers from h5 file.
- property ntemps
Get ntemps from h5 file.
- property rj
Get rj from h5 file.
- property nleaves_max
Get nleaves_max from h5 file.
- property ndims
Get ndims from h5 file.
- property move_keys
Get move_keys from h5 file.
- property branch_names
Get branch names from h5 file.
- property nbranches
Get number of branches from h5 file.
- property reset_args
Get reset_args from h5 file.
- property reset_kwargs
Get reset_kwargs from h5 file.
- has_blobs()
Returns
Trueif the model includes blobs
- get_value(name, thin=1, discard=0, slice_vals=None, temp_index=None, branch_names=None)
Returns a requested value to user.
This function helps to streamline the backend for both basic and hdf backend.
- Parameters:
name (str) – Name of value requested.
thin (int, optional) – Take only every
thinsteps from the chain. (default:1)discard (int, optional) – Discard the first
discardsteps in the chain as burn-in. (default:0)slice_vals (indexing np.ndarray or slice, optional) – If provided, slice the array directly from the HDF5 file with slice =
slice_vals.thinanddiscardwill be ignored if slice_vals is notNone. This is particularly useful if files are very large and the user only wants a small subset of the overall array. (default:None)temp_index (int, optional) – Integer for the desired temperature index. If
None, will return all temperatures. (default:None)branch_names (str or list, optional) – Specific branch names requested. (default:
None)
- Returns:
Values requested.
- Return type:
dict or np.ndarray
- get_move_info()
Get move information.
- Returns:
Keys are move names and values are dictionaries with information on the moves.
- Return type:
dict
- property shape
The dimensions of the ensemble
- Returns:
- Shape of samples
Keys are
branch_namesand values are tuples with shapes of individual branches: (ntemps, nwalkers, nleaves_max, ndim).
- Return type:
dict
- property iteration
Number of iterations stored in the hdf backend so far.
- property accepted
Number of accepted moves per walker.
- property rj_accepted
Number of accepted rj moves per walker.
- property swaps_accepted
Number of accepted swaps.
- property random_state
Get the random state
- grow(ngrow, blobs)
Expand the storage space by some number of samples
- Parameters:
ngrow (int) – The number of steps to grow the chain.
blobs (None or np.ndarray) – The current array of blobs. This is used to compute the dtype for the blobs array.
- save_step(state, accepted, rj_accepted=None, swaps_accepted=None, moves_accepted_fraction=None)
Save a step to the backend
- Parameters:
state (State) – The
Stateof the ensemble.accepted (ndarray) – An array of boolean flags indicating whether or not the proposal for each walker was accepted.
rj_accepted (ndarray, optional) – An array of the number of accepted steps for the reversible jump proposal for each walker. If
self.rjis True, then rj_accepted must be an array withrj_accepted.shape == accepted.shape. Ifself.rjis False, then rj_accepted must be None, which is the default.swaps_accepted (ndarray, optional) – 1D array with number of swaps accepted for the in-model step. (default:
None)moves_accepted_fraction (dict, optional) – Dict of acceptance fraction arrays for all of the moves in the sampler. This dict must have the same keys as
self.move_keys. (default:None)
- get_a_sample(it)
Access a sample in the chain
- Parameters:
it (int) – iteration of State to return.
- Returns:
eryn.state.Stateobject containing the sample from the chain.- Return type:
- Raises:
AttributeError – Backend is not initialized.
- get_autocorr_thin_burn()
Return the discard and thin values based on the autocorrelation length.
The
discardis determined as 2 times the maximum correlation length among parameters. Thethinis determined using 1/2 times the minimum correlation legnth among parameters.- Returns:
- Information on thin and burn
(discard, thin)
- Return type:
tuple
- get_autocorr_time(discard=0, thin=1, all_temps=False, multiply_thin=True, **kwargs)
Compute an estimate of the autocorrelation time for each parameter
- Parameters:
discard (int, optional) – Discard the first
discardsteps in the chain as burn-in. (default:0)thin (int, optional) – Use only every
thinsteps from the chain. The returned estimate is multiplied bythinso the estimated time is in units of steps, not thinned steps. (default:1)all_temps (bool, optional) – If True, calculate autocorrelation across all temperatures. If False, calculate autocorrelation across the minumum temperature chain (usually
T=1). (default:False)multiply_thin (bool, optional) – into the autocorrelation length. (default:
True)
Other arguments are passed directly to
emcee.autocorr.integrated_time().- Returns:
- autocorrelation times
The dictionary contains autocorrelation times for all parameters as 1D double np.ndarrays as values with associated
branch_namesas keys.
- Return type:
dict
- get_betas(**kwargs)
Get the chain of inverse temperatures
- Parameters:
thin (int, optional) – Take only every
thinsteps from the chain. (default:1)discard (int, optional) – Discard the first
discardsteps in the chain as burn-in. (default:0)slice_vals (indexing np.ndarray or slice, optional) – This is only available in
eryn.backends.hdfbackend. If provided, slice the array directly from the HDF5 file with slice =slice_vals.thinanddiscardwill be ignored if slice_vals is notNone. This is particularly useful if files are very large and the user only wants a small subset of the overall array. (default:None)temp_index (int, optional) – Integer for the desired temperature index. If
None, will return all temperatures. (default:None)
- Returns:
The chain of temperatures.
- Return type:
double np.ndarray[nsteps, ntemps]
- get_blobs(**kwargs)
Get the chain of blobs for each sample in the chain
- Parameters:
thin (int, optional) – Take only every
thinsteps from the chain. (default:1)discard (int, optional) – Discard the first
discardsteps in the chain as burn-in. (default:0)slice_vals (indexing np.ndarray or slice, optional) – This is only available in
eryn.backends.hdfbackend. If provided, slice the array directly from the HDF5 file with slice =slice_vals.thinanddiscardwill be ignored if slice_vals is notNone. This is particularly useful if files are very large and the user only wants a small subset of the overall array. (default:None)temp_index (int, optional) – Integer for the desired temperature index. If
None, will return all temperatures. (default:None)
- Returns:
The chain of blobs.
- Return type:
double np.ndarray[nsteps, ntemps, nwalkers, nblobs]
- get_chain(**kwargs)
Get the stored chain of MCMC samples
- Parameters:
thin (int, optional) – Take only every
thinsteps from the chain. (default:1)discard (int, optional) – Discard the first
discardsteps in the chain as burn-in. (default:0)slice_vals (indexing np.ndarray or slice, optional) – This is only available in
eryn.backends.hdfbackend. If provided, slice the array directly from the HDF5 file with slice =slice_vals.thinanddiscardwill be ignored if slice_vals is notNone. This is particularly useful if files are very large and the user only wants a small subset of the overall array. (default:None)temp_index (int, optional) – Integer for the desired temperature index. If
None, will return all temperatures. (default:None)
- Returns:
- MCMC samples
The dictionary contains np.ndarrays of samples across the branches.
- Return type:
dict
- get_evidence_estimate(discard=0, thin=1, return_error=True, method='therodynamic', **ss_kwargs)
Get an estimate of the evidence
This function gets the sample information and uses
thermodynamic_integration_log_evidence()orstepping_stone_log_evidence()to compute the evidence estimate.- Parameters:
discard (int, optional) – Discard the first
discardsteps in the chain as burn-in. (default:0)thin (int, optional) – Use only every
thinsteps from the chain. The returned estimate is multiplied bythinso the estimated time is in units of steps, not thinned steps. (default:1)return_error (bool, optional) – If True, return the error associated with the log evidence estimate. (default:
True)method (string, optional) – Method to compute the evidence. Available methods are the ‘thermodynamic’ and ‘stepping-stone’ (default:
thermodynamic)
- Returns:
- Evidence estimate
If requesting the error on the estimate, will receive a tuple:
(logZ, dlogZ). Otherwise, just a double value of logZ.
- Return type:
double or tuple
- get_gelman_rubin_convergence_diagnostic(discard=0, thin=1, doprint=True, **psrf_kwargs)
The Gelman - Rubin convergence diagnostic. A general approach to monitoring convergence of MCMC output of multiple walkers. The function makes a comparison of within-chain and between-chain variances. A large deviation between these two variances indicates non-convergence, and the output [Rhat] deviates from unity.
Based on a. Brooks, SP. and Gelman, A. (1998) General methods for monitoring convergence of iterative simulations. Journal of Computational and Graphical Statistics, 7, 434-455 b. Gelman, A and Rubin, DB (1992) Inference from iterative simulation using multiple sequences, Statistical Science, 7, 457-511.
- Parameters:
C (np.ndarray[nwalkers, nsamples, ndim]) – The parameter traces. The MCMC chains.
doprint (bool, optional) – Flag to print the results on screen.
- discard (int, optional): Discard the first
discardsteps in the chain as burn-in. (default:
0)- thin (int, optional): Use only every
thinsteps from the chain. The returned estimate is multiplied by
thinso the estimated time is in units of steps, not thinned steps. (default:1)
doprint (bool, optional): Flag to print a table with the results, per temperature.
- Returns
- dict:
Rhat_all_branches: Returns an estimate of the Gelman-Rubin convergence diagnostic
Rhat, per temperature, stored in a dictionary, per branch name.
- dict:
- get_inds(**kwargs)
Get the stored chain of MCMC samples
- Parameters:
thin (int, optional) – Take only every
thinsteps from the chain. (default:1)discard (int, optional) – Discard the first
discardsteps in the chain as burn-in. (default:0)slice_vals (indexing np.ndarray or slice, optional) – This is only available in
eryn.backends.hdfbackend. If provided, slice the array directly from the HDF5 file with slice =slice_vals.thinanddiscardwill be ignored if slice_vals is notNone. This is particularly useful if files are very large and the user only wants a small subset of the overall array. (default:None)temp_index (int, optional) – Integer for the desired temperature index. If
None, will return all temperatures. (default:None)
- Returns:
- The
indsassociated with the MCMC samples. The dictionary contains np.ndarrays of
indsacross the branches indicated which leaves were used at each step.
- The
- Return type:
dict
- get_info(discard=0, thin=1)
Get an output info dictionary
This dictionary could be used for diagnostics or plotting.
- Parameters:
discard (int, optional) – Discard the first
discardsteps in the chain as burn-in. (default:0)thin (int, optional) – Use only every
thinsteps from the chain. The returned estimate is multiplied bythinso the estimated time is in units of steps, not thinned steps. (default:1)
- Returns:
- Information for diagnostics
Dictionary that contains much of the information for diagnostic checks or plotting.
- Return type:
dict
- get_last_sample()
Access the most recent sample in the chain
- Returns:
eryn.state.Stateobject containing the last sample from the chain.- Return type:
- get_log_like(**kwargs)
Get the chain of log Likelihood values evaluated at the MCMC samples
- Parameters:
thin (int, optional) – Take only every
thinsteps from the chain. (default:1)discard (int, optional) – Discard the first
discardsteps in the chain as burn-in. (default:0)slice_vals (indexing np.ndarray or slice, optional) – This is only available in
eryn.backends.hdfbackend. If provided, slice the array directly from the HDF5 file with slice =slice_vals.thinanddiscardwill be ignored if slice_vals is notNone. This is particularly useful if files are very large and the user only wants a small subset of the overall array. (default:None)temp_index (int, optional) – Integer for the desired temperature index. If
None, will return all temperatures. (default:None)
- Returns:
The chain of log likelihood values.
- Return type:
double np.ndarray[nsteps, ntemps, nwalkers]
- get_log_posterior(temper: bool = False, **kwargs)
Get the chain of log posterior values evaluated at the MCMC samples
- Parameters:
temper (bool, optional) – Apply tempering to the posterior values. (default:
False)thin (int, optional) – Take only every
thinsteps from the chain. (default:1)discard (int, optional) – Discard the first
discardsteps in the chain as burn-in. (default:0)slice_vals (indexing np.ndarray or slice, optional) – This is only available in
eryn.backends.hdfbackend. If provided, slice the array directly from the HDF5 file with slice =slice_vals.thinanddiscardwill be ignored if slice_vals is notNone. This is particularly useful if files are very large and the user only wants a small subset of the overall array. (default:None)temp_index (int, optional) – Integer for the desired temperature index. If
None, will return all temperatures. (default:None)
- Returns:
The chain of log prior values.
- Return type:
double np.ndarray[nsteps, ntemps, nwalkers]
- get_log_prior(**kwargs)
Get the chain of log Prior evaluated at the MCMC samples
- Parameters:
thin (int, optional) – Take only every
thinsteps from the chain. (default:1)discard (int, optional) – Discard the first
discardsteps in the chain as burn-in. (default:0)slice_vals (indexing np.ndarray or slice, optional) – This is only available in
eryn.backends.hdfbackend. If provided, slice the array directly from the HDF5 file with slice =slice_vals.thinanddiscardwill be ignored if slice_vals is notNone. This is particularly useful if files are very large and the user only wants a small subset of the overall array. (default:None)temp_index (int, optional) – Integer for the desired temperature index. If
None, will return all temperatures. (default:None)
- Returns:
The chain of log prior values.
- Return type:
double np.ndarray[nsteps, ntemps, nwalkers]
- get_nleaves(**kwargs)
Get the number of leaves for each walker
- Parameters:
thin (int, optional) – Take only every
thinsteps from the chain. (default:1)discard (int, optional) – Discard the first
discardsteps in the chain as burn-in. (default:0)slice_vals (indexing np.ndarray or slice, optional) – This is only available in
eryn.backends.hdfbackend. If provided, slice the array directly from the HDF5 file with slice =slice_vals.thinanddiscardwill be ignored if slice_vals is notNone. This is particularly useful if files are very large and the user only wants a small subset of the overall array. (default:None)temp_index (int, optional) – Integer for the desired temperature index. If
None, will return all temperatures. (default:None)
- Returns:
- nleaves on each branch.
- The number of leaves on each branch associated with the MCMC samples
within each branch.
- Return type:
dict
- reset_base()
Allows for simple reset based on previous inputs