Skip to content

Commit 931ce78

Browse files
Ryan McKennacopybara-github
authored andcommitted
Consolidate low-level DP primitives into dpsynth.local_mode.primitives
- Merges _quantiles.py into primitives.py, establishing primitives.py as the singular home for low-level DP building blocks in dpsynth. - Extracts a general-purpose exponential_mechanism primitive which the histogram median algorithm now calls. - Deletes the obsolete DP-SIPS partition selection implementation and tests. - Updates the module header to document that all primitives expect pre-computed aggregates (counts) rather than computing aggregations themselves, placing caller responsibility on satisfying privacy assumptions (such as each user contributing at most one record to one bucket). - Updates initialization and tests to import from primitives.py and deletes _quantiles.py and _quantiles_test.py. PiperOrigin-RevId: 976794904
1 parent 900fc4f commit 931ce78

7 files changed

Lines changed: 371 additions & 536 deletions

File tree

docs/mechanism_api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ composed or split as cleanly:
280280
bisections, whose composite `dp_event` is a composition of exponential
281281
mechanisms.
282282

283-
[dp-quantiles-src]: https://github.com/google/dpsynth/blob/main/dpsynth/local_mode/_quantiles.py
283+
[dp-quantiles-src]: https://github.com/google/dpsynth/blob/main/dpsynth/local_mode/primitives.py
284284

285285
Because these heterogeneous parameters cannot be directly combined,
286286
`configure()` accepts a single scalar `zcdp_rho` and translates it into each

dpsynth/local_mode/_quantiles.py

Lines changed: 0 additions & 153 deletions
This file was deleted.

dpsynth/local_mode/initialization.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import dp_accounting
2323
from dpsynth import api
2424
from dpsynth import domain
25-
from dpsynth.local_mode import _quantiles
2625
from dpsynth.local_mode import primitives
2726
from dpsynth.local_mode import vectorized_transformations as vtx
2827
import numpy as np
@@ -90,7 +89,7 @@ def compute_grid_spec(
9089
"""Returns (lower, upper, grid_size) for the quantile candidate grid."""
9190
min_value = float(attribute.min_value)
9291
if attribute.dtype == 'int':
93-
m = _quantiles.jitter_factor(num_partitions)
92+
m = primitives.jitter_factor(num_partitions)
9493
budget = max(2, max_grid_size // m)
9594
int_range = int(attribute.max_value - attribute.min_value + 1)
9695
step = max(1, math.ceil(int_range / budget))
@@ -212,7 +211,7 @@ def from_summary(
212211
) -> NumericalMeasurement:
213212
"""Returns a NumericalMeasurement from pre-aggregated histogram counts."""
214213
jitter_strategy = 'refine' if self.attribute.dtype == 'int' else 'symmetric'
215-
indices = _quantiles.quantiles_from_histogram(
214+
indices = primitives.quantiles_from_histogram(
216215
rng,
217216
counts,
218217
epsilon_levels=np.asarray(self.epsilon_levels),

0 commit comments

Comments
 (0)