本文整理汇总了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
示例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
示例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)
示例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)
示例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)
示例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)
示例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)
示例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))
示例9: _erfc_cpu
# 需要导入模块: import math [as 别名]
# 或者: from math import erfc [as 别名]
def _erfc_cpu(x, dtype):
return numpy.vectorize(math.erfc, otypes=[dtype])(x)
示例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)
示例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)
示例12: label
# 需要导入模块: import math [as 别名]
# 或者: from math import erfc [as 别名]
def label(self):
return 'erfc'
示例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),
示例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]
示例15: normcdf
# 需要导入模块: import math [as 别名]
# 或者: from math import erfc [as 别名]
def normcdf(n):
return 0.5 * math.erfc(-n * math.sqrt(0.5))