opendp / smartnoise-sdk

Tools and service for differentially private processing of tabular and relational data
MIT License
254 stars 68 forks source link

Update OpenDP dependency to 0.9 #593

Closed Shoeboxam closed 3 months ago

Shoeboxam commented 8 months ago

OpenDP 0.9 has essentially no backwards-incompatible changes, but it does add an implementation of the exponential mechanism for private selection on a finite set:

import numpy as np
import opendp.prelude as dp
dp.enable_features("contrib")

# takes a vector of scores, one score per candidate
# returns the index of the selected candidate
scores_dataset = np.linspace(0, 10, num=11)
scale = 1.
domain = dp.vector_domain(dp.atom_domain(T=float))

# standard use of the mechanism
metric = dp.linf_distance(T=float)
meas = dp.m.make_report_noisy_max_gumbel(domain, metric, scale, optimize="max")

print(meas(scores_dataset))
assert meas.map(2.) == 4.

# when the scoring function is monotonic (scores always vary in the same direction)
metric = dp.linf_distance(T=float, monotonic=True)
meas = dp.m.make_report_noisy_max_gumbel(domain, metric, scale, optimize="max")

print(meas(scores_dataset))
assert meas.map(2.) == 2.

Can this be used to replace the various implementations of the exponential mechanism in the SDK? Thanks.

joshua-oss commented 3 months ago

Updated to 0.10.0