Skip to content

Commit

Permalink
clamping gaussian noise multiplier
Browse files Browse the repository at this point in the history
  • Loading branch information
andicuko committed Mar 20, 2024
1 parent 8dc9795 commit f619931
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 19 deletions.
10 changes: 1 addition & 9 deletions src/differential_privacy/aggregates.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
use crate::{
builder::{With, WithIterator},
data_type::DataTyped,
differential_privacy::dp_event::DpEvent,
differential_privacy::{dp_event, DpRelation, Error, Result},
expr::{aggregate::{self, Aggregate}, AggregateColumn, Expr, Column, Identifier},
privacy_unit_tracking::PupRelation,
relation::{field::Field, Map, Reduce, Relation, Variant},
DataType, Ready,
builder::{With, WithIterator}, data_type::DataTyped, differential_privacy::{dp_event::{self, DpEvent}, DpRelation, Error, Result}, display::Dot, expr::{aggregate::{self, Aggregate}, AggregateColumn, Column, Expr, Identifier}, privacy_unit_tracking::PupRelation, relation::{field::Field, Map, Reduce, Relation, Variant}, DataType, Ready

};
use std::{cmp, collections::HashMap, ops::Deref};
Expand Down Expand Up @@ -78,7 +71,6 @@ impl Relation {
// Cf. Theorem A.1. in (Dwork, Roth et al. 2014)
log::warn!("Warning, epsilon>1 the gaussian mechanism applied will not be exactly epsilon,delta-DP!")
}

let number_of_agg = bounds.len() as f64;
let (dp_relation, dp_event) = if number_of_agg > 0. {
let noise_multipliers = bounds
Expand Down
3 changes: 2 additions & 1 deletion src/differential_privacy/dp_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ impl From<Vec<DpEvent>> for DpEvent {
}

pub fn gaussian_noise(epsilon: f64, delta: f64, sensitivity: f64) -> f64 {
(2. * (1.25_f64 / delta).ln()).sqrt() * sensitivity / epsilon
// it can be inf so we clamp the results between 0 and f64::MAX
((2. * (1.25_f64 / delta).ln()).sqrt() * sensitivity / epsilon).clamp(0, f64::MAX)
}

pub fn gaussian_tau(epsilon: f64, delta: f64, sensitivity: f64) -> f64 {
Expand Down
14 changes: 5 additions & 9 deletions src/rewriting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ mod tests {
("CODE", DataType::integer()),
("DESCRIPTION", DataType::text()),
("BASE_ENCOUNTER_COST", DataType::float()),
("TOTAL_CLAIM_COST", DataType::float_min(-1.,)),
("TOTAL_CLAIM_COST", DataType::float_min(-1.)),
("PAYER_COVERAGE", DataType::float()),
("REASON_CODE", DataType::integer()),
("REASONDESCRIPTION", DataType::integer()),
Expand All @@ -593,18 +593,14 @@ mod tests {
let dp_parameters = DpParameters::from_epsilon_delta(1., 1e-3);

let queries = [
// r#"
// SELECT
// 1/"TOTAL_CLAIM_COST"
// FROM private.axa_encounters e
// "#,
r#"
SELECT
"ENCOUNTERCLASS",
COUNT(p."Id") as patient_count,
SUM("TOTAL_CLAIM_COST") as total_cost
FROM private.axa_patients p
JOIN private.axa_encounters e
SUM("TOTAL_CLAIM_COST") as sum_cost,
AVG("TOTAL_CLAIM_COST") as avg_cost
FROM axa_patients p
JOIN axa_encounters e
ON p."Id" = e."PATIENT"
GROUP BY "ENCOUNTERCLASS"
"#,
Expand Down

0 comments on commit f619931

Please sign in to comment.