Пример #1
0
def rectifier(mean, var):
    """Return the mean and variance of a Gaussian distributed random variable,
    described by its mean and variacne, after passing it through a rectified
    linear unit.

    Parameters
    ----------

    mean : Theano variable
        Theano variable of the shape ``s``.

    var : Theano variable
        Theano variable of the shape ``s``.

    Returns
    -------

    mean_ : Theano variable
        Theano variable of the shape ``r``.

    var_ : Theano variable
        Theano variable of the shape ``r``.
    """
    std = T.sqrt(var)
    ratio = mean / (std + epsilon)

    mean_ = normal.cdf(ratio) * mean + normal.pdf(ratio) * std

    A = mean * std * normal.pdf(ratio)
    B = (mean ** 2 + std ** 2) * normal.cdf(ratio)
    exp_of_squared = A + B

    var_ = exp_of_squared - mean_ ** 2

    return mean_, var_
Пример #2
0
def rectifier(mean, var):
    std = T.sqrt(var)
    ratio = mean / (std + epsilon)

    mean_ = normal.cdf(ratio) * mean + normal.pdf(ratio) * std

    A = mean * std * normal.pdf(ratio)
    B = (mean ** 2 + std ** 2) * normal.cdf(ratio)
    exp_of_squared = A + B

    var_ = exp_of_squared - mean_ ** 2
    return mean_, var_