def test_get_delta_R_regression_valid_params(self):
        """ Tests that results of get_delta_R did not drift from last version."""
        nc = 10
        sigmas = np.linspace(1.6, 1.8, nc)
        q_values = np.linspace(0.05, 0.06, nc)
        ks = 10 * np.ones(
            nc, dtype=np.int32
        )  #number of compositions for each value of (q,sigma)

        test_data = [
            (dict(sigma=sigmas,
                  q=q_values,
                  ncomp=ks,
                  target_eps=1.0,
                  nx=1E6,
                  L=20.0), 0.0007824006722393885),
            (dict(sigma=sigmas,
                  q=q_values,
                  ncomp=ks,
                  target_eps=1.0,
                  nx=1E6,
                  L=40.0), 0.0007824006547443852),
            (dict(sigma=sigmas,
                  q=q_values,
                  ncomp=ks,
                  target_eps=1.0,
                  nx=1E5,
                  L=20.0), 0.0007824000947941229),
            (dict(sigma=sigmas,
                  q=q_values,
                  ncomp=ks,
                  target_eps=0.8,
                  nx=1E6,
                  L=20.0), 0.0030814519279194538),
            (dict(sigma=sigmas[:-1],
                  q=q_values[:-1],
                  ncomp=ks[:-1],
                  target_eps=1.0,
                  nx=1E6,
                  L=20.0), 0.0005014987387132376),
        ]

        for params, expected in test_data:
            actual = get_delta_R(**params)
            self.assertAlmostEqual(expected, actual)
 def test_get_delta_R_invalid_sizes(self):
     with self.assertRaises(ValueError):
         get_delta_R(sigma=np.ones(2),
                     q=np.ones(2),
                     ncomp=np.ones(1, dtype=np.int32))
     with self.assertRaises(ValueError):
         get_delta_R(sigma=np.ones(2),
                     q=np.ones(1),
                     ncomp=np.ones(2, dtype=np.int32))
     with self.assertRaises(ValueError):
         get_delta_R(sigma=np.ones(1),
                     q=np.ones(2),
                     ncomp=np.ones(2, dtype=np.int32))
Exemple #3
0
# Examples for fixed q and sigma

q = 0.01
sigma = 1.5
nc = 1000  #number of compositions
L = 20
nx = 2E6

# Examples for computing delta as a function of epsilon

eps = 1.0  #target epsilon

#Compute delta in remove/add relation
d1 = compute_delta.get_delta_R(q=q,
                               sigma=sigma,
                               target_eps=eps,
                               L=L,
                               nx=nx,
                               ncomp=nc)

#Compute delta in substitute relation
d2 = compute_delta.get_delta_S(q=q,
                               sigma=sigma,
                               target_eps=eps,
                               L=L,
                               nx=nx,
                               ncomp=nc)

# Examples for computing epsilon as a function of delta

delta = 1e-7
Exemple #4
0
    def get_delta(self, target_epsilon, q, num_epochs=None, num_iter=None):
        num_iter = self._validate_epochs_and_iter(num_epochs, num_iter, q)

        eps = get_delta_R(target_epsilon, self._dp_scale, q, ncomp=num_iter)
        return eps