import tensorflow as tf


    # Inverse of a softplus function, so that the value of the standard deviation
    # will be equal to what the user specifies, but we can still enforce positivity
    # by wrapping the standard deviation in the softplus function.
    # standard_dev = tf.log(tf.exp(standard_dev) - 1.0) * tf.ones(shape)

    # it's important to initialize variances with care, otherwise the model takes too long to converge
    sigma_min = 1-1/10
    sigma_max = 1+1/10

    rho_max_init = tf.log(tf.exp(sigma_max) - 1.0)
    rho_min_init = tf.log(tf.exp(sigma_min) - 1.0)
    std_init = tf.random_uniform_initializer(rho_min_init, rho_max_init)

    # Initialize the mean
    mean = tf.get_variable(name + "_mean", shape, dtype=dtype)

    # Initialize the standard deviation
    pre_sigma = tf.get_variable(name + "_standard_deviation",
                                         shape,
                                         initializer=std_init,
                                         dtype=dtype)

    standard_deviation = tf.nn.softplus(pre_sigma) + 1e-5

    # The famous reparametrization formula for the factorized Gaussian
    noise = tf.random_normal([num_samples] + shape, 0.0, 1.0, dtype)
    weights = mean + standard_deviation * noise

    return weights, mean, standard_deviation, pre_sigma, noise