'Create an input dependent diagonal Gaussian distribution.
Args:
x: The input tensor from which the mean and variance are computed,
via a linear transformation of x.  I.e.
mu = Wx + b, log(var) = Mx + c
z_size: The size of the distribution.
name:  The name to prefix to learned variables.
var_min (optional): Minimal variance allowed.  This is an additional
way to control the amount of information getting through the stochastic
layer.'

def __init__(self, x_bxu, z_size, name, var_min=0.0):

    size_bxn = tf.stack([tf.shape(x_bxu)[0], z_size])
    self.mean_bxn = mean_bxn = linear(x_bxu, z_size, name=(name + '/mean'))
    logvar_bxn = linear(x_bxu, z_size, name=(name + '/logvar'))
    if (var_min > 0.0):
        logvar_bxn = tf.log((tf.exp(logvar_bxn) + var_min))
    self.logvar_bxn = logvar_bxn
    self.noise_bxn = noise_bxn = tf.random_normal(size_bxn)
    self.noise_bxn.set_shape([None, z_size])
    self.sample_bxn = (mean_bxn + (tf.exp((0.5 * logvar_bxn)) * noise_bxn))
