本文整理汇总了Python中mpmath.gammainc方法的典型用法代码示例。如果您正苦于以下问题:Python mpmath.gammainc方法的具体用法?Python mpmath.gammainc怎么用?Python mpmath.gammainc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mpmath
的用法示例。
在下文中一共展示了mpmath.gammainc方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_digamma_boundary
# 需要导入模块: import mpmath [as 别名]
# 或者: from mpmath import gammainc [as 别名]
def test_digamma_boundary():
# Check that there isn't a jump in accuracy when we switch from
# using the asymptotic series to the reflection formula.
x = -np.logspace(300, -30, 100)
y = np.array([-6.1, -5.9, 5.9, 6.1])
x, y = np.meshgrid(x, y)
z = (x + 1j*y).flatten()
dataset = []
with mpmath.workdps(30):
for z0 in z:
res = mpmath.digamma(z0)
dataset.append((z0, complex(res)))
dataset = np.asarray(dataset)
FuncData(sc.digamma, dataset, 0, 1, rtol=1e-13).check()
# ------------------------------------------------------------------------------
# gammainc
# ------------------------------------------------------------------------------
示例2: gammainc
# 需要导入模块: import mpmath [as 别名]
# 或者: from mpmath import gammainc [as 别名]
def gammainc(a, x, dps=50, maxterms=10**8):
"""Compute gammainc exactly like mpmath does but allow for more
summands in hypercomb. See
mpmath/functions/expintegrals.py#L134
in the mpmath github repository.
"""
with mp.workdps(dps):
z, a, b = mp.mpf(a), mp.mpf(x), mp.mpf(x)
G = [z]
negb = mp.fneg(b, exact=True)
def h(z):
T1 = [mp.exp(negb), b, z], [1, z, -1], [], G, [1], [1+z], b
return (T1,)
res = mp.hypercomb(h, [z], maxterms=maxterms)
return mpf2float(res)
示例3: test_gammainc_boundary
# 需要导入模块: import mpmath [as 别名]
# 或者: from mpmath import gammainc [as 别名]
def test_gammainc_boundary():
# Test the transition to the asymptotic series.
small = 20
a = np.linspace(0.5*small, 2*small, 50)
x = a.copy()
a, x = np.meshgrid(a, x)
a, x = a.flatten(), x.flatten()
dataset = []
with mpmath.workdps(100):
for a0, x0 in zip(a, x):
dataset.append((a0, x0, float(mpmath.gammainc(a0, b=x0, regularized=True))))
dataset = np.array(dataset)
FuncData(sc.gammainc, dataset, (0, 1), 2, rtol=1e-12).check()
# ------------------------------------------------------------------------------
# spence
# ------------------------------------------------------------------------------
示例4: gammaincc
# 需要导入模块: import mpmath [as 别名]
# 或者: from mpmath import gammainc [as 别名]
def gammaincc(a, x, dps=50, maxterms=10**8):
"""Compute gammaincc exactly like mpmath does but allow for more
terms in hypercomb. See
mpmath/functions/expintegrals.py#L187
in the mpmath github repository.
"""
with mp.workdps(dps):
z, a = a, x
if mp.isint(z):
try:
# mpmath has a fast integer path
return mpf2float(mp.gammainc(z, a=a, regularized=True))
except mp.libmp.NoConvergence:
pass
nega = mp.fneg(a, exact=True)
G = [z]
# Use 2F0 series when possible; fall back to lower gamma representation
try:
def h(z):
r = z-1
return [([mp.exp(nega), a], [1, r], [], G, [1, -r], [], 1/nega)]
return mpf2float(mp.hypercomb(h, [z], force_series=True))
except mp.libmp.NoConvergence:
def h(z):
T1 = [], [1, z-1], [z], G, [], [], 0
T2 = [-mp.exp(nega), a, z], [1, z, -1], [], G, [1], [1+z], a
return T1, T2
return mpf2float(mp.hypercomb(h, [z], maxterms=maxterms))
示例5: main
# 需要导入模块: import mpmath [as 别名]
# 或者: from mpmath import gammainc [as 别名]
def main():
t0 = time()
# It would be nice to have data for larger values, but either this
# requires prohibitively large precision (dps > 800) or mpmath has
# a bug. For example, gammainc(1e20, 1e20, dps=800) returns a
# value around 0.03, while the true value should be close to 0.5
# (DLMF 8.12.15).
print(__doc__)
pwd = os.path.dirname(__file__)
r = np.logspace(4, 14, 30)
ltheta = np.logspace(np.log10(pi/4), np.log10(np.arctan(0.6)), 30)
utheta = np.logspace(np.log10(pi/4), np.log10(np.arctan(1.4)), 30)
regimes = [(gammainc, ltheta), (gammaincc, utheta)]
for func, theta in regimes:
rg, thetag = np.meshgrid(r, theta)
a, x = rg*np.cos(thetag), rg*np.sin(thetag)
a, x = a.flatten(), x.flatten()
dataset = []
for i, (a0, x0) in enumerate(zip(a, x)):
if func == gammaincc:
# Exploit the fast integer path in gammaincc whenever
# possible so that the computation doesn't take too
# long
a0, x0 = np.floor(a0), np.floor(x0)
dataset.append((a0, x0, func(a0, x0)))
dataset = np.array(dataset)
filename = os.path.join(pwd, '..', 'tests', 'data', 'local',
'{}.txt'.format(func.__name__))
np.savetxt(filename, dataset)
print("{} minutes elapsed".format((time() - t0)/60))
示例6: test_gammainc
# 需要导入模块: import mpmath [as 别名]
# 或者: from mpmath import gammainc [as 别名]
def test_gammainc(self):
assert_mpmath_equal(sc.gammainc,
_exception_to_nan(
lambda z, b: mpmath.gammainc(z, b=b)/mpmath.gamma(z)),
[Arg(a=0), Arg(a=0)])
示例7: test_gdtria
# 需要导入模块: import mpmath [as 别名]
# 或者: from mpmath import gammainc [as 别名]
def test_gdtria(self):
_assert_inverts(
sp.gdtria,
lambda a, b, x: mpmath.gammainc(b, b=a*x, regularized=True),
0, [ProbArg(), Arg(0, 1e3, inclusive_a=False),
Arg(0, 1e4, inclusive_a=False)], rtol=1e-7,
endpt_atol=[None, 1e-7, 1e-10])
示例8: test_gdtrib
# 需要导入模块: import mpmath [as 别名]
# 或者: from mpmath import gammainc [as 别名]
def test_gdtrib(self):
# Use small values of a and x or mpmath doesn't converge
_assert_inverts(
sp.gdtrib,
lambda a, b, x: mpmath.gammainc(b, b=a*x, regularized=True),
1, [Arg(0, 1e2, inclusive_a=False), ProbArg(),
Arg(0, 1e3, inclusive_a=False)], rtol=1e-5)
示例9: test_chdtriv
# 需要导入模块: import mpmath [as 别名]
# 或者: from mpmath import gammainc [as 别名]
def test_chdtriv(self):
_assert_inverts(
sp.chdtriv,
lambda v, x: mpmath.gammainc(v/2, b=x/2, regularized=True),
0, [ProbArg(), IntArg(1, 100)], rtol=1e-4)
示例10: test_gammainc
# 需要导入模块: import mpmath [as 别名]
# 或者: from mpmath import gammainc [as 别名]
def test_gammainc():
# Quick check that the gammainc in
# special._precompute.gammainc_data agrees with mpmath's
# gammainc.
assert_mpmath_equal(gammainc,
lambda a, x: mp.gammainc(a, b=x, regularized=True),
[Arg(0, 100, inclusive_a=False), Arg(0, 100)],
nan_ok=False, rtol=1e-17, n=50, dps=50)
示例11: test_gammaincc
# 需要导入模块: import mpmath [as 别名]
# 或者: from mpmath import gammainc [as 别名]
def test_gammaincc():
# Check that the gammaincc in special._precompute.gammainc_data
# agrees with mpmath's gammainc.
assert_mpmath_equal(lambda a, x: gammaincc(a, x, dps=1000),
lambda a, x: mp.gammainc(a, a=x, regularized=True),
[Arg(20, 100), Arg(20, 100)],
nan_ok=False, rtol=1e-17, n=50, dps=1000)
# Test the fast integer path
assert_mpmath_equal(gammaincc,
lambda a, x: mp.gammainc(a, a=x, regularized=True),
[IntArg(1, 100), Arg(0, 100)],
nan_ok=False, rtol=1e-17, n=50, dps=50)
示例12: test_gammaincc
# 需要导入模块: import mpmath [as 别名]
# 或者: from mpmath import gammainc [as 别名]
def test_gammaincc(self):
# Larger arguments are tested in test_data.py:test_local
assert_mpmath_equal(sc.gammaincc,
lambda z, a: mpmath.gammainc(z, a=a, regularized=True),
[Arg(0, 1e4, inclusive_a=False), Arg(0, 1e4)],
nan_ok=False, rtol=1e-11)
示例13: gammaincc
# 需要导入模块: import mpmath [as 别名]
# 或者: from mpmath import gammainc [as 别名]
def gammaincc(a, x):
import mpmath
return mpmath.gammainc(a, a=x, regularized=True)