-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
two new unit tests on the converters
- Loading branch information
Showing
6 changed files
with
144 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from autodp.mechanism_zoo import GaussianMechanism | ||
from autodp.fdp_bank import fDP_gaussian | ||
|
||
import numpy as np | ||
|
||
from absl.testing import absltest | ||
from absl.testing import parameterized | ||
|
||
params = [0.05, 0.1, 0.2, 0.5,1.0, 2.0,5.0, 10.0] | ||
|
||
|
||
def _fdp_conversion(sigma): | ||
|
||
# Using the log(1-f(fpr)) and log(- \partial f(fpr)) that are implemented dedicatedly | ||
|
||
fpr_list = np.linspace(0, 1, 21) | ||
|
||
# analytical gaussian implementation (privacy profile) | ||
gm2 = GaussianMechanism(sigma, name='GM2', RDP_off=True) | ||
|
||
# direct f-DP implementation | ||
fdp = lambda x: fDP_gaussian({'sigma': sigma},x) | ||
|
||
fdp_direct = fdp(fpr_list) | ||
|
||
# the fdp is converted by numerical methods from privacy profile. | ||
fdp_converted = np.array([gm2.get_fDP(fpr) for fpr in fpr_list]) | ||
|
||
return fdp_direct - fdp_converted | ||
|
||
|
||
|
||
class Test_approxDP2fDP_Conversion(parameterized.TestCase): | ||
|
||
@parameterized.parameters(p for p in params) | ||
def test_fdp_conversion(self, sigma): | ||
max_diff = _fdp_conversion(sigma) | ||
self.assertSequenceAlmostEqual(max_diff, np.zeros_like(max_diff), places=4) | ||
|
||
|
||
if __name__ == '__main__': | ||
absltest.main() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from autodp.mechanism_zoo import GaussianMechanism | ||
from autodp.dp_bank import get_eps_ana_gaussian | ||
|
||
import numpy as np | ||
|
||
from absl.testing import absltest | ||
from absl.testing import parameterized | ||
|
||
params = [0.05, 0.1, 0.2, 0.5,1.0, 2.0, 5.0, 10.0] | ||
|
||
|
||
def _fdp_conversion(sigma): | ||
|
||
delta_list = [0,1e-8, 1e-6, 1e-4, 1e-2, 0.3, 0.5, 1] | ||
|
||
# f-DP implementation | ||
gm3 = GaussianMechanism(sigma, name='GM3', RDP_off=True, approxDP_off=True, fdp_off=False) | ||
|
||
# direct approxdp implementation | ||
agm = lambda x: get_eps_ana_gaussian(sigma, x) | ||
|
||
eps_direct = np.array([agm(delta) for delta in delta_list]) | ||
|
||
# the fdp is converted by numerical methods from privacy profile. | ||
eps_converted = np.array([gm3.get_approxDP(delta) for delta in delta_list]) | ||
max_diff = eps_direct - eps_converted | ||
|
||
rel_diff = max_diff / (eps_direct+1e-10) | ||
|
||
if np.isinf(eps_direct[0]) and np.isinf(eps_converted[0]): | ||
rel_diff[0] = 0 | ||
return rel_diff | ||
|
||
|
||
_fdp_conversion(0.05) | ||
|
||
class Test_approxDP2fDP_Conversion(parameterized.TestCase): | ||
|
||
@parameterized.parameters(p for p in params) | ||
def test_fdp_conversion(self, sigma): | ||
max_diff = _fdp_conversion(sigma) | ||
self.assertSequenceAlmostEqual(max_diff, np.zeros_like(max_diff), places=2) | ||
|
||
|
||
if __name__ == '__main__': | ||
absltest.main() | ||
|