return s_1_t, s_2_t, s_3_t, theta_b_t, theta_c_t, theta_sig_t, v_t ((s_1_t, s_2_t, s_3_t, theta_b_t, theta_c_t, theta_sig_t, v_t), updates) = theano.scan(fn=inner_fn, sequences=[x], outputs_info=[s_1_0, s_2_0, s_3_0, None, None, None, None]) for k, v in updates.iteritems(): k.default_update = v lstm_1_tm1 = s_1_t[-1] lstm_2_tm1 = s_2_t[-1] lstm_3_tm1 = s_3_t[-1] theta_b_in = theta_b_t.reshape((x_shape[0]*x_shape[1], -1)) theta_c_in = theta_c_t.reshape((x_shape[0]*x_shape[1], -1)) theta_sig_in = theta_sig.fprop() v_in = v_t.reshape((x_shape[0]*x_shape[1], -1)) W = grbm.params['W_x__grbm'] free_energy = grbm_free_energy(x_in, W, [theta_b_in, theta_c_in, theta_sig_in]) -\ grbm_free_energy(v_in, W, [theta_b_in, theta_c_in, theta_sig_in]) free_energy = free_energy.mean() free_energy.name = 'grbm_free_energy' recon_err = T.sqr(x_in - v_in).mean() recon_err.name = 'reconstruction_error' max_x = x.max() mean_x = x.mean() min_x = x.min() max_x.name = 'max_x' mean_x.name = 'mean_x'
marginal_ll = [] for i in xrange(num_sample): z_is = prior.fprop([phi_mu_t, phi_sig_t]) theta_emb_t = theta_emb.fprop([dec_t]) theta_mu_t = theta_mu.fprop([theta_emb_t]) theta_sig_t = theta_sig.fprop([theta_emb_t]) coeff_t = coeff.fprop([theta_emb_t]) w = Gaussian(z_is, prior_mu_t, prior_sig_t) -\ Gaussian(z_is, phi_mu_t, phi_sig_t) marginal_ll.append(GMM(x_t, theta_mu_t, theta_sig_t, coeff_t) + w) marginal_ll = T.concatenate(marginal_ll, axis=0).mean() return enc_t, dec_t, pec_t, kl_t, theta_mu_t, coeff_t, marginal_ll prior_sig_t = prior_sig.fprop() phi_sig_t = phi_sig.fprop() theta_sig_t = theta_sig.fprop() ((enc_t, dec_t, pec_t, kl_t, theta_mu_t, coeff_t, marginal_ll), updates) =\ theano.scan(fn=inner_fn, sequences=[x, x2], outputs_info=[encoder.get_init_state(), decoder.get_init_state(), pecoder.get_init_state(), None, None, None, None], non_sequences=[phi_sig_t, prior_sig_t, theta_sig_t]) for k, v in updates.iteritems(): k.default_update = v reshaped_x = x.reshape((x.shape[0]*x.shape[1], -1)) reshaped_theta_mu = theta_mu_t.reshape((theta_mu_t.shape[0]*theta_mu_t.shape[1], -1))