-
-
Notifications
You must be signed in to change notification settings - Fork 85
Create error estimator for SUM #528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,9 +49,18 @@ def _get_estimator( | |
| epsilon: float = 2**0.5 / 2, | ||
| delta: Optional[float] = None, | ||
| ): | ||
| return histogram_error_estimator.create_error_estimator( | ||
| return histogram_error_estimator.create_estimator_for_count_privacy_id_count( | ||
|
||
| self._get_histograms(), epsilon, delta, metric, noise_kind) | ||
|
|
||
| def _get_estimator_for_sum( | ||
| self, | ||
| noise_kind: pipeline_dp.NoiseKind = pipeline_dp.NoiseKind.LAPLACE, | ||
| epsilon: float = 2**0.5 / 2, | ||
| delta: Optional[float] = None, | ||
| ): | ||
| return histogram_error_estimator.create_estimator_for_sum( | ||
| self._get_histograms(), epsilon, delta, noise_kind) | ||
|
|
||
| @parameterized.named_parameters( | ||
| dict(testcase_name='count_gaussian', | ||
| metric=pipeline_dp.Metrics.COUNT, | ||
|
|
@@ -112,6 +121,15 @@ def test_get_ratio_dropped_l0(self, l0_bound, expected): | |
| self.assertAlmostEqual(estimator.get_ratio_dropped_l0(l0_bound), | ||
| expected) | ||
|
|
||
| @parameterized.parameters((0, 1), (1, 9 / 11), (2, 8 / 11), (3, 7 / 11), | ||
| (9, 1 / 11), (10, 0), (20, 0)) | ||
| # there are 11 (privacy_id, partition) pairs (from 2 privacy units), when | ||
| # l0_bound=1, 9 are dropped (from 1 privacy unit). | ||
| def test_get_ratio_dropped_l0_for_sum(self, l0_bound, expected): | ||
| estimator = self._get_estimator_for_sum() | ||
| self.assertAlmostEqual(estimator.get_ratio_dropped_l0(l0_bound), | ||
| expected) | ||
|
|
||
| @parameterized.parameters((0, 1), (1, 19 / 30), (2, 18 / 30), (10, 10 / 30), | ||
| (20, 0), (21, 0)) | ||
| # there are 30 rows (from 2 privacy units), when linf_bound=1, 19 are | ||
|
|
@@ -121,6 +139,17 @@ def test_get_ratio_dropped_linf(self, linf_bound, expected): | |
| self.assertAlmostEqual(estimator.get_ratio_dropped_linf(linf_bound), | ||
| expected) | ||
|
|
||
| @parameterized.parameters((0, 1), (0.5, 0.89), (1, 0.78), (2, 0.76), | ||
| (40, 0)) | ||
| # there 1 is contribution 40 and 10 contribution 1. | ||
|
||
| # total contribution = 1*40+10*1 = 50 | ||
| # when linf_bound = 0.5, left after contribution bounding 11*0.5=5.5, i.e. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how linf can be a double and not an integer?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. linf_bound is max contribution per partition, which means
|
||
| # dropped (50-5.5)/50 = 0.89 | ||
| def test_get_ratio_dropped_linf_for_sum(self, linf_bound, expected): | ||
| estimator = self._get_estimator_for_sum() | ||
| self.assertAlmostEqual(estimator.get_ratio_dropped_linf(linf_bound), | ||
| expected) | ||
|
|
||
| @parameterized.parameters((1, 1, 3.9565310998335823), | ||
| (1, 2, 5.683396971098993), | ||
| (10, 10, 200.01249625055996)) | ||
|
|
@@ -142,6 +171,10 @@ def test_estimate_rmse_count(self, l0_bound, linf_bound, expected): | |
| self.assertAlmostEqual(estimator.estimate_rmse(l0_bound, linf_bound), | ||
| expected) | ||
|
|
||
| def test_estimate_rmse_sum(self): | ||
| estimator = self._get_estimator_for_sum() | ||
| self.assertAlmostEqual(estimator.estimate_rmse(1, 1), 5.93769917) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| absltest.main() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it for debugging only? should we remove it? just double checking :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, thanks. Removed