jax_privacy.experimental.monte_carlo.delta_calculation.perform_calibration_from_samples

jax_privacy.experimental.monte_carlo.delta_calculation.perform_calibration_from_samples#

jax_privacy.experimental.monte_carlo.delta_calculation.perform_calibration_from_samples(epsilon, delta, *, positive_samples, negative_samples=None, other_event=None)[source]#

Perform calibration to find highest-utility parameter for DP target.

This is Algorithm 5 in https://arxiv.org/pdf/2602.09338.

In particular, this method assumes we have chosen a sweep of a hyperparameter (such as noise multiplier), for each value in the sweep independently generated some number of samples, and now want to find the highest-utility hyperparameter (e.g. the lowest noise multiplier or highest number of training iterations in DP-SGD) we can use and still report end-to-end (epsilon, delta)-DP using Monte Carlo verification.

We assume that the samples are ordered from highest to lowest privacy of the hyperparameters, i.e. lowest to highest delta at a fixed epsilon (or vice-versa), even though the privacy parameters may not be explicitly known. e.g., in the example of calibrating the noise multiplier for DP-BandMF, we would order the samples from highest to lowest noise multiplier, even if we may not know the exact (epsilon, delta)-DP guarantee for each noise multiplier.

If different numbers of samples were used for each hyperparameter, this method conservatively uses the minimum number of samples across all values of the hyperparameter for computing tail bounds. Likewise, if different support bounds apply to different hyperparameters, the maximum is used.

Example Usage (calibrating a Gaussian mechanism):
>>> epsilon, delta = 4.0, 1e-3
>>> nm_sweep = [2.0, 1.0, 0.5]
>>> positive_samples = []
>>> for nm in nm_sweep:
...   positive_samples.append(PrivacyLossSamples(
...     np.random.normal(loc=0.5 / nm ** 2, size=1_000_000)
...   ))
>>> passes_verification, best_nm_index = perform_calibration_from_samples(
...   epsilon, delta, positive_samples=positive_samples
... )
>>> if passes_verification:
...   print(nm_sweep[best_nm_index])
1.0
Parameters:
  • epsilon (float) – The epsilon parameter of the target DP guarantee.

  • delta (float) – The delta parameter of the target DP guarantee.

  • positive_samples (Sequence[PrivacyLossSamples]) – Privacy loss samples from the positive case, one PrivacyLossSamples for each hyperparameter value.

  • negative_samples (Optional[Sequence[PrivacyLossSamples | None]]) – Optional privacy loss samples from the negative case, one for each hyperparameter value. If None, this means we assume the positive case has a worse DP guarantee than the negative case, so we only need to do accounting for the positive case. Individual entries may also be None, meaning the negative case is known (e.g. from an analytic bound) to have delta at most the base delta that the positive case is verified against, see get_base_delta(), so only the positive case is checked for it.

  • other_event (Union[DpEvent, PLDAccountant, Sequence[DpEvent | PLDAccountant], None]) – Optional DpEvent or PLDAccountant or sequence thereof. For simplicity we don’t accept Sequence[DpEvent], the ComposedDpEvent can be used instead. For brevity, we below refer to other_event as if it is a DpEvent, but if an accountant is passed the below logic is equivalent by substituting in the event represented by the accountant. - If other_event is None, we are just calibrating the single event corresponding to the sequence of privacy loss samples. - If other_event is a single DpEvent, we are calibrating the composition of the mechanism whose privacy loss samples we computed and other_event, and are assuming other_event is fixed with respect to the parameter we are calibrating. - If other_event is a list of other_event objects, it must have the same length as positive_samples, i.e. one event for each hyperparameter value. In this case, we are again calibrating the composition of the mechanism whose privacy loss samples we computed, and other_event, but now we are assuming other_event is defined as a function of the parameter we are calibrating (and other_event[i] corresponds to the i-th hyperparameter value). For example, suppose we are calibrating sigma in {sigma_1, sigma_2} for the composition of a mechanism M(sigma) with a Gaussian mechanism with noise multiplier sigma. Then we should have positive_samples = [samples_1, samples_2], where samples_i is the privacy loss samples for M(sigma_i) (and samples_1 is independent of samples_2), and other_event is [GaussianDpEvent(sigma_1), GaussianDpEvent(sigma_2)]. Cannot be combined with importance-weighted samples.

Return type:

tuple[bool, int | float]

Returns:

Either (True, i), or (False, base_delta). If there is an associated set of hyperparameters and (True, i) is returned, i is the index of the highest-utility hyperparameter we can use while satisfying the target \((\varepsilon, \delta)\)-DP guarantee. If (False, base_delta) is returned, we should fall back to a mechanism that is known to be \((\varepsilon, \text{base\_delta})\)-DP (i.e., one that can be calibrated without Monte Carlo verification).