Class LaplaceNoise

  • All Implemented Interfaces:
    Noise

    public class LaplaceNoise
    extends java.lang.Object
    implements Noise
    Generates and adds Laplace noise to a raw piece of numerical data such that the result is securely differentially private.

    The Laplace noise is generated according to the geometric sampling mechanism described here. This approach is robust against unintentional privacy leaks due to artifacts of floating point arithmetic.

    • Constructor Summary

      Constructors 
      Constructor Description
      LaplaceNoise()
      Returns a Noise instance initialized with a secure randomness source.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      double addNoise​(double x, double l1Sensitivity, double epsilon, java.lang.Double delta)
      double addNoise​(double x, int l0Sensitivity, double lInfSensitivity, double epsilon, java.lang.Double delta)
      Adds Laplace noise to x such that the output is epsilon-differentially private, with respect to the specified L_0 and L_inf sensitivities.
      long addNoise​(long x, int l0Sensitivity, long lInfSensitivity, double epsilon, java.lang.Double delta)
      Adds Laplace noise to the integer x such that the output is epsilon-differentially private, with respect to the specified L_0 and L_inf sensitivities.
      long addNoise​(long x, long l1Sensitivity, double epsilon, java.lang.Double delta)
      ConfidenceInterval computeConfidenceInterval​(double noisedX, int l0Sensitivity, double lInfSensitivity, double epsilon, java.lang.Double delta, double alpha)
      Computes a confidence interval that contains the raw value x passed to addNoise(double, int, double, double, Double) with a probability equal to 1 - alpha based on the specified noisedX and noise parameters.
      ConfidenceInterval computeConfidenceInterval​(long noisedX, int l0Sensitivity, long lInfSensitivity, double epsilon, java.lang.Double delta, double alpha)
      Computes a confidence interval that contains the raw integer value x passed to addNoise(long, int, long, double, Double) with a probability greater or equal to 1 - alpha based on the specified noisedX and noise parameters.
      double computeQuantile​(double rank, double x, int l0Sensitivity, double lInfSensitivity, double epsilon, java.lang.Double delta)
      Computes the quantile z satisfying Pr[Y <= z] = rank for a Laplace random variable Y with mean x and variance according to the specified privacy parameters.
      com.google.differentialprivacy.SummaryOuterClass.MechanismType getMechanismType()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • LaplaceNoise

        public LaplaceNoise()
        Returns a Noise instance initialized with a secure randomness source.
    • Method Detail

      • addNoise

        public double addNoise​(double x,
                               int l0Sensitivity,
                               double lInfSensitivity,
                               double epsilon,
                               @Nullable
                               java.lang.Double delta)
        Adds Laplace noise to x such that the output is epsilon-differentially private, with respect to the specified L_0 and L_inf sensitivities. Note that delta must be set to null because it does not parameterize Laplace noise. Moreover, epsilon must be at least 2^-50.
        Specified by:
        addNoise in interface Noise
      • addNoise

        public double addNoise​(double x,
                               double l1Sensitivity,
                               double epsilon,
                               @Nullable
                               java.lang.Double delta)
        See addNoise(double, int, double, double, Double).

        As opposed to the latter method, this accepts the L_1 sensitivity of x directly instead of the L_0 and L_Inf proxies. This should be used in settings where it is feasible or more convenient to calculate the L_1 sensitivity directly.

      • addNoise

        public long addNoise​(long x,
                             int l0Sensitivity,
                             long lInfSensitivity,
                             double epsilon,
                             @Nullable
                             java.lang.Double delta)
        Adds Laplace noise to the integer x such that the output is epsilon-differentially private, with respect to the specified L_0 and L_inf sensitivities. Note that delta must be set to null because it does not parameterize Laplace noise. Moreover, epsilon must be at least 2^-50.
        Specified by:
        addNoise in interface Noise
      • addNoise

        public long addNoise​(long x,
                             long l1Sensitivity,
                             double epsilon,
                             @Nullable
                             java.lang.Double delta)
        See addNoise(long, int, long, double, Double).

        As opposed to the latter method, this accepts the L_1 sensitivity of x directly instead of the L_0 and L_Inf proxies. This should be used in settings where it is feasible or more convenient to calculate the L_1 sensitivity directly.

      • getMechanismType

        public com.google.differentialprivacy.SummaryOuterClass.MechanismType getMechanismType()
        Specified by:
        getMechanismType in interface Noise
      • computeConfidenceInterval

        public ConfidenceInterval computeConfidenceInterval​(double noisedX,
                                                            int l0Sensitivity,
                                                            double lInfSensitivity,
                                                            double epsilon,
                                                            @Nullable
                                                            java.lang.Double delta,
                                                            double alpha)
        Computes a confidence interval that contains the raw value x passed to addNoise(double, int, double, double, Double) with a probability equal to 1 - alpha based on the specified noisedX and noise parameters. Note that delta must be set to null because it does not parameterize Laplace noise. Moreover, epsilon must be at least 2^-50.

        Refer to this doc for more information.

        Specified by:
        computeConfidenceInterval in interface Noise
      • computeConfidenceInterval

        public ConfidenceInterval computeConfidenceInterval​(long noisedX,
                                                            int l0Sensitivity,
                                                            long lInfSensitivity,
                                                            double epsilon,
                                                            @Nullable
                                                            java.lang.Double delta,
                                                            double alpha)
        Computes a confidence interval that contains the raw integer value x passed to addNoise(long, int, long, double, Double) with a probability greater or equal to 1 - alpha based on the specified noisedX and noise parameters. Note that delta must be set to null because it does not parameterize Laplace noise. Moreover, epsilon must be at least 2^-50.

        Refer to this doc for more information.

        Specified by:
        computeConfidenceInterval in interface Noise
      • computeQuantile

        public double computeQuantile​(double rank,
                                      double x,
                                      int l0Sensitivity,
                                      double lInfSensitivity,
                                      double epsilon,
                                      @Nullable
                                      java.lang.Double delta)
        Computes the quantile z satisfying Pr[Y <= z] = rank for a Laplace random variable Y with mean x and variance according to the specified privacy parameters.
        Specified by:
        computeQuantile in interface Noise