pymcmcstat.chain package¶
pymcmcstat.chain.ChainProcessing module¶
Created on Tue May 1 09:12:06 2018
@author: prmiles
-
pymcmcstat.chain.ChainProcessing.
check_parallel_directory_contents
(parallel_dir, cf_orig)[source]¶ Check that items in directory are subdirectories with name “chain_#”
-
pymcmcstat.chain.ChainProcessing.
generate_chain_list
(pres, burnin_percentage=50)[source]¶ Generate list of chains.
-
pymcmcstat.chain.ChainProcessing.
generate_combined_chain_with_index
(pres, burnin_percentage=50)[source]¶ Generate combined chain with index.
-
pymcmcstat.chain.ChainProcessing.
load_json_object
(filename)[source]¶ Load object stored in json file.
Note
Filename should include extension.
-
pymcmcstat.chain.ChainProcessing.
print_log_files
(savedir)[source]¶ Print log files to screen.
- Args:
- savedir (
str
): Directory where log files are saved.
- savedir (
The output display will include a date/time stamp, as well as indices of the chain that were saved during that export sequence.
Example display:
-------------------------- Display log file: <savedir>/binlogfile.txt 2018-05-03 14:15:54 0 999 2018-05-03 14:15:54 1000 1999 2018-05-03 14:15:55 2000 2999 2018-05-03 14:15:55 3000 3999 2018-05-03 14:15:55 4000 4999 --------------------------
-
pymcmcstat.chain.ChainProcessing.
read_in_bin_file
(filename)[source]¶ Read in information from file containing binary data.
If file exists, it will read in the array elements. Otherwise, it will return and empty list.
-
pymcmcstat.chain.ChainProcessing.
read_in_parallel_json_results_files
(parallel_dir)[source]¶ Read in json results files from directory containing results from parallel MCMC simulation.
- Args:
- parallel_dir (
str
): Directory where parallel log files are saved.
- parallel_dir (
-
pymcmcstat.chain.ChainProcessing.
read_in_parallel_savedir_files
(parallel_dir, extension='h5', chainfile='chainfile', sschainfile='sschainfile', s2chainfile='s2chainfile', covchainfile='covchainfile')[source]¶ Read in log files from directory containing results from parallel MCMC simulation.
-
pymcmcstat.chain.ChainProcessing.
read_in_savedir_files
(savedir, extension='h5', chainfile='chainfile', sschainfile='sschainfile', s2chainfile='s2chainfile', covchainfile='covchainfile')[source]¶ Read in log files from directory.
pymcmcstat.chain.ChainStatistics module¶
Created on Thu Apr 26 10:23:51 2018
@author: prmiles
-
pymcmcstat.chain.ChainStatistics.
batch_mean_standard_deviation
(chain, b=None)[source]¶ Standard deviation calculated from batch means
-
pymcmcstat.chain.ChainStatistics.
calculate_psrf
(x, nsimu, nchains)[source]¶ Calculate Potential Scale Reduction Factor (PSRF)
Performs analysis of variances for set of chains corresponding to a single parameter. This code follows the MATLAB implementation found here:
-
pymcmcstat.chain.ChainStatistics.
chainstats
(chain=None, results=None, returnstats=False)[source]¶ Calculate chain statistics.
-
pymcmcstat.chain.ChainStatistics.
display_gelman_rubin
(psrf)[source]¶ Display results of Gelman-Rubin diagnostic
- Args:
- psrf (
dict
): Results from GR diagnostic
- psrf (
-
pymcmcstat.chain.ChainStatistics.
gelman_rubin
(chains, names=None, results=None, display=True)[source]¶ Gelman-Rubin diagnostic for multiple chains [GR+92], [BG98].
This diagnostic technique compares the variance within a single change to the variance between multiple chains. This process serves as a method for testing whether or not the chain has converged. If the chain has converged, we would expect the variance within and the variance between to be equal. This diagnostic tool pairs well with the ParallelMCMC module, which generates a set of distinct chains that have all been initialized at different points within the parameter space.
- Args:
- Returns:
- (
dict
): Keywords of the dictionary correspond to the parameter names. Each keyword corresponds to a dictionary outputted fromcalculate_psrf()
.
- (
-
pymcmcstat.chain.ChainStatistics.
get_parameter_names
(nparam, results)[source]¶ Get parameter names from results dictionary.
If no results found, then default names are generated. If some results are found, then an extended set is generated to complete the list requirement. Uses the functions:
generate_default_names()
andextend_names_to_match_nparam()
-
pymcmcstat.chain.ChainStatistics.
geweke
(chain, a=0.1, b=0.5)[source]¶ Geweke’s MCMC convergence diagnostic
Test for equality of the means of the first a% (default 10%) and last b% (50%) of a Markov chain - see [BR98].
- Args:
- Returns:
Note
The percentage of the chain should be given as a decimal between zero and one. So, for the first 10% of the chain, define
a = 0.1
. Likewise, for the last 50% of the chain, defineb = 0.5
.
-
pymcmcstat.chain.ChainStatistics.
integrated_autocorrelation_time
(chain)[source]¶ Estimates the integrated autocorrelation time using Sokal’s adaptive truncated periodogram estimator.
-
pymcmcstat.chain.ChainStatistics.
power_spectral_density_using_hanning_window
(x, nfft=None, nw=None)[source]¶ Power spectral density using Hanning window.
-
pymcmcstat.chain.ChainStatistics.
print_chain_statistics
(names, meanii, stdii, mcerr, tau, p)[source]¶ Print chain statistics to terminal window.
- Args:
Example display:
--------------------- name : mean std MC_err tau geweke $p_{0}$ : 1.9680 0.0319 0.0013 36.3279 0.9979 $p_{1}$ : 3.0818 0.0803 0.0035 37.1669 0.9961 ---------------------