• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python math._exp函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: 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.

        """
        # mu:    mean angle (in radians between 0 and 2*pi)
        # kappa: concentration parameter kappa (>= 0)
        # if kappa = 0 generate uniform random angle

        # Based upon an algorithm published in: Fisher, N.I.,
        # "Statistical Analysis of Circular Data", Cambridge
        # University Press, 1993.

        # Thanks to Magnus Kessler for a correction to the
        # implementation of step 4.

        random = self.random
        if kappa <= 1e-6:
            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 not (u2 >= c * (2.0 - c) and 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:zhoupan,项目名称:OpenModelSphereMirror,代码行数:47,代码来源:random.py


示例17: 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.

        """
        # mu:    mean angle (in radians between 0 and 2*pi)
        # kappa: concentration parameter kappa (>= 0)
        # if kappa = 0 generate uniform random angle

        # Based upon an algorithm published in: Fisher, N.I.,
        # "Statistical Analysis of Circular Data", Cambridge
        # University Press, 1993.

        # Thanks to Magnus Kessler for a correction to the
        # implementation of step 4.

        random = self.random
        if kappa <= 1e-6:
            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:zegab,项目名称:diane,代码行数:45,代码来源:random.py


示例18: _propagateInputClassification

    def _propagateInputClassification(self,input):
        """Same as _propagateInput; but applies softMax
        """
        Y,Z = self._propagateInputRegression(input)
            
        #apply softmax function
        try:
        
            expY = [_exp(y) for y in Y]
          
        #if the exp of the outputs starts getting too big just normalize the outputs
        except OverflowError: 
            expY = Y
        sumExpY = sum(expY)
 
        Y = [y/sumExpY for y in Y]
        
        return Y,Z
开发者ID:DerekParks,项目名称:ML1050,代码行数:18,代码来源:NeuralNetwork.py


示例19: integer_nthroot

def integer_nthroot(y, n):
    """
    Return a tuple containing x = floor(y**(1/n))
    and a boolean indicating whether the result is exact (that is,
    whether x**n == y).

    >>> integer_nthroot(16,2)
    (4, True)
    >>> integer_nthroot(26,2)
    (5, False)
    """
    if y < 0:
        raise ValueError("y must not be negative")
    if n < 1:
        raise ValueError("n must be positive")
    if y in (0, 1):
        return y, True
    if n == 1:
        return y, True
    if n > y:
        return 1, False
    # Get initial estimate for Newton's method. Care must be taken to
    # avoid overflow
    try:
        guess = int(y ** (1.0 / n) + 0.5)
    except OverflowError:
        try:
            guess = int(_exp(_log(y) / n) + 0.5)
        except OverflowError:
            guess = 1 << int(_log(y, 2) / n)
    # Newton iteration
    xprev, x = -1, guess
    while abs(x - xprev) > 1:
        t = x ** (n - 1)
        xprev, x = x, x - (t * x - y) // (n * t)
    # Compensate
    t = x ** n
    while t > y:
        x -= 1
        t = x ** n
    return x, t == y
开发者ID:rkern,项目名称:sympy-rkern,代码行数:41,代码来源:power.py


示例20: vonmisesvariate

 def vonmisesvariate(self, mu, kappa):
     random = self.random
     if kappa <= 1e-06:
         return TWOPI*random()
     s = 0.5/kappa
     r = s + _sqrt(1.0 + s*s)
     while True:
         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:johndpope,项目名称:sims4-ai-engine,代码行数:21,代码来源:random.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python math._log函数代码示例发布时间:2022-05-27
下一篇:
Python math._cos函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap