当前位置: 首页>>代码示例>>Python>>正文


Python math._exp函数代码示例

本文整理汇总了Python中math._exp函数的典型用法代码示例。如果您正苦于以下问题:Python _exp函数的具体用法?Python _exp怎么用?Python _exp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了_exp函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _softMax

 def _softMax(self,Y):
     """ softmax function used on outputs"""
     y = []
     sumExpY = 0.0
     for i in Y:
         sumExpY = sumExpY + _exp(i)
     for i in Y:
         t = _exp(i)/sumExpY
         y.append(t)
     return y
开发者ID:DerekParks,项目名称:ML1050,代码行数:10,代码来源:TanhNeuralNetwork.py

示例2: gammavariate

    def gammavariate(self, alpha, beta):
        """Gamma distribution.  Not the gamma function!
        
        Conditions on the parameters are alpha > 0 and beta > 0.
        
        The probability distribution function is:
        
                    x ** (alpha - 1) * math.exp(-x / beta)
          pdf(x) =  --------------------------------------
                      math.gamma(alpha) * beta ** alpha
        
        """
        if alpha <= 0.0 or beta <= 0.0:
            raise ValueError, "gammavariate: alpha and beta must be > 0.0"
        random = self.random
        if alpha > 1.0:
            ainv = _sqrt(2.0 * alpha - 1.0)
            bbb = alpha - LOG4
            ccc = alpha + ainv
            while 1:
                u1 = random()
                if not 1e-07 < u1 < 0.9999999:
                    continue
                u2 = 1.0 - random()
                v = _log(u1 / (1.0 - u1)) / ainv
                x = alpha * _exp(v)
                z = u1 * u1 * u2
                r = bbb + ccc * v - x
                if r + SG_MAGICCONST - 4.5 * z >= 0.0 or r >= _log(z):
                    return x * beta

        else:
            if alpha == 1.0:
                u = random()
                while u <= 1e-07:
                    u = random()

                return -_log(u) * beta
            while 1:
                u = random()
                b = (_e + alpha) / _e
                p = b * u
                if p <= 1.0:
                    x = p ** (1.0 / alpha)
                else:
                    x = -_log((b - p) / alpha)
                u1 = random()
                if p > 1.0:
                    if u1 <= x ** (alpha - 1.0):
                        break
                elif u1 <= _exp(-x):
                    break

            return x * beta
开发者ID:webiumsk,项目名称:WOT-0.9.12,代码行数:54,代码来源:random.py

示例3: stdgamma

    def stdgamma(self, alpha, ainv, bbb, ccc):
        # ainv = sqrt(2 * alpha - 1)
        # bbb = alpha - log(4)
        # ccc = alpha + ainv

        random = self.random
        if alpha <= 0.0:
            raise ValueError, 'stdgamma: alpha must be > 0.0'

        if alpha > 1.0:

            # Uses R.C.H. Cheng, "The generation of Gamma
            # variables with non-integral shape parameters",
            # Applied Statistics, (1977), 26, No. 1, p71-74

            while 1:
                u1 = random()
                u2 = random()
                v = _log(u1/(1.0-u1))/ainv
                x = alpha*_exp(v)
                z = u1*u1*u2
                r = bbb+ccc*v-x
                if r + SG_MAGICCONST - 4.5*z >= 0.0 or r >= _log(z):
                    return x

        elif alpha == 1.0:
            # expovariate(1)
            u = random()
            while u <= 1e-7:
                u = random()
            return -_log(u)

        else:   # alpha is between 0 and 1 (exclusive)

            # Uses ALGORITHM GS of Statistical Computing - Kennedy & Gentle

            while 1:
                u = random()
                b = (_e + alpha)/_e
                p = b*u
                if p <= 1.0:
                    x = pow(p, 1.0/alpha)
                else:
                    # p > 1
                    x = -_log((b-p)/alpha)
                u1 = random()
                if not (((p <= 1.0) and (u1 > _exp(-x))) or
                          ((p > 1)  and  (u1 > pow(x, alpha - 1.0)))):
                    break
            return x
开发者ID:AngusGeek,项目名称:org.aspectj,代码行数:50,代码来源:random.py

示例4: _calculate_weights

    def _calculate_weights(self, this_samples, N):
        """Calculate and save the weights of a run."""

        this_weights = self.weights.append(N)[:,0]

        if self.target_values is None:
            for i in range(N):
                tmp = self.target(this_samples[i]) - self.proposal.evaluate(this_samples[i])
                this_weights[i] = _exp(tmp)
        else:
            this_target_values = self.target_values.append(N)
            for i in range(N):
                this_target_values[i] = self.target(this_samples[i])
                tmp = this_target_values[i] - self.proposal.evaluate(this_samples[i])
                this_weights[i] = _exp(tmp)
开发者ID:fredRos,项目名称:pypmc,代码行数:15,代码来源:importance_sampling.py

示例5: _myExp

def _myExp(x):
	if x < 0.00000001:
		return 0
	elif x > 500:
		return 1e200
	else:
		return _exp(x)		
开发者ID:DerekParks,项目名称:ML1050,代码行数:7,代码来源:NeuralNetwork.py

示例6: _sigmoid

def _sigmoid(x):
	if x < -50:
		return 0.
	elif x > 20:
		return 1.
	else:
		return 1./(1.+_exp(-1*x))
开发者ID:DerekParks,项目名称:ML1050,代码行数:7,代码来源:NeuralNetwork.py

示例7: vonmisesvariate

 def vonmisesvariate(self, mu, kappa):
     random = self.random
     if kappa <= 9.9999999999999995e-007:
         return TWOPI * random()
     
     a = 1.0 + _sqrt(1.0 + 4.0 * kappa * kappa)
     b = (a - _sqrt(2.0 * a)) / 2.0 * kappa
     r = (1.0 + b * b) / 2.0 * b
     while 1:
         u1 = random()
         z = _cos(_pi * u1)
         f = (1.0 + r * z) / (r + z)
         c = kappa * (r - f)
         u2 = random()
         if u2 >= c * (2.0 - c):
             pass
         if not (u2 > c * _exp(1.0 - c)):
             break
         
     u3 = random()
     if u3 > 0.5:
         theta = mu % TWOPI + _acos(f)
     else:
         theta = mu % TWOPI - _acos(f)
     return theta
开发者ID:Toonerz,项目名称:Toontown-2003,代码行数:25,代码来源:random.py

示例8: vonmisesvariate

    def vonmisesvariate(self, mu, kappa):
        """Circular data distribution.
        
        mu is the mean angle, expressed in radians between 0 and 2*pi, and
        kappa is the concentration parameter, which must be greater than or
        equal to zero.  If kappa is equal to zero, this distribution reduces
        to a uniform random angle over the range 0 to 2*pi.
        
        """
        random = self.random
        if kappa <= 1e-06:
            return TWOPI * random()
        a = 1.0 + _sqrt(1.0 + 4.0 * kappa * kappa)
        b = (a - _sqrt(2.0 * a)) / (2.0 * kappa)
        r = (1.0 + b * b) / (2.0 * b)
        while 1:
            u1 = random()
            z = _cos(_pi * u1)
            f = (1.0 + r * z) / (r + z)
            c = kappa * (r - f)
            u2 = random()
            if u2 < c * (2.0 - c) or u2 <= c * _exp(1.0 - c):
                break

        u3 = random()
        if u3 > 0.5:
            theta = mu % TWOPI + _acos(f)
        else:
            theta = mu % TWOPI - _acos(f)
        return theta
开发者ID:AkiSyndicat,项目名称:AbletonLive9_RemoteScripts,代码行数:30,代码来源:random.py

示例9: vonmisesvariate

    def vonmisesvariate(self, mu, kappa):
        """Circular data distribution.
        
        mu is the mean angle, expressed in radians between 0 and 2*pi, and
        kappa is the concentration parameter, which must be greater than or
        equal to zero.  If kappa is equal to zero, this distribution reduces
        to a uniform random angle over the range 0 to 2*pi.
        
        """
        random = self.random
        if kappa <= 1e-06:
            return TWOPI * random()
        s = 0.5 / kappa
        r = s + _sqrt(1.0 + s * s)
        while 1:
            u1 = random()
            z = _cos(_pi * u1)
            d = z / (r + z)
            u2 = random()
            if u2 < 1.0 - d * d or u2 <= (1.0 - d) * _exp(d):
                break

        q = 1.0 / r
        f = (q + z) / (1.0 + q * z)
        u3 = random()
        if u3 > 0.5:
            theta = (mu + _acos(f)) % TWOPI
        else:
            theta = (mu - _acos(f)) % TWOPI
        return theta
开发者ID:webiumsk,项目名称:WOT-0.9.12,代码行数:30,代码来源:random.py

示例10: lognormvariate

 def lognormvariate(self, mu, sigma):
     # """Log normal distribution.
     # If you take the natural logarithm of this distribution, you'll get a
     # normal distribution with mean mu and standard deviation sigma.
     # mu can have any value, and sigma must be greater than zero.
     # """
     return _exp(self.normalvariate(mu, sigma))
开发者ID:Afey,项目名称:pyjs,代码行数:7,代码来源:random.py

示例11: gammavariate

    def gammavariate(self, alpha, beta):
        if alpha <= 0.0 or beta <= 0.0:
            raise ValueError('gammavariate: alpha and beta must be > 0.0')
        random = self.random
        if alpha > 1.0:
            ainv = _sqrt(2.0*alpha - 1.0)
            bbb = alpha - LOG4
            ccc = alpha + ainv
            u1 = random()
            if not 1e-07 < u1 < 0.9999999:
                continue
            u2 = 1.0 - random()
            v = _log(u1/(1.0 - u1))/ainv
            x = alpha*_exp(v)
            z = u1*u1*u2
            r = bbb + ccc*v - x
            #ERROR: Unexpected statement:   517 BINARY_MULTIPLY  |   518 RETURN_VALUE 

            if r + SG_MAGICCONST - 4.5*z >= 0.0 or r >= _log(z):
                return x*beta
                continue
        else:
            if alpha == 1.0:
                u = random()
                while u <= 1e-07:
                    u = random()
                return -_log(u)*beta
            while True:
                u = random()
                b = (_e + alpha)/_e
                p = b*u
                if p <= 1.0:
                    x = p**(1.0/alpha)
                else:
                    x = -_log((b - p)/alpha)
                u1 = random()
                if p > 1.0:
                    if u1 <= x**(alpha - 1.0):
                        break
                        continue
                        if u1 <= _exp(-x):
                            break
                elif u1 <= _exp(-x):
                    break
            return x*beta
开发者ID:johndpope,项目名称:sims4-ai-engine,代码行数:45,代码来源:random.py

示例12: gammavariate

    def gammavariate(self, alpha, beta):
        if alpha <= 0.0 or beta <= 0.0:
            raise ValueError, 'gammavariate: alpha and beta must be > 0.0'
        random = self.random
        if alpha > 1.0:
            ainv = _sqrt(2.0 * alpha - 1.0)
            bbb = alpha - LOG4
            ccc = alpha + ainv
            while 1:
                u1 = random()
                if not 1e-07 < u1 < 0.9999999:
                    continue
                u2 = 1.0 - random()
                v = _log(u1 / (1.0 - u1)) / ainv
                x = alpha * _exp(v)
                z = u1 * u1 * u2
                r = bbb + ccc * v - x
                if r + SG_MAGICCONST - 4.5 * z >= 0.0 or r >= _log(z):
                    return x * beta

        else:
            if alpha == 1.0:
                u = random()
                while u <= 1e-07:
                    u = random()

                return -_log(u) * beta
            while 1:
                u = random()
                b = (_e + alpha) / _e
                p = b * u
                if p <= 1.0:
                    x = p ** (1.0 / alpha)
                else:
                    x = -_log((b - p) / alpha)
                u1 = random()
                if p > 1.0:
                    if u1 <= x ** (alpha - 1.0):
                        break
                elif u1 <= _exp(-x):
                    break

            return x * beta
开发者ID:connoryang,项目名称:dec-eve-serenity,代码行数:43,代码来源:random.py

示例13: exp

def exp(S):
    """Convenience function for exponentiating PowerSeries.
    
    This can also replace the ``math.exp`` function, extending it to
    take a PowerSeries as an argument.
    """
    from math import exp as _exp
    if isinstance(S, PowerSeries):
        return S.exponential()
    return _exp(S)
开发者ID:pdonis,项目名称:powerseries,代码行数:10,代码来源:powerseries.py

示例14: gammavariate

 def gammavariate(self, alpha, beta):
     if alpha <= 0.0 or beta <= 0.0:
         raise ValueError, 'gammavariate: alpha and beta must be > 0.0'
     
     random = self.random
     if alpha > 1.0:
         ainv = _sqrt(2.0 * alpha - 1.0)
         bbb = alpha - LOG4
         ccc = alpha + ainv
         while 1:
             u1 = random()
             u2 = random()
             v = _log(u1 / (1.0 - u1)) / ainv
             x = alpha * _exp(v)
             z = u1 * u1 * u2
             r = bbb + ccc * v - x
             if r + SG_MAGICCONST - 4.5 * z >= 0.0 or r >= _log(z):
                 return x * beta
             
     elif alpha == 1.0:
         u = random()
         while u <= 9.9999999999999995e-008:
             u = random()
         return -_log(u) * beta
     else:
         while 1:
             u = random()
             b = (_e + alpha) / _e
             p = b * u
             if p <= 1.0:
                 x = pow(p, 1.0 / alpha)
             else:
                 x = -_log((b - p) / alpha)
             u1 = random()
             if p <= 1.0 and u1 > _exp(-x) and p > 1:
                 pass
             if not (u1 > pow(x, alpha - 1.0)):
                 break
             
         return x * beta
开发者ID:Toonerz,项目名称:Toontown-2003,代码行数:40,代码来源:random.py

示例15: _sigmoid

def _sigmoid(x):
    """Sigmoid function
    
    >>> _sigmoid(0)
    0.5
    >>> _sigmoid(1)
    0.7310585786300049
    >>> _sigmoid(-1)
    0.2689414213699951
    """
    e=0
    try:
        e = _exp(-1*x)
    except OverflowError:
        return 0
    return 1./(1.+e)
开发者ID:DerekParks,项目名称:ML1050,代码行数:16,代码来源:NeuralNetwork.py


注:本文中的math._exp函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。