See the example below. I have generated some data and made a few observations from two variables missing at random. The expected behavior was for pymc3 to automatically impute these values. Instead I get " ValueError: array must not contain infs or NaNs." What is my problem here?
import pandas as pd
import numpy as np
import numpy.ma as ma
import pymc3 as pm
import theano.tensor as tt
from scipy.stats import matrix_normal
import random
true_phi = np.random.normal(size=200)
true_phi = np.reshape(true_phi, (100, 2))
true_lambda = np.array([[1, 1, 1, 1, 1, 1, 1],[0, 1, 1, 1, 1, 1, 1]])
true_mu = np.dot(true_phi, true_lambda)
my_Y = matrix_normal.rvs(mean=true_mu, rowcov=np.identity(100), colcov=np.identity(7))
my_Y.shape
Y1 = my_Y[:,0]
Y0 = my_Y[:,range(1, 7)]
miss1 = [random.randint(0, 99) for i in range(30)]
Y0[miss1, 2] = float("NaN")
Y0 = ma.masked_array(Y0)
miss0 = [random.randint(0, 99) for i in range(30)]
Y1[miss0] = float("NaN")
Y1 = ma.masked_array(Y1)
with pm.Model() as my_model:
L0 = pm.Normal('Lambda', 0, sd=2, shape=(2, 6))
l = pm.HalfNormal("l", sigma=1)
phi = pm.Normal('phi', 0, sd=1, shape=(Y1.shape[0], 2))
sig = pm.HalfNormal('sig', sigma=1, shape=6)
sig1 = pm.HalfNormal('sig1', sigma=1)
mu0 = pm.Deterministic('mu', pm.math.dot(phi, L0))
mu1 = phi[:,0]*l
y0_obs = pm.MvNormal('y0_obs', mu=mu0, cov=np.identity(6)*sig, observed=Y0)
y1_obs = pm.Normal('y1_obs', mu=mu1, sd=sig1, observed=Y1)
trace = pm.sample(draws=1000, tune=500, target_accept=.95)