當前位置: 首頁>>代碼示例>>Python>>正文


Python math.erf方法代碼示例

本文整理匯總了Python中math.erf方法的典型用法代碼示例。如果您正苦於以下問題:Python math.erf方法的具體用法?Python math.erf怎麽用?Python math.erf使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在math的用法示例。


在下文中一共展示了math.erf方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: ndtr

# 需要導入模塊: import math [as 別名]
# 或者: from math import erf [as 別名]
def ndtr(a):
    """
    Returns the area under the Gaussian probability density function,
    integrated from minus infinity to x.

    See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.ndtr.html#scipy.special.ndtr

    """
    sqrth = math.sqrt(2) / 2
    x = float(a) * sqrth
    z = abs(x)
    if z < sqrth:
        y = 0.5 + 0.5 * math.erf(x)
    else:
        y = 0.5 * math.erfc(z)
        if x > 0:
            y = 1 - y
    return y 
開發者ID:mozilla,項目名稱:python_moztelemetry,代碼行數:20,代碼來源:stats.py

示例2: expimp

# 需要導入模塊: import math [as 別名]
# 或者: from math import erf [as 別名]
def expimp(self, x):
        '''
        Returns the expected improvement at the design vector X in the model
        :param x: A real world coordinates design vector
        :return EI: The expected improvement value at the point x in the model
        '''
        S = self.predicterr_normalized(x)
        y_min = np.min(self.y)
        if S <= 0.:
            EI = 0.
        elif S > 0.:
            EI_one = ((y_min - self.predict_normalized(x)) * (0.5 + 0.5*m.erf((
                      1./np.sqrt(2.))*((y_min - self.predict_normalized(x)) /
                                       S))))
            EI_two = ((S * (1. / np.sqrt(2. * np.pi))) * (np.exp(-(1./2.) *
                      ((y_min - self.predict_normalized(x))**2. / S**2.))))
            EI = EI_one + EI_two
        return EI 
開發者ID:capaulson,項目名稱:pyKriging,代碼行數:20,代碼來源:regressionkrige.py

示例3: erf_local

# 需要導入模塊: import math [as 別名]
# 或者: from math import erf [as 別名]
def erf_local(x):
    # save the sign of x
    sign = 1 if x >= 0 else -1
    x = abs(x)

    # constants
    a1 =  0.254829592
    a2 = -0.284496736
    a3 =  1.421413741
    a4 = -1.453152027
    a5 =  1.061405429
    p  =  0.3275911

    # A&S formula 7.1.26
    t = 1.0/(1.0 + p*x)
    y = 1.0 - (((((a5*t + a4)*t) + a3)*t + a2)*t + a1)*t*math.exp(-x*x)
    return sign*y # erf(-x) = -erf(x) 
開發者ID:spectralpython,項目名稱:spectral,代碼行數:19,代碼來源:resampling.py

示例4: integral_gaussian

# 需要導入模塊: import math [as 別名]
# 或者: from math import erf [as 別名]
def integral_gaussian(a, b, mu, sigma):
    """
    Computes the integral of a gaussian centered
    in mu with a given sigma
    :param a:
    :param b:
    :param mu:
    :param sigma:
    :return:
    """

    # Integral from -\infty to a
    val_floor = 0.5 * (1 + math.erf((a - mu) / (sigma * math.sqrt(2.0))))

    # Integral from -\infty to b
    val_ceil = 0.5 * (1 + math.erf((b - mu) / (sigma * sqrt(2.0))))

    return val_ceil - val_floor 
開發者ID:MaterialsDiscovery,項目名稱:PyChemia,代碼行數:20,代碼來源:mathematics.py

示例5: erfinv

# 需要導入模塊: import math [as 別名]
# 或者: from math import erf [as 別名]
def erfinv(y):
    # courtesy of
    # https://github.com/antelopeusersgroup/antelope_contrib/blob/master/lib/location/libgenloc/erfinv.c#L15
    a = [0.886226899, -1.645349621, 0.914624893, -0.140543331]
    b = [-2.118377725, 1.442710462, -0.329097515, 0.012229801]
    c = [-1.970840454, -1.624906493, 3.429567803, 1.641345311]
    d = [3.543889200, 1.637067800]
    if y > 1:
        return None
    if y == 1:
        return math.copysign(1, y) * float("inf")
    if y <= 0.7:
        z = y * y
        num = (((a[3] * z + a[2]) * z + a[1]) * z + a[0])
        dem = ((((b[3] * z + b[2]) * z + b[1]) * z + b[0]) * z + 1.0)
        x = y * num / dem
    else:
        z = math.sqrt(-math.log((1.0 - abs(y)) / 2.0))
        num = ((c[3] * z + c[2]) * z + c[1]) * z + c[0]
        dem = (d[1] * z + d[0]) * z + 1.0
        x = (math.copysign(1.0, y)) * num / dem
    for _ in [1, 2]:
        x = x - (erf(x) - y) / ((2 / math.sqrt(trig.c_pi)) * math.exp(-x * x))
    return x 
開發者ID:TuringApp,項目名稱:Turing,代碼行數:26,代碼來源:stats.py

示例6: integral_default_gaussian

# 需要導入模塊: import math [as 別名]
# 或者: from math import erf [as 別名]
def integral_default_gaussian(y, x):
    """Calculate the value of the integral from x to y of the erf function

    Parameters
    ----------
    y : float
        upper limit
    x : float
        lower limit

    Returns
    -------
    float
        Calculated value of integral

    """
    return 0.5 * (math.erf(x) - math.erf(y)) 
開發者ID:SunPower,項目名稱:pvfactors,代碼行數:19,代碼來源:utils.py

示例7: sum_of_erf

# 需要導入模塊: import math [as 別名]
# 或者: from math import erf [as 別名]
def sum_of_erf(mu, sigma, N=1000):
    """
    Compute the sum of erf term

    :param mu: The Gaussian mean
    :param sigma: The Gaussian sigma
    :param N: The number of iterations in the sum
    """
    from math import sqrt, erf

    sum1 = 0
    sum2 = N * erf((N + 1 - mu) / (sqrt(2) * sigma))
    sum3 = N * erf((-N - mu) / (sqrt(2) * sigma))
    for i in range(-N, N):
        sum1 += erf((i + 1 - mu) / (sqrt(2) * sigma))
    return -0.5 * (sum1 + sum2 + sum3) 
開發者ID:dials,項目名稱:dials,代碼行數:18,代碼來源:generate_bias_lookup_table.py

示例8: __call__

# 需要導入模塊: import math [as 別名]
# 或者: from math import erf [as 別名]
def __call__(self, state, scope, pos, paramTypes, x):
        return unwrapForNorm(x, lambda y: (math.erf(y/math.sqrt(2.)) + 1.)/2.) 
開發者ID:modelop,項目名稱:hadrian,代碼行數:4,代碼來源:link.py

示例9: CDF

# 需要導入模塊: import math [as 別名]
# 或者: from math import erf [as 別名]
def CDF(self, x):
        if (self.sigma == 0.0) and (x < self.mu):
            return 0.0
        elif (self.sigma == 0.0) and (x >= self.mu):
            return 1.0
        else:
            return 0.5 * (1.0 + math.erf((x - self.mu)/(self.sigma * math.sqrt(2.0)))) 
開發者ID:modelop,項目名稱:hadrian,代碼行數:9,代碼來源:dist.py

示例10: __call__

# 需要導入模塊: import math [as 別名]
# 或者: from math import erf [as 別名]
def __call__(self, state, scope, pos, paramTypes, a):
        try:
            return math.erf(a)
        except:
            raise PFARuntimeException("domain error", self.errcodeBase + 0, self.name, pos) 
開發者ID:modelop,項目名稱:hadrian,代碼行數:7,代碼來源:spec.py

示例11: Erf

# 需要導入模塊: import math [as 別名]
# 或者: from math import erf [as 別名]
def Erf(self):
    return unary(self, 'erf(' + str(self._name_no_id()) + ')', (lambda x: math.erf(self.value()))) 
開發者ID:timkpaine,項目名稱:tributary,代碼行數:4,代碼來源:ops.py

示例12: __array_ufunc__

# 需要導入模塊: import math [as 別名]
# 或者: from math import erf [as 別名]
def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
    if ufunc == np.add:
        if isinstance(inputs[0], Node):
            return inputs[0].__add__(inputs[1])
        else:
            return inputs[1].__add__(inputs[0])
    elif ufunc == np.subtract:
        if isinstance(inputs[0], Node):
            return inputs[0].__sub__(inputs[1])
        else:
            return inputs[1].__sub__(inputs[0])
    elif ufunc == np.multiply:
        if isinstance(inputs[0], Node):
            return inputs[0].__mul__(inputs[1])
        else:
            return inputs[1].__mul__(inputs[0])
    elif ufunc == np.divide:
        if isinstance(inputs[0], Node):
            return inputs[0].__truediv__(inputs[1])
        else:
            return inputs[1].__truediv__(inputs[0])
    elif ufunc == np.sin:
        return inputs[0].sin()
    elif ufunc == np.cos:
        return inputs[0].cos()
    elif ufunc == np.tan:
        return inputs[0].tan()
    elif ufunc == np.arcsin:
        return inputs[0].asin()
    elif ufunc == np.arccos:
        return inputs[0].acos()
    elif ufunc == np.arctan:
        return inputs[0].atan()
    elif ufunc == np.exp:
        return inputs[0].exp()
    elif ufunc == sp.special.erf:
        return inputs[0].erf()
    raise NotImplementedError('Not Implemented!') 
開發者ID:timkpaine,項目名稱:tributary,代碼行數:40,代碼來源:ops.py

示例13: test_Erf

# 需要導入模塊: import math [as 別名]
# 或者: from math import erf [as 別名]
def test_Erf(self):
        t = tl.Node(value=2)
        out = tl.Erf(t)
        assert out() == math.erf(2) 
開發者ID:timkpaine,項目名稱:tributary,代碼行數:6,代碼來源:test_ops_lazy.py

示例14: test_Erf

# 需要導入模塊: import math [as 別名]
# 或者: from math import erf [as 別名]
def test_Erf(self):
        t = ts.Timer(foo, count=2)
        out = ts.Erf(t)
        assert ts.run(out) == [math.erf(1), math.erf(2)] 
開發者ID:timkpaine,項目名稱:tributary,代碼行數:6,代碼來源:test_ops_streaming.py

示例15: test_erf_erfc

# 需要導入模塊: import math [as 別名]
# 或者: from math import erf [as 別名]
def test_erf_erfc(self):
        tolerance = 15
        for x in itertools.count(0.0, 0.001):
            if x > 5.0:
                break
            self.assertAlmostEqual(math.erf(x), -math.erf(-x), places=tolerance)
            self.assertAlmostEqual(math.erfc(x), 2.0 - math.erfc(-x), places=tolerance)

            self.assertAlmostEqual(1.0 - math.erf(x), math.erfc(x), places=tolerance)
            self.assertAlmostEqual(1.0 - math.erf(-x), math.erfc(-x), places=tolerance)
            self.assertAlmostEqual(1.0 - math.erfc(x), math.erf(x), places=tolerance)
            self.assertAlmostEqual(1.0 - math.erfc(-x), math.erf(-x), places=tolerance) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:14,代碼來源:test_math.py


注:本文中的math.erf方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。