An implementation of major general-purpose mechanisms for privatizing
statistics, models, and machine learners, within the framework of differential
privacy of Dwork et al. (2006)
diffpriv package makes privacy-aware data science in R easy.
diffpriv implements the formal framework of differential privacy: differentially-private mechanisms can safely release to untrusted third parties: statistics computed, models fit, or arbitrary structures derived on privacy-sensitive data. Due to the worst-case nature of the framework, mechanism development typically requires involved theoretical analysis.
diffpriv offers a turn-key approach to differential privacy by automating this process with sensitivity sampling in place of theoretical sensitivity analysis.
diffpriv is easy. From within R:
A typical example in differential privacy is privately releasing a simple
target function of privacy-sensitive input data
X. Say the mean of
## a target function we'd like to run on private data X, releasing the resulttarget <- function(X) mean(X)
First load the
diffpriv package (installed as above) and construct a chosen differentially-private mechanism for privatizing
## target seeks to release a numeric, so we'll use the Laplace mechanism---a## standard generic mechanism for privatizing numeric responseslibrary(diffpriv)mech <- DPMechLaplace(target = target)
mech on a dataset
X we must first determine the sensitivity of
target to small changes to input dataset. One avenue is to analytically bound sensitivity (on paper; see the vignette) and supply it via the
sensitivity argument of mechanism construction: in this case not hard if we assume bounded data, but in general sensitivity can be very non-trivial to calculate manually. The other approach, which we follow in this example, is sensitivity sampling: repeated probing of
target to estimate sensitivity automatically. We need only specify a distribution for generating random probe datasets;
sensitivitySampler() takes care of the rest. The price we pay for this convenience is the weaker form of random differential privacy.
## set a dataset sampling distribution, then estimate target sensitivity with## sufficient samples for subsequent mechanism responses to achieve random## differential privacy with confidence 1-gammadistr <- function(n) rnorm(n)mech <- sensitivitySampler(mech, oracle = distr, n = 5, gamma = 0.1)#> Sampling sensitivity with m=285 gamma=0.1 k=285[email protected] ## DPMech and subclasses are S4: slots accessed via @#>  0.8089517
With a sensitivity-calibrated mechanism in hand, we can release private responses on a dataset
X, displayed alongside the non-private response for comparison:
X <- c(0.328,-1.444,-0.511,0.154,-2.062) # length is sensitivitySampler() nr <- releaseResponse(mech, privacyParams = DPParamsEps(epsilon = 1), X = X)cat("Private response r$response: ", r$response,"\nNon-private response target(X):", target(X))#> Private response r$response: -1.119506#> Non-private response target(X): -0.707
The above example demonstrates the main components of
DPMechfor generic mechanisms that captures the non-private
targetand releases privatized responses from it. Current subclasses
DPMechGaussian: the Laplace and Gaussian mechanisms for releasing numeric responses with additive noise;
DPMechExponential: the exponential mechanism for privately optimizing over finite sets (which need not be numeric); and
DPMechBernstein: the Bernstein mechanism for privately releasing multivariate real-valued functions. See the bernstein vignette for more.
DPParamsEpsand subclasses for encapsulating privacy parameters.
DPMechsubclasses estimates target sensitivity necessary to run
DPMechgeneric mechanisms. This provides an easy alternative to exact sensitivity bounds requiring mathematical analysis. The sampler repeatedly probes
[email protected]to estimate sensitivity to data perturbation. Running mechanisms with obtained sensitivities yield random differential privacy.
diffpriv is an open-source package offered with a permissive MIT License. Please acknowledge use of
diffpriv by citing the paper on the sensitivity sampler:
Other relevant references to cite depending on usage:
bernsteinon: Bernstein approximations and use of
DPMechBernsteinfor private function release.
predict()generic implementation for fitting (non-iterated) Bernstein polynomial function approximations.
DPMechBernsteinclass implementing the Bernstein mechanism of Alda and Rubinstein (AAAI'2017), for privately releasing functions.
DPMechGaussianclass for the generic Gaussian mechanism to README, Vignette. Resolves #2
DPMechNumeric. Resolves #1
DPMechGaussianclass implementing the Gaussian mechanism, which achieves (epsilon,delta)-differential privacy by adding Gaussian noise to numeric responses calibrated by L2-norm sensitivity.
DPMechLaplaceunderneath a new
DPMechNumericwhich contains common methods,
dimis a special slot for S4).
DPMechLaplaceobjects can now be initialized without specifying non-private
dim. In such cases, the sensitivity sampler will perform an additional
targetprobe to determine