Exemplo n.º 1
0
def erf(x):
    """
    Approximation to the erf-function with fractional error
    everywhere less than 1.2e-7

    @param x: value
    @type  x: float

    @return: value
    @rtype: float
    """
    if x > 10.: return 1.
    if x < -10.: return -1.

    z = abs(x)
    t = 1. / (1. + 0.5 * z)

    r = t * N0.exp(-z * z - 1.26551223 + t * (1.00002368 + t * (0.37409196 + \
                                                               t * (0.09678418 + t * (-0.18628806 + t * (0.27886807 + t * \
                                                                                                         (-1.13520398 + t * (1.48851587 + t * (-0.82215223 + t * \
                                                                                                                                               0.17087277)))))))))

    if x >= 0.:
        return 1. - r
    else:
        return r - 1.
Exemplo n.º 2
0
def logMean( alpha, beta ):
    """
    @param alpha: mean of log-transformed distribution
    @type  alpha: float
    @param beta: standarddev of log-transformed distribution
    @type  beta: float

    @return: mean of the original lognormal distribution
    @rtype: float
    """
    return N0.exp( alpha + (beta**2)/2. )
Exemplo n.º 3
0
def logMedian( alpha, beta=None ):
    """
    @param alpha: mean of log-transformed distribution
    @type  alpha: float
    @param beta: not needed
    @type  beta: float

    @return: median of the original lognormal distribution
    @rtype: float
    """
    return N0.exp( alpha )
Exemplo n.º 4
0
def logSigma( alpha, beta ):
    """
    @param alpha: mean of log-transformed distribution
    @type  alpha: float
    @param beta: standarddev of log-transformed distribution
    @type  beta: float

    @return: 'standard deviation' of the original lognormal distribution
    @rtype: float
    """
    return logMean( alpha, beta ) * N0.sqrt( N0.exp(beta**2) - 1.)
Exemplo n.º 5
0
    def test_MatrixPlot(self):
        """MatrixPlot test"""
        n = 30

        z = N0.zeros((n, n), N0.Float)

        for i in range(N0.shape(z)[0]):
            for j in range(N0.shape(z)[1]):
                z[i, j] = N0.exp(-0.01 * ((i - n / 2)**2 + (j - n / 2)**2))

        self.p = MatrixPlot(z, palette='sausage', legend=1)

        if self.local or self.VERBOSITY > 2:
            self.p.show()

        self.assert_(self.p is not None)
Exemplo n.º 6
0
def logArea(x, alpha, beta):
    """
    Area of the smallest interval of a lognormal distribution that still
    includes x.

    @param x: border value
    @type  x: float
    @param alpha: mean of log-transformed distribution
    @type  alpha: float
    @param beta: standarddev of log-transformed distribution
    @type  beta: float

    @return: probability that x is NOT drawn from the given distribution
    @rtype: float
    """
    r_max = N0.exp(alpha - beta**2)

    if x < r_max: x = r_max**2 / x

    upper = (N0.log(x) - alpha) / beta 

    return 0.5 * (erf(upper / N0.sqrt(2)) - erf(-(upper + 2*beta) / N0.sqrt(2)))
Exemplo n.º 7
0
def ln(r, alpha, beta):
    return N0.exp(-0.5/beta**2 * (N0.log(r) - alpha)**2 \
                 - 0.5*N0.log(2*N0.pi)-N0.log(beta*r))
Exemplo n.º 8
0
def rand_log_normal(alpha, beta, shape):
    return N0.exp(R.normal(alpha, beta, shape))