secretflow.security.privacy.accounting package#

Submodules#

secretflow.security.privacy.accounting.gdp_accountant module#

Functions:

cal_mu_uniform(step, noise_multiplier, ...)

Calculate mu from uniform subsampling.

cal_mu_poisson(step, noise_multiplier, ...)

Calculate mu from Poisson subsampling.

delta_gaussian(eps, mu)

Calculate dual between mu-GDP and (epsilon, delta)-DP.

get_eps_from_mu(mu, delta)

Get epsilon from mu given delta via inverse dual.

secretflow.security.privacy.accounting.gdp_accountant.cal_mu_uniform(step: int, noise_multiplier, num_samples, batch_size)[source]#

Calculate mu from uniform subsampling.

Parameters
  • step – The current step of model training or prediction.

  • epnoise_multipliers – Epsilon for pure DP.

  • batch_size – Batch size.

  • num_samples – Number of all samples.

secretflow.security.privacy.accounting.gdp_accountant.cal_mu_poisson(step: int, noise_multiplier, num_samples, batch_size)[source]#

Calculate mu from Poisson subsampling.

Parameters
  • step – The current step of model training or prediction.

  • epnoise_multipliers – Epsilon for pure DP.

  • batch_size – Batch size.

  • num_samples – Number of all samples.

secretflow.security.privacy.accounting.gdp_accountant.delta_gaussian(eps, mu)[source]#

Calculate dual between mu-GDP and (epsilon, delta)-DP.

Parameters
  • mu – The parameters of the GDP.

  • eps – The parameters of the (epsilon, delta)-DP.

secretflow.security.privacy.accounting.gdp_accountant.get_eps_from_mu(mu, delta)[source]#

Get epsilon from mu given delta via inverse dual.

Parameters
  • mu – The parameters of the GDP.

  • delta – The parameters of the (epsilon, delta)-DP.

secretflow.security.privacy.accounting.log_utils module#

Functions:

add_log(logx, logy)

Add two numbers in the log space.

sub_log(logx, logy)

Subtract two numbers in the log space.

erfc_log(x)

Calculate log(erfc(x)) with high accuracy for large x.

comb_log(n, k)

log_alpha_int(q, sigma, alpha)

Calculate log(A_alpha) for integer alpha.

log_alpha_frac(q, sigma, alpha)

Calculate log(A_alpha) for fractional alpha.

log_alpha(q, sigma, alpha)

Calculate log(A_alpha) for any positive finite alpha.

secretflow.security.privacy.accounting.log_utils.add_log(logx, logy)[source]#

Add two numbers in the log space.

secretflow.security.privacy.accounting.log_utils.sub_log(logx, logy)[source]#

Subtract two numbers in the log space. The return value must be non-negative.

secretflow.security.privacy.accounting.log_utils.erfc_log(x)[source]#

Calculate log(erfc(x)) with high accuracy for large x.

secretflow.security.privacy.accounting.log_utils.comb_log(n, k)[source]#
secretflow.security.privacy.accounting.log_utils.log_alpha_int(q, sigma, alpha)[source]#

Calculate log(A_alpha) for integer alpha. 0 < q < 1.

secretflow.security.privacy.accounting.log_utils.log_alpha_frac(q, sigma, alpha)[source]#

Calculate log(A_alpha) for fractional alpha. 0 < q < 1.

secretflow.security.privacy.accounting.log_utils.log_alpha(q, sigma, alpha)[source]#

Calculate log(A_alpha) for any positive finite alpha.

secretflow.security.privacy.accounting.rdp_accountant module#

Functions:

rdp_core(q, noise_multiplier, alpha)

Comnpute RDP of the Sampled Gaussian mechanism at order alpha.

get_rdp(q, noise_multiplier, steps, orders)

Calculate RDP of the Sampled Gaussian Mechanism.

cal_delta(orders, rdp, eps)

Calculate delta given a list of RDP values and target epsilon.

cal_eps(orders, rdp, delta)

Calculate epsilon given a list of RDP values and target delta.

get_privacy_spent_rdp(orders, rdp[, ...])

Calculates delta (or eps) for given eps (or delta) from RDP values.

secretflow.security.privacy.accounting.rdp_accountant.rdp_core(q: float, noise_multiplier: float, alpha: float)[source]#

Comnpute RDP of the Sampled Gaussian mechanism at order alpha.

Parameters
  • q – The sampling rate.

  • noise_multiplier – The noise_multiplier used for calculating the std of the additive Gaussian noise.

  • alpha – The order at which RDP is cald

Returns

RDP at alpha, can be np.inf.

secretflow.security.privacy.accounting.rdp_accountant.get_rdp(q: float, noise_multiplier: float, steps: int, orders)[source]#

Calculate RDP of the Sampled Gaussian Mechanism.

Parameters
  • q – The sampling rate.

  • noise_multiplier – The ratio of the standard deviation of the Gaussian noise to the l2-sensitivity of the function to which it is added

  • steps – The number of steps.

  • orders – An array (or a scalar) of RDP orders.

Returns

The RDPs at all orders. Can be np.inf.

secretflow.security.privacy.accounting.rdp_accountant.cal_delta(orders, rdp, eps: float)[source]#

Calculate delta given a list of RDP values and target epsilon. :param orders: An array (or a scalar) of orders. :param rdp: A list (or a scalar) of RDP guarantees. :param eps: The target epsilon.

Returns

Pair of (delta, optimal_order).

Raises

ValueError – If input is malformed.

secretflow.security.privacy.accounting.rdp_accountant.cal_eps(orders, rdp, delta: float)[source]#

Calculate epsilon given a list of RDP values and target delta. :param orders: An array (or a scalar) of orders. :param rdp: A list (or a scalar) of RDP guarantees. :param delta: The target delta.

Returns

Pair of (eps, optimal_order).

Raises

ValueError – If input is malformed.

secretflow.security.privacy.accounting.rdp_accountant.get_privacy_spent_rdp(orders, rdp, target_eps: Optional[float] = None, target_delta: Optional[float] = None)[source]#

Calculates delta (or eps) for given eps (or delta) from RDP values.

Parameters
  • orders – An array (or a scalar) of RDP orders.

  • rdp – An array of RDP values. Must be of the same length as the orders list.

  • target_eps – If not None, the epsilon for which we cal the corresponding delta.

  • target_delta – If not None, the delta for which we cal the corresponding epsilon. Exactly one of target_eps and target_delta must be None.

Returns

A tuple of epsilon, delta, and the optimal order.

Raises

ValueError – If target_eps and target_delta are messed up.

Module contents#