Esempio n. 1
0
  def _compare_bounds(self, q, sigma, order):
    log_a_mp, log_b_mp = self._compute_rdp_mp(q, sigma, order)
    log_a = rdp_accountant._compute_log_a(q, sigma, order)
    log_bound_b = rdp_accountant._bound_log_b(q, sigma, order)

    if log_a_mp < 1000 and log_a_mp > 1e-6:
      self._almost_equal(log_a, log_a_mp, rtol=1e-6)
    else:  # be more tolerant for _very_ large or small logarithms
      self._almost_equal(log_a, log_a_mp, rtol=1e-3, atol=1e-14)

    if np.isfinite(log_bound_b):
      # Ignore divergence between the bound and exact value of B if
      # they don't matter anyway (bound on A is larger) or q > .5
      if log_bound_b > log_a and q <= .5:
        self._almost_equal(log_b_mp, log_bound_b, rtol=1e-6, atol=1e-14)

    if np.isfinite(log_a_mp) and np.isfinite(log_b_mp):
      # We hypothesize that this assertion is always true; no proof yet.
      self.assertLessEqual(log_b_mp, log_a_mp + 1e-6)
Esempio n. 2
0
  def _compare_bounds(self, q, sigma, order):
    log_a_mp, log_b_mp = self._compute_rdp_mp(q, sigma, order)
    log_a = rdp_accountant._compute_log_a(q, sigma, order)
    log_bound_b = rdp_accountant._bound_log_b(q, sigma, order)

    if log_a_mp < 1000 and log_a_mp > 1e-6:
      self._almost_equal(log_a, log_a_mp, rtol=1e-6)
    else:  # be more tolerant for _very_ large or small logarithms
      self._almost_equal(log_a, log_a_mp, rtol=1e-3, atol=1e-14)

    if np.isfinite(log_bound_b):
      # Ignore divergence between the bound and exact value of B if
      # they don't matter anyway (bound on A is larger) or q > .5
      if log_bound_b > log_a and q <= .5:
        self._almost_equal(log_b_mp, log_bound_b, rtol=1e-6, atol=1e-14)

    if np.isfinite(log_a_mp) and np.isfinite(log_b_mp):
      # We hypothesize that this assertion is always true; no proof yet.
      self.assertLessEqual(log_b_mp, log_a_mp + 1e-6)
Esempio n. 3
0
 def test_compute_log_a_equals_mp(self, q, sigma, order):
     # Compare the cheap computation of log(A) with an expensive, multi-precision
     # computation.
     log_a = rdp_accountant._compute_log_a(q, sigma, order)
     log_a_mp = self._log_float_mp(self._compute_a_mp(sigma, q, order))
     np.testing.assert_allclose(log_a, log_a_mp, rtol=1e-4)