Closed naoise-h closed 1 year ago
Base: 99.49% // Head: 99.38% // Decreases project coverage by -0.11%
:warning:
Coverage data is based on head (
ffd1b92
) compared to base (b3d6a72
). Patch coverage: 98.21% of modified lines in pull request are covered.
:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.
This pull request introduces 1 alert when merging a0ddbc2c9a6609726bfbe779e412d617f593d2cf into b3d6a722e1eae9f9576690e42743afb2bc247db9 - view on LGTM.com
new alerts:
This PR adds the
random_state
parameter to all diffprivlib methods (mechanisms, models and tools) to allow for the seeding of the random number generator (RNG). This fixes #31Description
Random State
All functions in diffprivlib that implement differential privacy (i.e., mechanisms, models and tools) now have a
random_state
parameter, to which an RNG seed can be passed, or a RandomState instance itself. Diffprivlib largely follows the same standard as scikit-learn , in that deterministic behaviour of a function requires an integer seed (i.e.,random_state=42
). For deterministic behaviour across a script, a RandomState instance should be seeded (i.e.,rng = np.random.RandomState(42)
orrng = dp.utils.check_random_state(42)
), and passed to all relevant functions.If no random state is passed (i.e.,
random_state=None
), diffprivlib tries to use a cryptographically secure pseudorandom number generator (CSPRNG) in its mechanisms for generating noise to satisfy differential privacy, using the secrets library. This applies even whenrandom_state=None
is passed to a function in themodels
andtools
modules. At the time of this pull request, a CSPRNG is used in all mechanisms except for the Bingham and Staircase mechanisms.Logistic Regression
Separately, this PR also correctly implements the scikit-learn loss module for the logistic regression classifier. This first appeared in sklearn 1.1.0, and diffprivlib includes backwards compatibility for older versions of scikit-learn that are still supported.