[1]:
import pyobs
import numpy
[2]:
# generate autocorrelated data
N=500 # number of configs
# central values
mu=[0.5, 1.2, -3.4, 60.2, -10.1, 5.01]
# diagonal cov matrix
cov=[(mu[i]*0.05)**2 for i in range(len(mu))]
# autocorrelation time
tau=4.0
rng = pyobs.random.generator('tutorial')
data = rng.markov_chain(mu,cov,tau,N)
data = numpy.reshape(data,numpy.size(data),)
yobs = pyobs.observable()
yobs.create('ensA',data,shape=(3,2))
Random generator initialized with seed = 649309182 [tutorial]
In jupyter notebooks we can also print an observable in a pretty format by typing it at the end of a cell.
[3]:
yobs
[3]:
0.484(23) 1.118(95)
-4.06(13) 61.3(2.8)
-10.40(30) 5.25(26)
We slice our test observable in various ways. We select rows, columns and specific sub-matrices
[4]:
print('first row: ', yobs[0,:])
print('second column: ', yobs[:,1])
first row: 0.484(23) 1.118(95)
second column: 1.118(95)
61.3(2.8)
5.25(26)
[5]:
idx = numpy.array([0,1])
print('upper 2x2 matrix \n',yobs[idx,:])
idx = numpy.array([1,2])
print('lower 2x2 matrix \n',yobs[idx,:])
idx = numpy.array([0,2])
print('third 2x2 matrix \n',yobs[idx,:])
upper 2x2 matrix
0.484(23) 1.118(95)
-4.06(13) 61.3(2.8)
lower 2x2 matrix
-4.06(13) 61.3(2.8)
-10.40(30) 5.25(26)
third 2x2 matrix
0.484(23) 1.118(95)
-10.40(30) 5.25(26)
Observables can also be reshaped and transposed, like normal numpy
arrays
[6]:
print('transpose \n',pyobs.transpose(yobs))
print('reshape \n',pyobs.reshape(yobs,(6,)))
transpose
0.484(23) -4.06(13) -10.40(30)
1.118(95) 61.3(2.8) 5.25(26)
reshape
0.484(23) 1.118(95) -4.06(13) 61.3(2.8) -10.40(30) 5.25(26)
[7]:
print('diag of upper 2x2 matrix \n',pyobs.diag(yobs[numpy.array([0,1]),:]))
diag of upper 2x2 matrix
0.484(23) 61.3(2.8)