pub struct DifferentialPrivacy { /* private fields */ }Expand description
Differential privacy for gradient protection
Implementations§
Source§impl DifferentialPrivacy
impl DifferentialPrivacy
Sourcepub fn new(
epsilon: f64,
delta: f64,
sensitivity: f64,
mechanism: DPMechanism,
) -> Self
pub fn new( epsilon: f64, delta: f64, sensitivity: f64, mechanism: DPMechanism, ) -> Self
Create a new differential privacy instance
Sourcepub fn add_gaussian_noise(
&mut self,
gradient: &mut [f32],
) -> Result<(), GradientError>
pub fn add_gaussian_noise( &mut self, gradient: &mut [f32], ) -> Result<(), GradientError>
Add Gaussian noise to gradient (for DP-SGD) Calibrated according to sensitivity and privacy parameters
Sourcepub fn add_laplacian_noise(
&mut self,
gradient: &mut [f32],
) -> Result<(), GradientError>
pub fn add_laplacian_noise( &mut self, gradient: &mut [f32], ) -> Result<(), GradientError>
Add Laplacian noise to gradient Calibrated according to L1 sensitivity and privacy parameters
Sourcepub fn apply_dp_sgd(
&mut self,
gradient: &mut [f32],
clip_norm: f32,
) -> Result<(), GradientError>
pub fn apply_dp_sgd( &mut self, gradient: &mut [f32], clip_norm: f32, ) -> Result<(), GradientError>
Apply DP-SGD (Differential Private Stochastic Gradient Descent) This clips gradients and adds noise
Sourcepub fn remaining_budget(&self) -> f64
pub fn remaining_budget(&self) -> f64
Get remaining privacy budget
Sourcepub fn is_budget_exhausted(&self) -> bool
pub fn is_budget_exhausted(&self) -> bool
Check if privacy budget is exhausted
Sourcepub fn get_privacy_params(&self) -> (f64, f64)
pub fn get_privacy_params(&self) -> (f64, f64)
Get privacy parameters
Sourcepub fn calculate_noise_multiplier(
epsilon: f64,
delta: f64,
sensitivity: f64,
) -> f64
pub fn calculate_noise_multiplier( epsilon: f64, delta: f64, sensitivity: f64, ) -> f64
Calculate noise multiplier for given privacy parameters Used in DP-SGD implementations
Sourcepub fn add_gaussian_noise_sens(&self, gradient: &mut [f32], sensitivity: f32)
pub fn add_gaussian_noise_sens(&self, gradient: &mut [f32], sensitivity: f32)
Add calibrated Gaussian noise to a gradient slice (stateless, sensitivity supplied).
σ = sensitivity × √(2 ln(1.25/δ)) / ε
Uses Box-Muller transform for Normal sampling (no rand_distr dependency).
Sourcepub fn add_laplace_noise_sens(&self, gradient: &mut [f32], sensitivity: f32)
pub fn add_laplace_noise_sens(&self, gradient: &mut [f32], sensitivity: f32)
Add calibrated Laplace noise to a gradient slice (stateless, sensitivity supplied).
scale = sensitivity / ε
Sourcepub fn clip_l2(&self, gradient: &mut [f32], max_norm: f32)
pub fn clip_l2(&self, gradient: &mut [f32], max_norm: f32)
Clip gradient in-place to L2 norm ≤ max_norm.
Sourcepub fn remaining_budget_after(&self, rounds_used: u32) -> f32
pub fn remaining_budget_after(&self, rounds_used: u32) -> f32
Return remaining epsilon budget after rounds_used rounds, each costing ε/100.
This mirrors the per-round consumption used by add_gaussian_noise (mutable version).
Sourcepub fn is_exhausted_after(&self, rounds_used: u32) -> bool
pub fn is_exhausted_after(&self, rounds_used: u32) -> bool
True if the budget would be exhausted after rounds_used rounds.
Auto Trait Implementations§
impl Freeze for DifferentialPrivacy
impl RefUnwindSafe for DifferentialPrivacy
impl Send for DifferentialPrivacy
impl Sync for DifferentialPrivacy
impl Unpin for DifferentialPrivacy
impl UnsafeUnpin for DifferentialPrivacy
impl UnwindSafe for DifferentialPrivacy
Blanket Implementations§
impl<T> Allocation for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more