secretflow.security.privacy.accounting#
secretflow.security.privacy.accounting.gdp_accountant#
Functions:
|
Calculate mu from uniform subsampling. |
|
Calculate mu from Poisson subsampling. |
|
Calculate dual between mu-GDP and (epsilon, delta)-DP. |
|
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)[源代码]#
Calculate mu from uniform subsampling.
- 参数:
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)[源代码]#
Calculate mu from Poisson subsampling.
- 参数:
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.log_utils#
Functions:
|
Add two numbers in the log space. |
|
Subtract two numbers in the log space. |
|
Calculate log(erfc(x)) with high accuracy for large x. |
|
|
|
Calculate log(A_alpha) for integer alpha. |
|
Calculate log(A_alpha) for fractional alpha. |
|
Calculate log(A_alpha) for any positive finite alpha. |
- secretflow.security.privacy.accounting.log_utils.add_log(logx, logy)[源代码]#
Add two numbers in the log space.
- secretflow.security.privacy.accounting.log_utils.sub_log(logx, logy)[源代码]#
Subtract two numbers in the log space. The return value must be non-negative.
- secretflow.security.privacy.accounting.log_utils.erfc_log(x)[源代码]#
Calculate log(erfc(x)) with high accuracy for large x.
- secretflow.security.privacy.accounting.log_utils.log_alpha_int(q, sigma, alpha)[源代码]#
Calculate log(A_alpha) for integer alpha. 0 < q < 1.
secretflow.security.privacy.accounting.rdp_accountant#
Functions:
|
Comnpute RDP of the Sampled Gaussian mechanism at order alpha. |
|
Calculate RDP of the Sampled Gaussian Mechanism. |
|
Calculate delta given a list of RDP values and target epsilon. |
|
Calculate epsilon given a list of RDP values and target delta. |
|
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)[源代码]#
Comnpute RDP of the Sampled Gaussian mechanism at order alpha.
- 参数:
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
- 返回:
RDP at alpha, can be np.inf.
- secretflow.security.privacy.accounting.rdp_accountant.get_rdp(q: float, noise_multiplier: float, steps: int, orders)[源代码]#
Calculate RDP of the Sampled Gaussian Mechanism.
- 参数:
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.
- 返回:
The RDPs at all orders. Can be np.inf.
- secretflow.security.privacy.accounting.rdp_accountant.cal_delta(orders, rdp, eps: float)[源代码]#
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.
- 返回:
Pair of (delta, optimal_order).
- 抛出:
ValueError – If input is malformed.
- secretflow.security.privacy.accounting.rdp_accountant.cal_eps(orders, rdp, delta: float)[源代码]#
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.
- 返回:
Pair of (eps, optimal_order).
- 抛出:
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)[源代码]#
Calculates delta (or eps) for given eps (or delta) from RDP values.
- 参数:
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.
- 返回:
A tuple of epsilon, delta, and the optimal order.
- 抛出:
ValueError – If target_eps and target_delta are messed up.