Mechanism Calibration

A PrivacyAccountant and a DpEvent can be used to compute the privacy parameters of a mechanism, given the mechanism’s parameters. This module reverses that process: it offers functions to compute the minimal/maximal parameter of a mechanism that is needed to achieve a given level of privacy.

As a simple example, this snippet calibrates the noise multiplier for a Gaussian mechanism to achieve (1, 1e-5)-DP:

noise_multiplier = dp_accounting.calibrate_dp_mechanism(
    make_fresh_accountant=dp_accounting.pld.PLDAccountant,
    make_event_from_param=dp_accounting.GaussianDpEvent,
    target_epsilon=1.0,
    target_delta=1e-5,
)

Functions

dp_accounting.mechanism_calibration.calibrate_dp_mechanism(make_fresh_accountant, make_event_from_param, target_epsilon, target_delta, bracket_interval=None, discrete=False, tol=None)[source]

Searches for optimal mechanism parameter value within privacy budget.

The procedure searches over the space of parameters by creating, for each sample value, a DpEvent representing the mechanism generated from that value, and a freshly initialized PrivacyAccountant. Then the accountant is applied to the event to determine its epsilon at the target delta. Brent’s method is used to determine the value of the parameter at which the target epsilon is achieved.

Parameters:
  • make_fresh_accountant (Callable[[], PrivacyAccountant]) – A callable with no parameters that returns an initialized PrivacyAccountant. The accountants that are returned across multiple calls are assumed to be initialized identically. It is an error for the initialized accountant’s ledger property to return anything besides NoOpDpEvent.

  • make_event_from_param (Union[Callable[[float], DpEvent], Callable[[int], DpEvent]]) – A callable that takes a parameter value as an argument and creates a DpEvent representing the mechanism defined using that value.

  • target_epsilon (float) – The target epsilon value.

  • target_delta (float) – The target delta value.

  • bracket_interval (Optional[BracketInterval]) – A BracketInterval used to determine the upper and lower endpoints of the interval within which Brent’s method will search. If None, searches for a non-negative bracket starting from [0, 1].

  • discrete (bool) – A bool determining whether the parameter is continuous or discrete valued. If True, the parameter is assumed to take only integer values. Concretely, discrete=True has three effects. 1) ints, not floats are passed to make_event_from_param. 2) The minimum optimization tolerance is 0.5. 3) An integer is returned.

  • tol (Optional[float]) – The tolerance, in parameter space. If the maximum (or minimum) value of the parameter that meets the privacy requirements is x*, calibrate_dp_mechanism is guaranteed to return a value x such that |x - x*| <= tol. If None, tol is set to 1e-6 for continuous parameters or 0.5 for discrete parameters.

Return type:

Union[float, int]

Returns:

A value of the parameter within tol of the optimum subject to the privacy constraint. If discrete=True, the returned value will be an integer. Otherwise it will be a float.

Raises:
  • NoBracketIntervalFoundError – if bracket_interval is LowerEndpointAndGuess and no upper bound can be found within a factor of 2**30 of the original guess.

  • NonEmptyAccountantError – if make_fresh_accountant returns an accountant with nonempty ledger.

Classes

class dp_accounting.mechanism_calibration.BracketInterval[source]
class dp_accounting.mechanism_calibration.ExplicitBracketInterval(endpoint_1, endpoint_2)[source]

Bases: BracketInterval

endpoint_1: float
endpoint_2: float
class dp_accounting.mechanism_calibration.LowerEndpointAndGuess(lower_endpoint, initial_guess)[source]

Bases: BracketInterval

lower_endpoint: float
initial_guess: float

Exceptions

exception dp_accounting.mechanism_calibration.NoBracketIntervalFoundError[source]

Error raised when explicit bracket interval cannot be found.

exception dp_accounting.mechanism_calibration.NonEmptyAccountantError[source]

Error raised when result of make_fresh_accountant has nonempty ledger.