jax_privacy.batch_selection.RandomAllocationSampling#
- class jax_privacy.batch_selection.RandomAllocationSampling(total_participations, iterations, cycle_length=1, partition_type=PartitionType.INDEPENDENT, sampling_prob=1.0)[source]#
Bases:
BatchSelectionStrategyImplements k-out-of-t random allocation (aka balanced-iteration sampling).
Each example independently selects exactly \(k\) steps (out of the steps it is eligible for) to participate in, uniformly at random. For \(k=1\) and
cycle_length=1, this participation pattern is equivalent to BallsInBinsSampling, and fortotal_participations = ceil(iterations / cycle_length)andsampling_prob < 1, it recovers CyclicPoissonSampling (without batch truncation).If
cycle_length > 1, each example is first independently assigned to one ofcycle_lengthgroups uniformly at random, and group \(j\) is only eligible to participate in iterations \(i\) withi % cycle_length == j. Two consecutive participations of an example are then always at leastcycle_lengthiterations apart, which satisfies the min-separation requirement of acycle_length-banded matrix mechanism.cycle_length == 1retrieves standard random allocation.References
https://arxiv.org/abs/2206.03151 (k=1 only)
https://arxiv.org/abs/2306.08153 (cycle_length > 1)
https://arxiv.org/abs/2410.06266 (k=1 only)
https://arxiv.org/abs/2412.16802 (k=1 only)
https://arxiv.org/abs/2610.12712 (cycle_length > 1, k > 1)
- Formal guarantees of the
batch_iterator: All batches consist of indices in the range
[0, num_examples).Each example only appears in batches with index
isuch thati % cycle_length == jfor some fixedjchosen uniformly at random independently for each example.Each example appears in exactly \(k\) of the batches it is eligible for, chosen uniformly at random without replacement.
The allocation for each example is independent of all other examples.
- Accounting:
For DP-SGD with Gaussian noise (
cycle_length = 1), and for amplified BandMF with acycle_length-banded strategy matrix, exact analytical privacy accounting under the add-or-remove-one adjacency notion is supported viarandom_allocation_dpsgd_event()andrandom_allocation_bandmf_event()respectively.
- Variables:
total_participations – The number of eligible steps each example participates in (k). If
iterationsis not a multiple ofcycle_length, the schedule runs as if for the next multiple ofcycle_lengthand truncates afteriterationssteps.iterations – The total number of iterations / batches to generate (t).
cycle_length – If > 1, the examples are independently partitioned into
cycle_lengthgroups which participate in a round-robin fashion, so that each example participates at most once everycycle_lengthiterations.cycle_length == 1retrieves standard random allocation.partition_type – How to partition the examples into groups before random allocation.
INDEPENDENTis the default, whileEQUAL_SPLITshuffles and splits into groups of equal size (discardingnum_examples % cycle_lengthexamples).sampling_prob – Probability of independently keeping each allocated participation. Defaults to
1.0(no subsampling).
Methods
__init__Yields 1D batches of data indices.
Attributes
-
total_participations:
int#
-
iterations:
int#
-
cycle_length:
int= 1#
-
partition_type:
PartitionType= 1#
-
sampling_prob:
float= 1.0#