import tensorflow as tf

            x = tf.matmul(x, tf.nn.l2_normalize(V.initialized_value(), 0))

            init_scale = .01
            m_init, v_init = tf.nn.moments(x, [0])
            scale_init = init_scale / tf.sqrt(v_init + 1e-10)
            with tf.control_dependencies([g.assign(g * scale_init), b.assign_add(-m_init * scale_init)]):
                x = tf.reshape(scale_init, [1, num_units]) * (x - tf.reshape(m_init, [1, num_units]))

        else:
            V = maybe_avg(V)
            g = maybe_avg(g)
            b = maybe_avg(b)

            x = tf.matmul(x, V)
            scaler = g / tf.sqrt(tf.reduce_sum(tf.square(V), [0]))
            x = tf.reshape(scaler, [1, num_units]) * x + tf.reshape(b, [1, num_units])


        return x


def sample_from_discretized_mix_logistic(l, nr_mix):
    """
    This function is copied from https://github.com/openai/pixel-cnn/blob/master/pixel_cnn_pp/nn.py in reference to:
    See [Salimans et. al., 2017](https://arxiv.org/pdf/1701.05517)
    ([pdf](https://arxiv.org/pdf/1701.05517.pdf))

    log-likelihood for mixture of discretized logistics, assumes the data has been rescaled to [-1,1] interval
