tf.set_random_seed(1) # input and output placeholder x_ph_bin = tf.placeholder(tf.float32, [M, len(binfeats)], name='x_bin') # binary inputs x_ph_cont = tf.placeholder(tf.float32, [M, len(contfeats) + pnoise_size], name='x_cont') # continuous inputs t_ph = tf.placeholder(tf.float32, [M, 1]) y_ph = tf.placeholder(tf.float32, [M, 1]) x_ph = tf.concat([x_ph_bin, x_ph_cont], 1) activation = tf.nn.elu """Model Building""" # CEVAE model (decoder) # p(z) mu_z = tf.zeros([tf.shape(x_ph)[0], d]) sigma_z = tf.ones([tf.shape(x_ph)[0], d]) z = Normal(loc=mu_z, scale=sigma_z) # p(x|z) hx = fc_net(z, (nh - 1) * [h], [], 'px_z_shared', lamba=lamba, activation=activation) logits = fc_net(hx, [h], [[len(binfeats), None]], 'px_z_bin'.format(i + 1), lamba=lamba, activation=activation) x1 = Bernoulli(logits=logits, dtype=tf.float32, name='bernoulli_px_z') mu, sigma = fc_net(hx, [h], [[len(contfeats) + pnoise_size, None], [len(contfeats) + pnoise_size, tf.nn.softplus]], 'px_z_cont', lamba=lamba, activation=activation) x2 = Normal(loc=mu, scale=sigma, name='gaussian_px_z') # p(t|z) logits = fc_net(z, [h], [[1, None]], 'pt_z', lamba=lamba, activation=activation) t = Bernoulli(logits=logits, dtype=tf.float32) # p(y|t,z) mu2_t0 = fc_net(z, nh * [h], [[1, None]], 'py_t0z', lamba=lamba, activation=activation) mu2_t1 = fc_net(z, nh * [h], [[1, None]], 'py_t1z', lamba=lamba, activation=activation) if task != 'ihdp': y = BernoulliWithSigmoidProbs(logits=t * mu2_t1 + (1. - t) * mu2_t0, dtype=tf.float32) else: y = Normal(loc=t * mu2_t1 + (1. - t) * mu2_t0, scale=tf.ones_like(mu2_t0))
xj_ph_cont = tf.placeholder(tf.float32, [M, len(contfeats)], name='xj_cont') # continuous inputs tj_ph = tf.placeholder(tf.float32, [M, 1]) yj_ph = tf.placeholder(tf.float32, [M, 1]) xi_ph = tf.concat([xi_ph_bin, xi_ph_cont], 1) xj_ph = tf.concat([xj_ph_bin, xj_ph_cont], 1) activation = tf.nn.elu # CEVAE model (decoder) # p(z) zi = Normal(loc=tf.zeros([tf.shape(xi_ph)[0], d]), scale=tf.ones([tf.shape(xi_ph)[0], d])) zj = Normal(loc=tf.zeros([tf.shape(xj_ph)[0], d]), scale=tf.ones([tf.shape(xj_ph)[0], d])) # p(x|z) hxi = fc_net(zi, (nh - 1) * [h], [], 'px_z_shared', lamba=lamba, activation=activation) logitsxi = fc_net(hxi, [h], [[len(binfeats), None]], 'px_z_bin'.format(it + 1), lamba=lamba, activation=activation) xi1 = Bernoulli(logits=logitsxi, dtype=tf.float32, name='bernoulli_pxi_zi') mui, sigmai = fc_net(hxi, [h], [[len(contfeats), None], [len(contfeats), tf.nn.softplus]], 'px_z_cont', lamba=lamba, activation=activation) xi2 = Normal(loc=mui, scale=sigmai, name='gaussian_pxi_zi') hxj = fc_net(zj, (nh - 1) * [h], [], 'px_z_shared', lamba=lamba, activation=activation, reuse=True) logitsxj = fc_net(hxj, [h], [[len(binfeats), None]], 'px_z_bin'.format(it + 1), lamba=lamba, activation=activation, reuse=True) xj1 = Bernoulli(logits=logitsxj, dtype=tf.float32, name='bernoulli_pxj_zj') muj, sigmaj = fc_net(hxj, [h], [[len(contfeats), None], [len(contfeats), tf.nn.softplus]], 'px_z_cont', lamba=lamba, activation=activation, reuse=True) xj2 = Normal(loc=muj, scale=sigmaj, name='gaussian_pxj_zj')