本文整理匯總了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
示例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
示例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)
示例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
示例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
示例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))
示例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)
示例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.)
示例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))))
示例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)
示例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())))
示例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!')
示例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)
示例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)]
示例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)