Ejemplo n.º 1
0
try:
    from numpy import *
    from matplotlib.pyplot import *
except ImportError:
    print("Need numpy and matplotlib to test PyUQTk")

try:
    import PyUQTk.array as uqtkarray
    import PyUQTk.quad as uqtkquad
    import PyUQTk.pce as uqtkpce
except ImportError:
    print("PyUQTk array and quad module not found")

# get quad points and weights
x = uqtkarray.dblArray2D()
w = uqtkarray.dblArray1D()

print('Create an instance of Quad class')
ndim = 2
level = 8
q = uqtkquad.Quad('LU', 'full', ndim, level)
print('Now set and get the quadrature rule...')
q.SetRule()
q.GetRule(x, w)

# print out x and w
print('Displaying the quadrature points and weights:\n')
print(x)
print(w)
n = len(x)
Ejemplo n.º 2
0
try:
    from numpy import *
    from matplotlib.pyplot import *
except ImportError:
    "Need numpy and matplotlib to test PyUQTk"

try:
    import PyUQTk.array as uqtkarray
    import PyUQTk.quad as uqtkquad
    import PyUQTk.pce as uqtkpce
except ImportError:
    print "PyUQTk array and quad module not found"

# get quad points and weights
x = uqtkarray.dblArray2D()
w = uqtkarray.dblArray1D()

print 'Create an instance of Quad class'
ndim = 1
level = 8
q = uqtkquad.Quad('LU', 'full', ndim, level)
print 'Now set and get the quadrature rule...'
q.SetRule()
q.GetRule(x, w)

# print out x and w
print 'Displaying the quadrature points and weights:\n'
# print x
# print w
n = len(x)
Ejemplo n.º 3
0
dim = 2
mchain.setChainDim(dim)
mchain.initMethod("am")
g = uqtkarray.dblArray1D(dim, .1)
mchain.initChainPropCovDiag(g)
nCalls = L * M
thin2 = thin1 * L
mchain.setWriteFlag(0)
mchain.setOutputInfo("txt", "chain.dat", M, nCalls)
mchain.runChain(nCalls, xstart)
mchain.getSamples()
samples = mchain.samples
samples2 = zeros((dim, nCalls))
samples.getnpdblArray(samples2)
samples2 = samples2.T
propcov = uqtkarray.dblArray2D(2, 2, 0)
mchain.getChainPropCov(propcov)
m1 = propcov[0, 0]
m2 = propcov[1, 1]

# ax2.contour(qx,qy,qz,250,alpha=.4)
# ax2.plot(samples2[L*nburn::thin2,0],samples2[L*nburn::thin2,1],'*g',alpha=.1)

# plot mixing of samples
ax3.plot(samples1[nburn::thin1, 0], 'k', alpha=.4)
ax3.plot(samples2[L * nburn::thin2, 0], 'g', alpha=.4)
ax4.plot(samples1[nburn::thin1, 1], 'k', alpha=.4)
ax4.plot(samples2[L * nburn::thin2, 1], 'g', alpha=.4)

print 'acor using HMCMC', acor(samples1[nburn::thin1, 0])
print 'acor using MCMC', acor(samples2[L * nburn::thin2, 0])