I am running the below, it works for a very small dataset, but when I increase it, the initial evaluation results fail. I have tried different initialization, it works once every ten attempts.
import numpy as np
import theano.tensor as tt
import pymc3 as pm
# simulated data
np.random.seed(20090425)
n = 10
p = 50
k = 10
t = 200
lamb = np.diag(np.random.normal(10,.2,size=(k)))
W = np.random.normal(.1,.5,size=(p,k))
beta = 0.1
y = np.zeros((n,t,p))
for i in range(n):
for T in range(t):
z = np.random.multivariate_normal(np.zeros(k), lamb)
y[i,T,:] = np.squeeze(np.random.multivariate_normal(np.matmul(W,z),np.eye(p)))
def beta_spike_slab(shape,spike):
inclusion_prop = 0.7
beta_spike = pm.Normal('beta_spike', 0, spike, shape=shape)
beta_slab = pm.Normal('beta_slab', 10, shape=shape)
gamma = pm.Bernoulli('gamma', inclusion_prop, shape=shape)
beta_spike_slab = pm.Deterministic('beta_spike_slab',(beta_spike * (1-gamma)) + ((beta_slab * gamma)))
return beta_spike_slab
with pm.Model() as model:
beta = pm.HalfCauchy("beta", 4)
alpha = pm.HalfCauchy("alpha", 4)
W_t = beta_spike_slab((k,p),0.1)
A = pm.MvNormal("A",mu = np.zeros(k) , cov= np.eye(k), shape =(n,k) )
A = A*(A>0)
Ad = pm.Deterministic('Ad', A * alpha)
for i in range(n):
z = pm.MvNormal("Z"+str(i), mu = np.zeros(k), cov = np.eye(k), shape=(t,k))
zd = pm.Deterministic("Zd"+str(i), pm.math.dot(z,tt.diag(tt.squeeze(Ad[i,:]))))
obs = np.reshape(y[i,:,:],[p*t])
y_obs = pm.MatrixNormal("y_obs"+str(i), mu=(pm.math.dot(zd,W_t)),colcov=beta*np.eye(p),rowcov=np.eye(t),observed=obs.reshape(t, p),shape=(t,p))
with model:
tr = pm.sample(100, tune=100)
Almost every time Z has -inf in the results. Is there something wrong with the model formulation or the coding?