for label in labels: image = x_train[label] x_dim, y_dim = image.shape pixel_values = np.concatenate(image) # grey scale between 0 and 1 N, wmat, amat = create_matrices(x_dim, y_dim) with pm.Model() as model: beta0 = pm.Normal('beta0', mu=0., tau=1e-2) tau = pm.Gamma('tau_c', alpha=1.0, beta=1.0) mu_phi = CAR2('mu_phi', w=wmat, a=amat, tau=tau, shape=N) phi = pm.Deterministic('phi', mu_phi - tt.mean(mu_phi)) # zero-center phi mu = pm.Deterministic('mu', beta0 + phi) Yi = pm.LogitNormal('Yi', mu=mu, observed=pad(pixel_values)) max_a_post = pm.find_MAP() step = pm.NUTS() trace = pm.sample(draws=N_SAMPLES, step=step, start=max_a_post, cores=2, tune=N_TUNE, chains=N_CHAINS) posterior_pred = pm.sample_posterior_predictive(trace) prefix_file_name = 'mnist_digit{}(label{})_'.format(i, label) np.save( new_name(name=prefix_file_name + 'phi_values',
def pymc3(self, name="theta"): '''PyMC3 implementation of distribution''' return pymc3.LogitNormal(name, mu=self.m, sd=self.s)