Beispiel #1
0
def generate_x_given_z(z,
                       hidden_dim,
                       latent_dim,
                       is_training,
                       batch_norm,
                       batch_size,
                       input_dim,
                       keep_prob=1,
                       reuse=False):
    # Generative p(x|z)
    size = len(hidden_dim)
    with tf.variable_scope("decoder", reuse=reuse):
        noise = uniform(dim=latent_dim, batch_size=batch_size)
        z_plus_noise = tf.concat([z, noise], axis=1)
        layer_input = hidden_mlp_layers(batch_norm=batch_norm,
                                        hidden_dim=hidden_dim,
                                        is_training=is_training,
                                        keep_prob=keep_prob,
                                        layer_input=z_plus_noise,
                                        size=size)

        w_x, b_x = create_nn_weights('x', 'decoder',
                                     [hidden_dim[size - 1], input_dim])
        # Model
        # Reconstruction layer
        x = mlp_neuron(layer_input, w_x, b_x, activation=False)
        return x
Beispiel #2
0
def pt_given_x(x, hidden_dim, is_training, batch_norm, batch_size, input_dim, noise_alpha, keep_prob=0.9, reuse=False):
    size = len(hidden_dim)
    with tf.variable_scope('generate_t_given_x', reuse=reuse):
        # Variables
        noise = uniform(dim=input_dim, batch_size=batch_size) * tf.gather(noise_alpha, 0)
        x_plus_noise = tf.concat([x, noise], axis=1)
        hidden_x = hidden_mlp_layers_noise(batch_norm=batch_norm, hidden_dim=hidden_dim,
                                           is_training=is_training, keep_prob=keep_prob,
                                           layer_input=x_plus_noise, size=size, batch_size=batch_size,
                                           noise_alpha=noise_alpha)

        w_t, b_t = create_nn_weights('t', 'encoder', [hidden_x.get_shape().as_list()[1], 1])
        t_mu = mlp_neuron(hidden_x, w_t, b_t, activation=False)
        return tf.exp(t_mu)
Beispiel #3
0
def sample_z(batch_norm, batch_size, hidden_dim, input_dim, is_training,
             keep_prob, latent_dim, size, x):
    noise = uniform(dim=input_dim, batch_size=batch_size)
    x_plus_noise = tf.concat([x, noise], axis=1)
    layer_input = hidden_mlp_layers(batch_norm=batch_norm,
                                    hidden_dim=hidden_dim,
                                    is_training=is_training,
                                    keep_prob=keep_prob,
                                    layer_input=x_plus_noise,
                                    size=size)
    w_z, b_z = create_nn_weights('z', 'encoder',
                                 [hidden_dim[size - 1], latent_dim])
    z = mlp_neuron(layer_input, w_z, b_z, activation=False)
    return z
Beispiel #4
0
def discriminator(pair_one, pair_two, hidden_dim, is_training, batch_norm, scope, keep_prob=1, reuse=False):
    size = len(hidden_dim)
    with tf.variable_scope(scope, reuse=reuse):
        # Variables
        print("scope:{}, pair_one:{}, pair_two:{}".format(scope, pair_one.shape, pair_two.shape))
        hidden_pair_one = hidden_mlp_layers(batch_norm=batch_norm, hidden_dim=hidden_dim,
                                            is_training=is_training, keep_prob=keep_prob,
                                            layer_input=pair_one, size=size)

        hidden_pair_two = hidden_mlp_layers(batch_norm=batch_norm, hidden_dim=hidden_dim,
                                            is_training=is_training, keep_prob=keep_prob,
                                            layer_input=pair_two, size=size)
        hidden_pairs = tf.concat([hidden_pair_one, hidden_pair_two], axis=1)
        print("hidden_pairs:{}".format(hidden_pairs.get_shape()))
        w_logit, b_logit = create_nn_weights('logits', 'discriminator', [hidden_dim[size - 1] * 2, 1])
        f = mlp_neuron(layer_input=hidden_pairs, weights=w_logit, biases=b_logit, activation=False)
        logit = tf.nn.sigmoid(f)

        return tf.squeeze(logit), tf.squeeze(f)