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


Python math.erfc方法代碼示例

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


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

示例1: compute_kullback_leibler_check_statistic

# 需要導入模塊: import math [as 別名]
# 或者: from math import erfc [as 別名]
def compute_kullback_leibler_check_statistic(n=100, prngstate=None):
    """Compute the lowest of the survival function and the CDF of the exact KL
    divergence KL(N(mu1,s1)||N(mu2,s2)) w.r.t. the sample distribution of the
    KL divergence drawn by computing log(P(x|N(mu1,s1)))-log(P(x|N(mu2,s2)))
    over a sample x~N(mu1,s1). If we are computing the KL divergence
    accurately, the exact value should fall squarely in the sample, and the
    tail probabilities should be relatively large.

    """
    if prngstate is None:
        raise TypeError('Must explicitly specify numpy.random.RandomState')
    mu1 = mu2 = 0
    s1 = 1
    s2 = 2
    exact = gaussian_kl_divergence(mu1, s1, mu2, s2)
    sample = prngstate.normal(mu1, s1, n)
    lpdf1 = gaussian_log_pdf(mu1, s1)
    lpdf2 = gaussian_log_pdf(mu2, s2)
    estimate, std = kl.kullback_leibler(sample, lpdf1, lpdf2)
    # This computes the minimum of the left and right tail probabilities of the
    # exact KL divergence vs a gaussian fit to the sample estimate. There is a
    # distinct negative skew to the samples used to compute `estimate`, so this
    # statistic is not uniform. Nonetheless, we do not expect it to get too
    # small.
    return erfc(abs(exact - estimate) / std) / 2 
開發者ID:probcomp,項目名稱:bayeslite,代碼行數:27,代碼來源:test_kl.py

示例2: ndtr

# 需要導入模塊: import math [as 別名]
# 或者: from math import erfc [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

示例3: runs_test

# 需要導入模塊: import math [as 別名]
# 或者: from math import erfc [as 別名]
def runs_test(bits):
    n = len(bits)
    zeroes,ones = count_ones_zeroes(bits)

    prop = float(ones)/float(n)
    print("  prop ",prop)

    tau = 2.0/math.sqrt(n)
    print("  tau ",tau)

    if abs(prop-0.5) > tau:
        return (False,0.0,None)

    vobs = 1.0
    for i in range(n-1):
        if bits[i] != bits[i+1]:
            vobs += 1.0

    print("  vobs ",vobs)
      
    p = math.erfc(abs(vobs - (2.0*n*prop*(1.0-prop)))/(2.0*math.sqrt(2.0*n)*prop*(1-prop) ))
    success = (p >= 0.01)
    return (success,p,None) 
開發者ID:dj-on-github,項目名稱:sp800_22_tests,代碼行數:25,代碼來源:sp800_22_runs_test.py

示例4: get_quantiles

# 需要導入模塊: import math [as 別名]
# 或者: from math import erfc [as 別名]
def get_quantiles(acquisition_par, fmin, m, s):
    '''
    Quantiles of the Gaussian distribution useful to determine the acquisition function values
    :param acquisition_par: parameter of the acquisition function
    :param fmin: current minimum.
    :param m: vector of means.
    :param s: vector of standard deviations.
    '''
    if isinstance(s, np.ndarray):
        s[s<1e-10] = 1e-10
    elif s< 1e-10:
        s = 1e-10
    u = (fmin - m - acquisition_par)/s

    phi = np.exp(-0.5 * u**2) / np.sqrt(2*np.pi)
    # vectorized version of erfc to not depend on scipy
    Phi = 0.5 * erfc(-u / np.sqrt(2))
    return (phi, Phi, u) 
開發者ID:awslabs,項目名稱:autogluon,代碼行數:20,代碼來源:density.py

示例5: __call__

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

示例6: test_erf_erfc

# 需要導入模塊: import math [as 別名]
# 或者: from math import erfc [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

示例7: __call__

# 需要導入模塊: import math [as 別名]
# 或者: from math import erfc [as 別名]
def __call__(self, val):
        return __inline_fora(
            """fun(@unnamed_args:(val), *args) {
                   PyFloat(math.erfc(val.@m))
                   }"""
            )(val) 
開發者ID:ufora,項目名稱:ufora,代碼行數:8,代碼來源:pure_math.py

示例8: test_pure_python_math_module

# 需要導入模塊: import math [as 別名]
# 或者: from math import erfc [as 別名]
def test_pure_python_math_module(self):
        vals = [1, -.5, 1.5, 0, 0.0, -2, -2.2, .2]

        # not being tested: math.asinh, math.atanh, math.lgamma, math.erfc, math.acos
        def f():
            functions = [
                math.sqrt, math.cos, math.sin, math.tan, math.asin, math.atan,
                math.acosh, math.cosh, math.sinh, math.tanh, math.ceil,
                math.erf, math.exp, math.expm1, math.factorial, math.floor,
                math.log, math.log10, math.log1p
            ]
            tr = []
            for idx1 in range(len(vals)):
                v1 = vals[idx1]
                for funIdx in range(len(functions)):
                    function = functions[funIdx]
                    try:
                        tr = tr + [function(v1)]
                    except ValueError as ex:
                        pass

            return tr

        r1 = self.evaluateWithExecutor(f)
        r2 = f()
        self.assertGreater(len(r1), 100)
        self.assertTrue(numpy.allclose(r1, r2, 1e-6)) 
開發者ID:ufora,項目名稱:ufora,代碼行數:29,代碼來源:MathTestCases.py

示例9: _erfc_cpu

# 需要導入模塊: import math [as 別名]
# 或者: from math import erfc [as 別名]
def _erfc_cpu(x, dtype):
    return numpy.vectorize(math.erfc, otypes=[dtype])(x) 
開發者ID:chainer,項目名稱:chainer,代碼行數:4,代碼來源:test_erfc.py

示例10: _ndtr_cpu

# 需要導入模塊: import math [as 別名]
# 或者: from math import erfc [as 別名]
def _ndtr_cpu(x, dtype):
    erfc = numpy.vectorize(
        lambda x: 0.5 * math.erfc(-x / 2 ** 0.5))
    return utils.force_array(erfc(x), dtype=dtype) 
開發者ID:chainer,項目名稱:chainer,代碼行數:6,代碼來源:test_ndtr.py

示例11: _slow_ndtr_cpu

# 需要導入模塊: import math [as 別名]
# 或者: from math import erfc [as 別名]
def _slow_ndtr_cpu(x):
    return 0.5 * math.erfc(-x / 2 ** 0.5) 
開發者ID:chainer,項目名稱:chainer,代碼行數:4,代碼來源:ndtr.py

示例12: label

# 需要導入模塊: import math [as 別名]
# 或者: from math import erfc [as 別名]
def label(self):
        return 'erfc' 
開發者ID:chainer,項目名稱:chainer,代碼行數:4,代碼來源:erfc.py

示例13: forward_cpu

# 需要導入模塊: import math [as 別名]
# 或者: from math import erfc [as 別名]
def forward_cpu(self, x):
        global _erfc_cpu
        if _erfc_cpu is None:
            try:
                from scipy import special
                _erfc_cpu = special.erfc
            except ImportError:
                warnings.warn(
                    'SciPy is not available. Forward computation of erfc in'
                    ' CPU can be slow without SciPy.',
                    chainer.warnings.PerformanceWarning)
                _erfc_cpu = numpy.vectorize(math.erfc)
        self.retain_inputs((0,))
        return utils.force_array(_erfc_cpu(x[0]), dtype=x[0].dtype), 
開發者ID:chainer,項目名稱:chainer,代碼行數:16,代碼來源:erfc.py

示例14: erfc

# 需要導入模塊: import math [as 別名]
# 或者: from math import erfc [as 別名]
def erfc(x):
    """Elementwise complementary error function.

    .. note::
       Forward computation in CPU can be slow if
       `SciPy <https://www.scipy.org/>`_ is not available.

    Args:
        x (:class:`~chainer.Variable` or :ref:`ndarray`): Input variable.

    Returns:
        ~chainer.Variable: Output variable.
    """
    return Erfc().apply((x,))[0] 
開發者ID:chainer,項目名稱:chainer,代碼行數:16,代碼來源:erfc.py

示例15: normcdf

# 需要導入模塊: import math [as 別名]
# 或者: from math import erfc [as 別名]
def normcdf(n):
    return 0.5 * math.erfc(-n * math.sqrt(0.5)) 
開發者ID:dj-on-github,項目名稱:sp800_22_tests,代碼行數:4,代碼來源:sp800_22_cumulative_sums_test.py


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