Function smartnoise_runtime::utilities::mechanisms::exponential_mechanism[][src]

pub fn exponential_mechanism<T>(
    epsilon: f64,
    sensitivity: f64,
    candidate_set: &[T],
    utilities: Vec<f64>,
    enforce_constant_time: bool
) -> Result<T> where
    T: Clone

Returns data element according to the Exponential mechanism.

Arguments

NOTE: This implementation is likely non-private because of the difference between theory on the real numbers and floating-point numbers. See Ilvento 2019 for more information on the problem and a proposed fix.

Example

use ndarray::prelude::*;
use smartnoise_runtime::utilities::mechanisms::exponential_mechanism;
// create utility function
pub fn utility(x:&f64) -> f64 {
    let util = *x as f64;
    return util;
}


// create sample data
let xs: Vec<f64> = vec![1., 2., 3., 4., 5.];
let utilities: Vec<f64> = xs.iter().map(utility).collect();
let ans = exponential_mechanism(1.0, 1.0, &xs, utilities, false);