Esempio n. 1
0
    def rwiener(self, tau, xmin=float('-inf'), xmax=float('inf'), \
                           pmin=0.0, pmax=1.0):
        """
        Generates random numbers corrsponding to a Wiener process (the 
        intergral of white noise (Langevin's function)), inverse variant. 
        The Wiener process is W(t+tau) - W (t) = N(0, sqrt(tau)) 
        where tau is the time increment and N(0, sqrt(tau)) is a  
        normally distributed random variable having zero mean and 
        sqrt(tau) as its standard deviation.
        
        This method returns W(t+tau) - W(t) given tau and allows 
        tau to be negative.
        """

        self._checkminmax(xmin, xmax, pmin, pmax, 'rwiener')

        mu    = 0.0
        sigma = sqrt(abs(tau))   # abs(tau) is used

        pmn = pmin
        pmx = pmax
        if xmin > float('-inf'): pmn = max(pmin, cnormal(mu, sigma, xmin))
        if xmax < float('inf'):  pmx = min(pmax, cnormal(mu, sigma, xmax))

        p  =  pmn + (pmx-pmn)*self.runif01()
        w  =  inormal(p, mu, sigma)

        return w
Esempio n. 2
0
    def rnormal(self, mu, sigma, xmin=float('-inf'), xmax=float('inf'), \
                                 pmin=0.0, pmax=1.0):
        """
        Generator of normally distributed random variates using an inverse 
        method, claimed to give a maximum relative error less than 2.6e-9 
        (cf. statlib.invcdf.inormal for details). 
        """

        self._checkminmax(xmin, xmax, pmin, pmax, 'rnormal')

        pmn = pmin
        pmx = pmax
        if xmin > float('-inf'): pmn = max(pmin, cnormal(mu, sigma, xmin))
        if xmax < float('inf'):  pmx = min(pmax, cnormal(mu, sigma, xmax))

        p  =  pmn + (pmx-pmn)*self.runif01()
        x  =  inormal(p, mu, sigma)

        return x
Esempio n. 3
0
    def rlognormal(self, mulg, sigmalg, xmax=float('inf'), pmax=1.0):
        """
        Generator of lognormally distributed random variates, inverse variant.
        The log10-converted form is assumed for mulg and sigmalg: 
        mulg is the mean of the log10 (and the log10 of the median) of 
        the random variate, NOT the log10 of the mean of the non-logged 
        variate!, and sigmalg is the standard deviation of the log10 of 
        the random variate, NOT the log10 of the standard deviation of 
        the non-logged variate!!
        
        sigmalg > 0.0
        """

        assert xmax >= 0.0, "xmax must be a non-negative float in rlognormal!"
        # sigmalg is checked in rnormal
        self._checkpmax(pmax, 'rlognormal')

        if xmax < float('inf'): \
                   pmx = min(pmax, pow(10.0, cnormal(mulg, sigmalg, xmax)))
        pmn = 0.0
        x    = pow(10.0, self.rnormal(mulg, sigmalg, pmn, pmx))

        return x