Skip to main content

entrenar/optim/dp/
budget.rs

1//! Privacy budget tracking.
2
3use serde::{Deserialize, Serialize};
4
5/// Privacy budget (epsilon, delta)
6#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
7pub struct PrivacyBudget {
8    /// Privacy loss parameter epsilon (smaller = more private)
9    pub epsilon: f64,
10    /// Probability of privacy breach delta (smaller = more private)
11    pub delta: f64,
12}
13
14impl PrivacyBudget {
15    /// Create a new privacy budget
16    pub fn new(epsilon: f64, delta: f64) -> Self {
17        Self { epsilon, delta }
18    }
19
20    /// Check if the budget allows the given epsilon
21    pub fn allows(&self, spent: f64) -> bool {
22        spent <= self.epsilon
23    }
24
25    /// Get remaining budget
26    pub fn remaining(&self, spent: f64) -> f64 {
27        (self.epsilon - spent).max(0.0)
28    }
29}
30
31impl Default for PrivacyBudget {
32    fn default() -> Self {
33        // Commonly used default: (8.0, 1e-5)
34        Self { epsilon: 8.0, delta: 1e-5 }
35    }
36}