demo_trace

Demonstration of the BuTools trace package

Set the precision and import the necessary packages

In [1]:
%precision %g
%run "~/github/butools/Python/BuToolsInit.py"
Butools V2.0
Packages loaded: utils, mc, moments, reptrans, trace, ph, dph, map, dmap, fitting, mam, queues
Global variables: 
butools.verbose = False , butools.checkInput = True , butools.checkPrecision = 1e-12

Load the trace data from file

In [3]:
tr = np.loadtxt("../test/data/bctrace.iat")

Calculate the marginal moments $\mu_k$ from the trace data $x_i$ as $\mu_k=\frac{1}{N}\sum_{i=1}^N x_i$

In [4]:
MarginalMomentsFromTrace (tr, 5)
Out[4]:
[0.00314282, 4.1718e-05, 2.01042e-06, 1.81715e-07, 2.52881e-08]

Calculate the lag $k$ moments $\eta_{ij}$ from the trace data as $\eta_{ij}=\frac{1}{N}\sum_{i=1}^{N-k} x_i x_{i+k}$

In [5]:
LagkJointMomentsFromTrace (tr, 1, 5)
Out[5]:
array([[  1.00000000e+00,   3.14282641e-03],
       [  3.14281626e-03,   1.36067350e-05]])

Obtain the density function (pdf) of the trace

In [6]:
(x,y) = PdfFromTrace (tr, np.linspace(0, 0.2, 250))

Plot the body and the tail of the pdf

In [7]:
plt.figure(1, figsize=(12,4))
plt.subplot(121)
plt.plot(x,y)
plt.xlim(0,0.012)
plt.subplot(122)
plt.loglog(x,y)
plt.xlim(1e-3,2e-1)
Out[7]:
(0.001, 0.2)

Calculate the lag $k$ autocorrelation function of the trace as $r_k=\frac{1}{N-k}\frac{1}{\sigma^2}\sum_{i=1}^{N-k}(x_i-\mu_1)(x_{i+k}-\mu_1)$

In [8]:
acf = LagCorrelationsFromTrace (tr, 20000)

Plot the lag $k$ autocorrelation function on log scale

In [10]:
plt.figure(2, figsize=(12,4))
plt.subplot(121)
plt.plot(acf)
plt.xlim(1,10)
plt.subplot(122)
plt.loglog(acf)
plt.xlim(1,20000)
Out[10]:
(1, 20000)