privacy_budget#

Classes for specifying privacy budgets.

For a full introduction to privacy budgets, see the privacy budget topic guide.

Classes#

PrivacyBudget

Base class for specifying privacy parameters.

PureDPBudget

A privacy budget under pure differential privacy.

ApproxDPBudget

A privacy budget under approximate differential privacy.

RhoZCDPBudget

A privacy budget under rho-zero-concentrated differential privacy.

class PrivacyBudget#

Bases: abc.ABC

Base class for specifying privacy parameters.

A PrivacyBudget is a privacy definition, along with its associated parameters. The choice of a PrivacyBudget has an impact on the accuracy of query results. Smaller parameters correspond to a stronger privacy guarantee, and usually lead to less accurate results.

Note

An “infinite” privacy budget means that the chosen DP algorithm will use parameters that do not guarantee privacy. This is not always exactly equivalent to evaluating the query without applying differential privacy. Please see the individual subclasses of PrivacyBudget for details on how to appropriately specify infinite budgets.

property value: tmlt.core.utils.exact_number.ExactNumber | Tuple[tmlt.core.utils.exact_number.ExactNumber, tmlt.core.utils.exact_number.ExactNumber]#
Abstractmethod:

Return type:

Union[tmlt.core.utils.exact_number.ExactNumber, Tuple[tmlt.core.utils.exact_number.ExactNumber, tmlt.core.utils.exact_number.ExactNumber]]

Return the value of the privacy budget.

property is_infinite: bool#
Abstractmethod:

Return type:

bool

Returns true if the privacy budget is infinite.

abstract __truediv__(other)#

Budgets can be divided by finite integer/float values > 0.

Return type:

PrivacyBudget

abstract __mul__(other)#

Budgets can be multiplied by finite integer/float values >= 0.

Return type:

PrivacyBudget

abstract __add__(other)#

Budgets can be added to other budgets of compatible types.

Addition is only supported so long as the result is still a valid budget (i.e. all parameters fall within valid ranges).

Return type:

PrivacyBudget

abstract __sub__(other)#

Budgets can be subtracted from other budgets of compatible types.

Subtraction is only supported so long as the result is still a valid budget (i.e. all parameters fall within valid ranges).

Subtracting anything from an infinite budget will return an infinite budget.

Return type:

PrivacyBudget

classmethod inf()#
Abstractmethod:

Return type:

PrivacyBudget

Get an infinite budget of this type.

class PureDPBudget(epsilon)#

Bases: PrivacyBudget

A privacy budget under pure differential privacy.

This privacy definition is also known as epsilon-differential privacy, and the associated value is the epsilon privacy parameter. The privacy definition can be found here.

Parameters:

epsilon (Union[int, float, tmlt.core.utils.exact_number.ExactNumber])

property value: tmlt.core.utils.exact_number.ExactNumber#

Return the value of the privacy budget as an ExactNumber.

For printing purposes, you should use the epsilon property instead, as it will represent the same value, but be more human readable.

Return type:

tmlt.core.utils.exact_number.ExactNumber

property epsilon: int | float#

Returns the value of epsilon as an int or float.

This is helpful for human readability. If you need to use the epsilon value in a computation, you should use self.value instead.

Return type:

Union[int, float]

property is_infinite: bool#

Returns true if epsilon is float(‘inf’).

Return type:

bool

__init__(epsilon)#

Construct a new PureDPBudget.

Parameters:

epsilon (Union[int, float, ExactNumber]) – The epsilon privacy parameter. Must be non-negative and cannot be NaN. To specify an infinite budget, set epsilon equal to float(‘inf’).

__truediv__(other)#

Divide this budget by a finite integer/float value > 0.

Return type:

PureDPBudget

__mul__(other)#

Multiply this budget by a finite integer/float value >= 0.

Return type:

PureDPBudget

__add__(other)#

Add this budget to another PureDPBudget or an ApproxDPBudget.

The resulting epsilon must be greater than zero, and the resulting delta (if any) must be in [0, 1].

Return type:

PrivacyBudget

__sub__(other)#

Subtract a PureDPBudget from this budget.

The resulting epsilon must greater than zero. Subtracting anything from an infinite budget will return an infinite budget.

Note that you cannot subtract an ApproxDPBudget from a PureDPBudget, though the reverse is allowed.

Return type:

PureDPBudget

classmethod inf()#

Get an infinite budget of this type.

Return type:

PureDPBudget

class ApproxDPBudget(epsilon, delta)#

Bases: PrivacyBudget

A privacy budget under approximate differential privacy.

This privacy definition is also known as (ε, δ)-differential privacy, and the associated privacy parameters are epsilon and delta. The formal definition can be found here.

Parameters:
  • epsilon (Union[int, float, tmlt.core.utils.exact_number.ExactNumber])

  • delta (Union[int, float, tmlt.core.utils.exact_number.ExactNumber])

property value: Tuple[tmlt.core.utils.exact_number.ExactNumber, tmlt.core.utils.exact_number.ExactNumber]#

Returns self._epsilon and self._delta as an ExactNumber tuple.

For printing purposes, you might want to use the epsilon and delta properties instead, as they will represent the same values, but be more human readable.

Return type:

Tuple[tmlt.core.utils.exact_number.ExactNumber, tmlt.core.utils.exact_number.ExactNumber]

property epsilon: int | float#

Returns the value of epsilon as an int or float.

This is helpful for human readability. If you need to use the epsilon value in a computation, you should use self.value[0] instead.

Return type:

Union[int, float]

property delta: int | float#

Returns the value of delta as an int or float.

This is helpful for human readability. If you need to use the delta value in a computation, you should use self.value[1] instead.

Return type:

Union[int, float]

property is_infinite: bool#

Returns true if epsilon is float(‘inf’) or delta is 1.

Return type:

bool

__init__(epsilon, delta)#

Construct a new ApproxDPBudget.

Parameters:
  • epsilon (Union[int, float, ExactNumber]) – The epsilon privacy parameter. Must be non-negative. To specify an infinite budget, set epsilon equal to float(‘inf’).

  • delta (Union[int, float, ExactNumber]) – The delta privacy parameter. Must be between 0 and 1 (inclusive). If delta is 0, this is equivalent to PureDP.

__eq__(other)#

Returns True if both ApproxDPBudgets are infinite or have equal values.

Return type:

bool

__truediv__(other)#

Divide this budget by a finite integer/float value > 0.

Return type:

ApproxDPBudget

__mul__(other)#

Multiply this budget by a finite integer/float value >= 0.

Return type:

ApproxDPBudget

__add__(other)#

Add this budget to another ApproxDPBudget or a PureDPBudget.

The resulting epsilon must greater than zero. If the resulting delta is >1 it will be rounded down to 1.

Addition is performed using basic composition, and the sum is therefore a (possibly loose) upper bound on the privacy loss from running two queries.

Return type:

ApproxDPBudget

__sub__(other)#

Subtract a PureDPBudget or ApproxDPBudget from this budget.

The resulting epsilon greater than zero, and the resulting delta must be in [0, 1]. Subtracting anything from an infinite budget will return an infinite budget.

Note that you can subtract a PureDPBudget from an ApproxDPBudget, though the reverse is not allowed.

Return type:

ApproxDPBudget

classmethod inf()#

Get an infinite budget of this type.

Return type:

ApproxDPBudget

class RhoZCDPBudget(rho)#

Bases: PrivacyBudget

A privacy budget under rho-zero-concentrated differential privacy.

The definition of rho-zCDP can be found in this paper under Definition 1.1.

Parameters:

rho (Union[int, float, tmlt.core.utils.exact_number.ExactNumber])

property value: tmlt.core.utils.exact_number.ExactNumber#

Return the value of the privacy budget as an ExactNumber.

For printing purposes, you should use the rho property instead, as it will represent the same value, but be more human readable.

Return type:

tmlt.core.utils.exact_number.ExactNumber

property rho: int | float#

Returns the value of rho as an int or float.

This is helpful for human readability. If you need to use the rho value in a computation, you should use self.value instead.

Return type:

Union[int, float]

property is_infinite: bool#

Returns true if rho is float(‘inf’).

Return type:

bool

__init__(rho)#

Construct a new RhoZCDPBudget.

Parameters:

rho (Union[int, float, ExactNumber]) – The rho privacy parameter. Rho must be non-negative and cannot be NaN. To specify an infinite budget, set rho equal to float(‘inf’).

__truediv__(other)#

Divide this budget by a finite integer/float value > 0.

Return type:

RhoZCDPBudget

__mul__(other)#

Multiply this budget by a finite integer/float value >= 0.

Return type:

RhoZCDPBudget

__add__(other)#

Add this budget to another RhoZCDPBudget.

The resulting rho must be greater than zero.

Return type:

RhoZCDPBudget

__sub__(other)#

Subtract a RhoZCDPBudget from this budget.

The resulting rho must be greater than zero. Subtracting anything from an infinite budget will return an infinite budget.

Return type:

RhoZCDPBudget

classmethod inf()#

Get an infinite budget of this type.

Return type:

RhoZCDPBudget