136 KiB
import sys
sys.path.append('..')
import numpy as np
import matplotlib.pyplot as plt
import pyerrors as pe
Primary observables¶
We can load data from preprocessed pickle files which contain a list of pyerror
Obs
:
p_obs_names = ['f_A', 'f_P']
p_obs = {}
for i, item in enumerate(p_obs_names):
p_obs[item] = pe.load_object('./data/B1k2_' + item + '.p')
We can now use the pyerrors
function plot_corrs
to have a quick look at the data we just read in
pe.plot_corrs([p_obs['f_A'], p_obs['f_P']], label=p_obs_names)
Secondary observables¶
One way of generating secondary observables is to write the desired math operations as for standard floats. pyerrors
currently supports the basic arithmetic operations as well as numpy's basic trigonometric functions.
We start by looking at the unimproved pcac mass $am=\tilde{\partial}_0 f_\mathrm{A}/2 f_\mathrm{P}$
uimpr_mass = []
for i in range(1, len(p_obs['f_A']) - 1):
uimpr_mass.append((p_obs['f_A'][i + 1] - p_obs['f_A'][i - 1]) / 2 / (2 * p_obs['f_P'][i]))
For more complicated secondary obsevables or secondary obsevables we use over and over again it is often useful to define a dedicated function for it. Here is an example for the improved pcac mass
def pcac_mass(data, **kwargs):
if 'ca' in kwargs:
ca = kwargs.get('ca')
else:
ca = 0
return ((data[1] - data[0]) / 2. + ca * (data[2] - 2 * data[3] + data[4])) / 2. / data[3]
Now we can construct the derived observable pcac_mass
from the primary ones. Note the additional key word argument ca
with which we can provide a value for the $\mathrm{O}(a)$ improvement coefficient of the axial vector current.
impr_mass = []
for i in range(1, len(p_obs['f_A']) - 1):
impr_mass.append(pcac_mass([p_obs['f_A'][i - 1], p_obs['f_A'][i + 1], p_obs['f_P'][i - 1],
p_obs['f_P'][i], p_obs['f_P'][i + 1]], ca=-0.03888694628624465))
To calculate the error of an observable we use the gamma_method
. Let us have a look at the docstring
?pe.Obs.gamma_method
We can apply the gamma_method
to the pcac mass on every time slice for both the unimproved and the improved mass.
masses = [uimpr_mass, impr_mass]
for i, item in enumerate(masses):
[o.gamma_method() for o in item]
We can now have a look at the result by plotting the two lists of Obs
pe.plot_corrs([impr_mass, uimpr_mass], xrange=[0.5, 18.5], label=['Improved pcac mass', 'Unimproved pcac mass'])
Tertiary observables¶
We can now construct a plateau as (tertiary) derived observable from the masses. At this point the distinction between primary and secondary observables becomes blurred. We can again and again resample objects into new observables which allows us to modulize the analysis. Note that np.mean
and similar functions can be applied to the Obs
as if they were real numbers.
pcac_plateau = np.mean(impr_mass[6:15])
pcac_plateau.gamma_method()
pcac_plateau.print()
We can also use a weighted average with given plateau_range
(passed to the function as kwarg)
def weighted_plateau(data, **kwargs):
if 'plateau_range' in kwargs:
plateau_range = kwargs.get('plateau_range')
else:
raise Exception('No range given.')
num = 0
den = 0
for i in range(plateau_range[0], plateau_range[1]):
if data[i].dvalue == 0.0:
raise Exception('Run gamma_method for input first')
num += 1 / data[i].dvalue * data[i]
den += 1 / data[i].dvalue
return num / den
w_pcac_plateau = weighted_plateau(impr_mass, plateau_range=[6, 15])
w_pcac_plateau.gamma_method()
w_pcac_plateau.print()
In this case the two variants of the plateau are almost identical
We can now plot the data with the two plateaus
pe.plot_corrs([impr_mass, uimpr_mass], plateau=[pcac_plateau, w_pcac_plateau], xrange=[0.5, 18.5],
label=['Improved pcac mass', 'Unimproved pcac mass'])
Refined error analysis¶
There are two way of adjusting the value of S. One can either change the class variable Obs.S_global
. The set value is then used for all following applications of the gamma_method
.
pe.Obs.S_global = 3.0
pcac_plateau.gamma_method()
pcac_plateau.print()
Alternatively one can call the gamma_method with the keyword argument S. This value overwrites the global value only for the current application of the gamma_method
.
pcac_plateau.gamma_method(S=2.5)
pcac_plateau.print()
We can have a look at the respective normalized autocorrelation function (rho) and the integrated autocorrelation time
pcac_plateau.plot_rho()
pcac_plateau.plot_tauint()
Critical slowing down¶
pyerrors
also supports the critical slowing down analysis of arXiv:1009.5228
pcac_plateau.gamma_method(tau_exp=10, N_sigma=1)
pcac_plateau.print()
The attached tail, which takes into account long range autocorrelations, is shown in the plots for rho and tauint
pcac_plateau.plot_rho()
pcac_plateau.plot_tauint()
Additional information on the ensembles and replicas can be printed with print level 2 (In this case there is only one ensemble with one replicum.)
pcac_plateau.print(2)
The Monte Carlo history of the observable can be accessed with plot_history
to identify possible outliers or have a look at the shape of the distribution
pcac_plateau.plot_history()
If everything is satisfactory, dump the Obs
in a pickle file for future use. The Obs
pcac_plateau
conatains all relevant information for any follow up analyses.
pcac_plateau.dump('B1k2_pcac_plateau')