当前位置: 首页>>代码示例>>Python>>正文


Python mpmath.inf方法代码示例

本文整理汇总了Python中mpmath.inf方法的典型用法代码示例。如果您正苦于以下问题:Python mpmath.inf方法的具体用法?Python mpmath.inf怎么用?Python mpmath.inf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mpmath的用法示例。


在下文中一共展示了mpmath.inf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_wrightomega_branch

# 需要导入模块: import mpmath [as 别名]
# 或者: from mpmath import inf [as 别名]
def test_wrightomega_branch():
    x = -np.logspace(10, 0, 25)
    picut_above = [np.nextafter(np.pi, np.inf)]
    picut_below = [np.nextafter(np.pi, -np.inf)]
    npicut_above = [np.nextafter(-np.pi, np.inf)]
    npicut_below = [np.nextafter(-np.pi, -np.inf)]
    for i in range(50):
        picut_above.append(np.nextafter(picut_above[-1], np.inf))
        picut_below.append(np.nextafter(picut_below[-1], -np.inf))
        npicut_above.append(np.nextafter(npicut_above[-1], np.inf))
        npicut_below.append(np.nextafter(npicut_below[-1], -np.inf))
    y = np.hstack((picut_above, picut_below, npicut_above, npicut_below))
    x, y = np.meshgrid(x, y)
    z = (x + 1j*y).flatten()

    dataset = []
    for z0 in z:
        dataset.append((z0, complex(_mpmath_wrightomega(z0, 25))))
    dataset = np.asarray(dataset)

    FuncData(sc.wrightomega, dataset, 0, 1, rtol=1e-8).check() 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:23,代码来源:test_mpmath.py

示例2: test_e1_complex

# 需要导入模块: import mpmath [as 别名]
# 或者: from mpmath import inf [as 别名]
def test_e1_complex(self):
        # E_1 oscillates as Im[z] -> +- inf, so limit range
        assert_mpmath_equal(sc.exp1,
                            mpmath.e1,
                            [ComplexArg(complex(-np.inf, -1e8), complex(np.inf, 1e8))],
                            rtol=1e-11)

        # Check cross-over region
        assert_mpmath_equal(sc.exp1,
                            mpmath.e1,
                            (np.linspace(-50, 50, 171)[:, None] +
                             np.r_[0, np.logspace(-3, 2, 61),
                                   -np.logspace(-3, 2, 11)]*1j).ravel(),
                            rtol=1e-11)
        assert_mpmath_equal(sc.exp1,
                            mpmath.e1,
                            (np.linspace(-50, -35, 10000) + 0j),
                            rtol=1e-11) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:20,代码来源:test_mpmath.py

示例3: test_lanczos_sum_expg_scaled

# 需要导入模块: import mpmath [as 别名]
# 或者: from mpmath import inf [as 别名]
def test_lanczos_sum_expg_scaled(self):
        maxgamma = 171.624376956302725
        e = np.exp(1)
        g = 6.024680040776729583740234375

        def gamma(x):
            with np.errstate(over='ignore'):
                fac = ((x + g - 0.5)/e)**(x - 0.5)
                if fac != np.inf:
                    res = fac*_lanczos_sum_expg_scaled(x)
                else:
                    fac = ((x + g - 0.5)/e)**(0.5*(x - 0.5))
                    res = fac*_lanczos_sum_expg_scaled(x)
                    res *= fac
            return res

        assert_mpmath_equal(gamma,
                            mpmath.gamma,
                            [Arg(0, maxgamma, inclusive_a=False)],
                            rtol=1e-13) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:22,代码来源:test_mpmath.py

示例4: _compute_delta

# 需要导入模块: import mpmath [as 别名]
# 或者: from mpmath import inf [as 别名]
def _compute_delta(log_moments, eps):
  """Compute delta for given log_moments and eps.
  Args:
    log_moments: the log moments of privacy loss, in the form of pairs
      of (moment_order, log_moment)
    eps: the target epsilon.
  Returns:
    delta
  """
  min_delta = 1.0
  for moment_order, log_moment in log_moments:
    if moment_order == 0:
      continue
    if math.isinf(log_moment) or math.isnan(log_moment):
      sys.stderr.write("The %d-th order is inf or Nan\n" % moment_order)
      continue
    if log_moment < moment_order * eps:
      min_delta = min(min_delta,
                      math.exp(log_moment - moment_order * eps))
  return min_delta 
开发者ID:SAP-samples,项目名称:machine-learning-diff-private-federated-learning,代码行数:22,代码来源:gaussian_moments.py

示例5: _compute_eps

# 需要导入模块: import mpmath [as 别名]
# 或者: from mpmath import inf [as 别名]
def _compute_eps(log_moments, delta):
  """Compute epsilon for given log_moments and delta.
  Args:
    log_moments: the log moments of privacy loss, in the form of pairs
      of (moment_order, log_moment)
    delta: the target delta.
  Returns:
    epsilon
  """
  min_eps = float("inf")
  for moment_order, log_moment in log_moments:
    if moment_order == 0:
      continue
    if math.isinf(log_moment) or math.isnan(log_moment):
      sys.stderr.write("The %d-th order is inf or Nan\n" % moment_order)
      continue
    min_eps = min(min_eps, (log_moment - math.log(delta)) / moment_order)
  return min_eps 
开发者ID:SAP-samples,项目名称:machine-learning-diff-private-federated-learning,代码行数:20,代码来源:gaussian_moments.py

示例6: compute_b_mp

# 需要导入模块: import mpmath [as 别名]
# 或者: from mpmath import inf [as 别名]
def compute_b_mp(self, sigma, q, order, verbose=False):
    """Compute B_lambda for arbitrary lambda by numerical integration."""
    mu0, _, mu = self._distributions_mp(sigma, q)
    b_lambda_fn = lambda z: mu0(z) * (mu0(z) / mu(z)) ** order
    b_numeric = self._integral_inf_mp(b_lambda_fn)

    if verbose:
      _, z1 = rdp_accountant._compute_zs(sigma, q)
      print("z1 = ", z1)
      print("x in the Taylor series = ", q / (1 - q) * np.exp(
          (2 * z1 - 1) / (2 * sigma ** 2)))

      b0_numeric = self._integral_bounded_mp(b_lambda_fn, -np.inf, z1)
      b1_numeric = self._integral_bounded_mp(b_lambda_fn, z1, +np.inf)

      print("B: numerically {} = {} + {}".format(b_numeric, b0_numeric,
                                                 b1_numeric))
    return float(b_numeric) 
开发者ID:isobar-us,项目名称:multilabel-image-classification-tensorflow,代码行数:20,代码来源:rdp_accountant_test.py

示例7: test_besselk

# 需要导入模块: import mpmath [as 别名]
# 或者: from mpmath import inf [as 别名]
def test_besselk(self):
        assert_mpmath_equal(sc.kv,
                            mpmath.besselk,
                            [Arg(-200, 200), Arg(0, np.inf)],
                            nan_ok=False, rtol=1e-12) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:7,代码来源:test_mpmath.py

示例8: test_besselk_int

# 需要导入模块: import mpmath [as 别名]
# 或者: from mpmath import inf [as 别名]
def test_besselk_int(self):
        assert_mpmath_equal(sc.kn,
                            mpmath.besselk,
                            [IntArg(-200, 200), Arg(0, np.inf)],
                            nan_ok=False, rtol=1e-12) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:7,代码来源:test_mpmath.py

示例9: test_bessely

# 需要导入模块: import mpmath [as 别名]
# 或者: from mpmath import inf [as 别名]
def test_bessely(self):
        def mpbessely(v, x):
            r = float(mpmath.bessely(v, x, **HYPERKW))
            if abs(r) > 1e305:
                # overflowing to inf a bit earlier is OK
                r = np.inf * np.sign(r)
            if abs(r) == 0 and x == 0:
                # invalid result from mpmath, point x=0 is a divergence
                return np.nan
            return r
        assert_mpmath_equal(sc.yv,
                            exception_to_nan(mpbessely),
                            [Arg(-1e100, 1e100), Arg(-1e8, 1e8)],
                            n=5000) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:16,代码来源:test_mpmath.py

示例10: test_bessely_complex

# 需要导入模块: import mpmath [as 别名]
# 或者: from mpmath import inf [as 别名]
def test_bessely_complex(self):
        def mpbessely(v, x):
            r = complex(mpmath.bessely(v, x, **HYPERKW))
            if abs(r) > 1e305:
                # overflowing to inf a bit earlier is OK
                olderr = np.seterr(invalid='ignore')
                try:
                    r = np.inf * np.sign(r)
                finally:
                    np.seterr(**olderr)
            return r
        assert_mpmath_equal(lambda v, z: sc.yv(v.real, z),
                            exception_to_nan(mpbessely),
                            [Arg(), ComplexArg()],
                            n=15000) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:17,代码来源:test_mpmath.py

示例11: test_ci_complex

# 需要导入模块: import mpmath [as 别名]
# 或者: from mpmath import inf [as 别名]
def test_ci_complex(self):
        def ci(z):
            return sc.sici(z)[1]
        # ci oscillates as Re[z] -> +- inf, so limit range
        assert_mpmath_equal(ci,
                            mpmath.ci,
                            [ComplexArg(complex(-1e8, -np.inf), complex(1e8, np.inf))],
                            rtol=1e-8) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:10,代码来源:test_mpmath.py

示例12: test_exprel

# 需要导入模块: import mpmath [as 别名]
# 或者: from mpmath import inf [as 别名]
def test_exprel(self):
        assert_mpmath_equal(sc.exprel,
                            lambda x: mpmath.expm1(x)/x if x != 0 else mpmath.mpf('1.0'),
                            [Arg(a=-np.log(np.finfo(np.double).max), b=np.log(np.finfo(np.double).max))])
        assert_mpmath_equal(sc.exprel,
                            lambda x: mpmath.expm1(x)/x if x != 0 else mpmath.mpf('1.0'),
                            np.array([1e-12, 1e-24, 0, 1e12, 1e24, np.inf]), rtol=1e-11)
        assert_(np.isinf(sc.exprel(np.inf)))
        assert_(sc.exprel(-np.inf) == 0) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:11,代码来源:test_mpmath.py

示例13: test_expm1_complex

# 需要导入模块: import mpmath [as 别名]
# 或者: from mpmath import inf [as 别名]
def test_expm1_complex(self):
        # Oscillates as a function of Im[z], so limit range to avoid loss of precision
        assert_mpmath_equal(sc.expm1,
                            mpmath.expm1,
                            [ComplexArg(complex(-np.inf, -1e7), complex(np.inf, 1e7))]) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:7,代码来源:test_mpmath.py

示例14: test_ei_complex

# 需要导入模块: import mpmath [as 别名]
# 或者: from mpmath import inf [as 别名]
def test_ei_complex(self):
        # Ei oscillates as Im[z] -> +- inf, so limit range
        assert_mpmath_equal(sc.expi,
                            mpmath.ei,
                            [ComplexArg(complex(-np.inf, -1e8), complex(np.inf, 1e8))],
                            rtol=1e-9) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:8,代码来源:test_mpmath.py

示例15: test_lambertw_real

# 需要导入模块: import mpmath [as 别名]
# 或者: from mpmath import inf [as 别名]
def test_lambertw_real(self):
        assert_mpmath_equal(lambda x, k: sc.lambertw(x, int(k.real)),
                            lambda x, k: mpmath.lambertw(x, int(k.real)),
                            [ComplexArg(-np.inf, np.inf), IntArg(0, 10)],
                            rtol=1e-13, nan_ok=False) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:7,代码来源:test_mpmath.py


注:本文中的mpmath.inf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。