def check(dist): q_s = Gamma(a_s, b_s) q_v = Gamma(a_v, b_v) sess = tf.InteractiveSession() init = tf.global_variables_initializer() init.run() no_sample = 100 s_sample = q_s.sample(no_sample).eval() v_sample = q_v.sample(no_sample).eval() n = np.zeros([C_u, C_i]) result = np.zeros([C_u, C_i]) n_expected = np.zeros([C_u, C_i]) for i in range(0, no_sample): n = np.add(n, np.matmul(s_sample[i], np.transpose(v_sample[i]))) n_expected = n / no_sample #mean of poisson is rate param. So this is fine. #sample response #distribution specific result = dist_mean(dist, n_expected) return mae(result)
def _test(alpha, beta, n): x = Gamma(alpha=alpha, beta=beta) val_est = get_dims(x.sample(n)) val_true = n + get_dims(alpha) assert val_est == val_true
# predictive check n_rep = 100 # number of replicated datasets we generate holdout_gen = np.zeros((n_rep, x_train.shape[0], x_train.shape[1])) for i in range(n_rep): x_generated = x_post.sample().eval() # look only at the heldout entries holdout_gen[i] = np.multiply(x_generated, holdout_mask) n_eval = 10 # we draw samples from the inferred Z and W obs_ll = [] rep_ll = [] pbar = Progbar(n_eval) for j in range(1, n_eval + 1): z1_sample = z1_post.sample().eval() W0_sample = qW0.sample().eval() holdoutmean_sample = np.multiply(z1_sample.dot(W0_sample), holdout_mask) obs_ll.append( np.mean(np.ma.masked_invalid( stats.poisson.logpmf(np.array(x_vad, dtype=int), holdoutmean_sample)), axis=1)) rep_ll.append( np.mean(np.ma.masked_invalid( stats.poisson.logpmf(holdout_gen, holdoutmean_sample)), axis=2)) pbar.update(j)