在Python中使用明显简单的MCMC代码会导致大量内存使用(> 15GB),即使我使用pickle后端。每当我在pymc中使用观察变量数组时就会发生这种情况。对于为什么会发生这种情况的任何想法?
import pymc as pymc
import numpy as np
N = 17
numC = 5
A = np.zeros([N,N])
A[0:numC, :] = 1
A[:, 0:numC] = 1
C = pymc.Beta('C', alpha=0.5, beta=0.5, size=N)
@pymc.deterministic(dtype=float)
def q(_C=C):
Q = np.zeros([N,N])
for i in range(0,N-1):
for j in range(i+1, N):
Q[i, j] = Q[j, i] = C[i] + C[j] - C[i]*C[j]
return Q
obs = []
for i in range(0,N-1):
for j in range(i+1, N):
o = pymc.Bernoulli('A%d%d'%(i,j), p=q[i,j], value=A[i,j], observed=True)
obs.append(o)
model = pymc.Model([C, q] + obs)
mcmc = pymc.MCMC(model, db='pickle', dbname='abc.pickle')
mcmc.sample(10000, burn=5000, thin=5)
mcmc.db.close()
答案 0 :(得分:0)