Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Interpretml Interpret GaussianDistribution

From Leeroopedia


Knowledge Sources
Domains Machine_Learning, EBM_Core
Last Updated 2026-02-07 12:00 GMT

Overview

GaussianDistribution is a C++ header module that provides a secure Gaussian noise generation mechanism for differential privacy, ported from Google's differential privacy library.

Description

This header implements the GaussianDistribution class and supporting utility functions for generating Gaussian-distributed random noise with cryptographic security guarantees. The implementation is derived from Google's differential privacy library and is licensed under Apache License 2.0.

The Gaussian noise is generated using a binomial-based sampling technique based on Bringmann et al.'s rejection sampling approach ("Internal DLA: Efficient Simulation of a Physical Growth Model"). Key components include:

  • GaussianDistribution class: Main class constructed with a standard deviation parameter. Its Sample method generates Gaussian-distributed noise scaled by a given sensitivity.
  • SampleBinomial: Implements binomial-to-Gaussian approximation using rejection sampling with geometric random variates.
  • SampleGeometric: Generates geometric random samples using fair coin flips.
  • ApproximateBinomialProbability: Approximates the probability mass function of a binomial distribution per Lemma 7 of the secure noise generation specification.
  • UniformDouble: Generates uniformly distributed doubles in [0, 1] using a technique from Google's differential privacy library that properly handles floating-point precision.
  • Geometric: Counts leading zeros to generate geometric random variates efficiently.
  • CountLeadingZeroes64: Portable implementation from Abseil for counting leading zeros in 64-bit integers.

The bound kBinomialBound = 2^57 is chosen to limit the chance of sampling inaccuracies due to overflow to approximately 2^-45.

Usage

This module is used when training EBM models with differential privacy enabled. The Gaussian noise is added to gradient and hessian statistics during boosting to ensure privacy guarantees. The noise scale is controlled by the privacy budget (epsilon) parameter.

Code Reference

Source Location

Signature

class GaussianDistribution final {
    double stddev_;

public:
    inline GaussianDistribution(double stddev);

    template<typename TRng>
    inline double Sample(TRng& rng, double scale);

    template<typename TRng>
    inline double SampleBinomial(TRng& rng, double sqrt_n);

    template<typename TRng>
    inline int SampleGeometric(TRng& rng);

    inline double GetGranularity(double scale) const;
};

// Supporting functions
inline static double ApproximateBinomialProbability(double sqrt_n, int64_t m);
template<typename TRng> inline static uint64_t Geometric(TRng& rng);
template<typename TRng> inline static double UniformDouble(TRng& rng);
template<typename TRng> inline static bool CoinFlip(TRng& rng);
inline static double GetNextPowerOfTwo(double n);
inline static int CountLeadingZeroes64(uint64_t x);

I/O Contract

Inputs

Name Type Required Description
stddev double Yes Standard deviation of the Gaussian distribution (constructor parameter)
rng TRng& Yes Random number generator (template parameter, must support Next() method)
scale double Yes Scaling factor for the noise (related to sensitivity/epsilon)

Outputs

Name Type Description
Sample return double A Gaussian-distributed random noise value with specified standard deviation and scale

Usage Examples

Pipeline Context

# This C++ module is called internally via the native bindings
# when differential privacy is enabled during boosting
from interpret.glassbox import ExplainableBoostingClassifier
ebm = ExplainableBoostingClassifier()
# Gaussian noise is added to gradient statistics when DP is enabled
ebm.fit(X, y)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment