import tensorflow as tf

            U = tf.reshape(flat_logits, [-1, num_acts, self.k])

            # Calculate w
            cut_g = tf.stop_gradient(self.g)
            cut_g = tf.expand_dims(cut_g, [1])
            gstack = tf.concat([self.prev_g, cut_g], axis=1)

            self.last_c_g = gstack[:, 1:]
            # print self.last_c_g
            gsum = tf.reduce_sum(gstack, axis=1)
            phi = tf.get_variable("phi", (self.g_dim, self.k))
            w = tf.matmul(gsum, phi)
            w = tf.expand_dims(w, [2])
            # Calculate policy and sample
            logits = tf.reshape(tf.matmul(U, w), [-1, num_acts])
            self.pi = tf.nn.softmax(logits)
            self.log_pi = tf.nn.log_softmax(logits)
            self.sample = policy_utils.categorical_sample(
                tf.reshape(logits, [-1, num_acts]), num_acts)[0, :]

    def build_value(self, _input):
        with tf.variable_scope('VF'):
            hidden = tf.layers.dense(inputs=_input,
                                     units=self.vf_hidden_size,
                                     activation=tf.nn.elu)

            w = tf.get_variable("weights", (self.vf_hidden_size, 1))
            return tf.matmul(hidden, w)
