smartnoise-sdk icon indicating copy to clipboard operation
smartnoise-sdk copied to clipboard

Update OpenDP dependency to 0.9

Open Shoeboxam opened this issue 11 months ago • 0 comments

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.

Shoeboxam avatar Feb 26 '24 23:02 Shoeboxam