GaussianDifferentialPrivacy<T>
Models & Types · AiDotNet.FederatedLearning.Privacy
Implements differential privacy using the Gaussian mechanism.
Inheritance: FederatedLearningComponentBase<T> → PrivacyMechanismBase<Dictionary<string, T[]>, T> → GaussianDifferentialPrivacy<T>
How It Works
The Gaussian mechanism provides (ε, δ)-differential privacy by adding calibrated Gaussian (normal distribution) noise to model parameters. This is one of the most widely used privacy mechanisms in federated learning.
For Beginners: Differential privacy is like adding static to a phone conversation. You add just enough noise that individual voices can’t be identified, but the overall message still gets through clearly.
How Gaussian Differential Privacy works:
- Clip gradients/parameters to bound sensitivity (maximum change any single data point can cause)
- Add Gaussian noise: noise ~ N(0, σ²) where σ depends on ε, δ, and sensitivity
- The noise calibration ensures (ε, δ)-DP guarantee
Mathematical formulation:
- Sensitivity Δ: Maximum L2 norm of gradient for any single training example
- Noise scale σ = (Δ/ε) × sqrt(2 × ln(1.25/δ))
- For each parameter w: w_private = w + N(0, σ²)
Privacy parameters:
- ε (epsilon): Privacy budget - smaller is more private
- ε = 0.1: Very strong privacy, significant noise
- ε = 1.0: Strong privacy, moderate noise (recommended)
- ε = 10: Weak privacy, minimal noise
- δ (delta): Failure probability - should be very small
- Typically δ = 1/n² where n is dataset size
- Common choice: δ = 1e-5
For example, protecting hospital patient data:
- Original gradient: [0.5, -0.3, 0.8, -0.2]
- Clip to max norm 1.0: [0.45, -0.27, 0.72, -0.18] (clipped)
- Add Gaussian noise with σ=0.1: [0.47, -0.29, 0.75, -0.21]
- Result: Individual patient influence is masked by noise
Privacy composition:
- Each time you share data, you consume privacy budget
- After T rounds with ε per round: total ε_total ≈ ε × sqrt(2T × ln(1/δ))
- This is more efficient than naive composition (ε × T)
Trade-offs:
- More privacy (smaller ε) → more noise → lower accuracy
- Less privacy (larger ε) → less noise → higher accuracy
- Must find acceptable balance for your application
When to use Gaussian DP:
- Need provable privacy guarantees
- Working with sensitive data (healthcare, finance)
- Regulatory requirements (GDPR, HIPAA)
- Publishing models or sharing with untrusted parties
Reference: Dwork, C., & Roth, A. (2014). “The Algorithmic Foundations of Differential Privacy.” Abadi, M., et al. (2016). “Deep Learning with Differential Privacy.” CCS 2016.
Constructors
| Constructor | Summary |
|---|---|
GaussianDifferentialPrivacy(double clipNorm, int? randomSeed) |
Initializes a new instance of the GaussianDifferentialPrivacy class. |
Methods
| Method | Summary |
|---|---|
Dictionary<string, T[]> ApplyPrivacy(Dictionary<string, T[]> model, double epsilon, double delta) |
Applies differential privacy to model parameters by adding calibrated Gaussian noise. |
double GetClipNorm() |
Gets the gradient clipping norm used for sensitivity bounding. |
double GetPrivacyBudgetConsumed() |
Gets the total privacy budget consumed so far. |
string GetMechanismName() |
Gets the name of the privacy mechanism. |
void ResetPrivacyBudget() |
Resets the privacy budget counter. |