Package: erroranalysis-py
Error AnalysisGenerate error bars and perform binning analysis using jackknife or bootstrap resampling. This package calculates the average and error in quantum Monte Carlo data (or other data) and on functions of averages (such as fluctuations, skew, and kurtosis). This package has been put together followingPeter Young's excellet data analysis guideand theAmbegaokar and Troyer dogs and fleas (Estimating errors reliably in Monte Carlo simulations) paper.InstallationYou can install Error Analysis fromPyPI:pip install erroranalysis-pyHow to useSomeexample datais provided from ourdimensional reduction of superfluid heliumproject. Specifically the data provied is for argon confined to the nanopores of the mesoporous silica MCM-41 from grand canonical Monte Carlo molecular simulations using theCassandra molecular simulation software.Command line methods have been included for convenience. Average, fluctuations, skew, and kurtosis can be plotted as a function of Monte Carlo step (or average bin) with errorbars. Binning analysis can also be performed. For the full set of options seepython -m erroranalysis --helporea --helpFor example, the following command generates plots for theNmols_2estimator (average number of particles):ea --skip_header 1 --estimator Nmols_2 --savefig argon_MCM41_-12.68.png examples/argon_MCM41_-12.68.out.prpNote that Error Analysis will attempt to read the headers for each column of data in the data files provided and the estimator of interest should be specified from the header. In the example, the header for the data is on the second line so--skip_header 1is specified to skip the first line of the data file before attempting to read the header. A custom header can be provided if the header is missing on the datafiles and multiple data files are supported as well. Here several options are shown off:ea --skip 5000 --bin_size 5 --skip_header 1 --custom_header "estimator_1,estimator_2,estimator_3,estimator_4,estimator_5" --estimator estimator_4 --pretty_estimator_name "N_\mathrm{Ar}" --savefig two_files_at_once.png --labels "file_1,file_2" --legend examples/argon_MCM41_-12.68.out.prp examples/argon_MCM41_-13.34.out.prpBinning analysis can be performed by adding the--binning_analysisflag:ea --skip 15000 --skip_header 1 --estimator Nmols_2 --binning_analysis --savefig argon_MCM41_-12.68.png examples/argon_MCM41_-12.68.out.prpAverage
autocorrelation time: 29.3695548682474
convergence factor: 1.6227794947682683

Fluctuations
autocorrelation time: 57.78295684564631
convergence factor: 1.0302306748178092

Skew
autocorrelation time: 55.363864907469626
convergence factor: 0.9741542111868422

Kurtosis
autocorrelation time: -0.07655265212193901
convergence factor: 1.6641092137649522Advanced usageMore advanced usage of the Error Analysis package can be achieved by importing the pacakge directly into your project or notebook environment usingimport erroranalysis as ea. Some advanced usage cases are discussed below.CompressibilityThe compressibility may be a measure of interest and can be calculated bywhereis the average particle density. Notice the compressibility is a function of averages. Jackknife or bootstrap resampling of the data may give a better measure of the error in the compressibility. Start with the compressibility as a function:defcompressibility(N,N2,volume=1.0,k_B=1.0,T=1.0):pf=volume/(k_B*T)returnpf*(((N2-(N**2)))/(N**2))Then use Error Analysis to calculate the average compressibility and errorimporterroranalysisaseaimportnumpyasnpfromscipy.constantsimportkask_bskip=6000# Skip some measurements# Values specific to the argon in MCM-41 GCMC simulationsbox_volume=139357.3925#\AA^3volume=box_volume*((1e-10)**3)temperature=87.35#K# Load the GCMC datafn="examples/argon_MCM41_-12.68.out.prp"_data=np.genfromtxt(fn,names=True,skip_header=1)#Calculate average compressibility and error using jackknife methodκ_avg,κ_err=ea.jackknife_on_function(compressibility,_data["Nmols_2"][skip:],_data["Nmols_2"][skip:]**2,volume=volume,k_B=k_b,T=temperature)print("κ_avg ={:.5e}".format(κ_avg))print("κ_err ={:.5e}".format(κ_err))κ_avg = 1.65368e-07
κ_err = 1.53513e-09Notice we pass thecompressibility()function as the first argument to thejackknife_on_function()and then the arguments tocompressibility()(including keyword arguments). Bootstrap sampling can similarly be performed usingbootstrap_on_function(). These methods are used when generating the fluctuations, skew, and kurtosis.Additional usageThe functionsjackknife(),bootstrap(),jackknife_on_function(), andboostrap_on_function()operate on array-like data. See the documentation to discover more creative usage!