Skip to content

Commit

Permalink
Add further todos
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Ristea committed Jul 15, 2021
1 parent cdb563f commit 71ac493
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions diffprivlib/mechanisms/snapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ def __init__(self, *, epsilon, sensitivity, lower, upper):
super().__init__(epsilon=epsilon, delta=0.0, sensitivity=sensitivity)
TruncationAndFoldingMixin.__init__(self, lower=lower, upper=upper)
# scale and center bounds around 0
self.bound = (self.upper - self.lower) / 2.0 / self.sensitivity
# todo: bound should be updated if upper, lower, or sensitivity changed
self._bound = (self.upper - self.lower) / 2.0 / self.sensitivity

def _check_all(self, value):
super()._check_all(value)
Expand All @@ -68,10 +69,10 @@ def _check_all(self, value):
return True

def _truncate(self, value):
if value > self.bound:
return self.bound
if value < -self.bound:
return -self.bound
if value > self._bound:
return self._bound
if value < -self._bound:
return -self._bound

return value

Expand All @@ -89,7 +90,7 @@ def effective_epsilon(self):
# as per section 5.2 of Mironov
# 1/λ + 12Bη/λ + 2η
machine_epsilon = np.finfo(float).epsneg
return self.epsilon + 12.0 * self.bound * self.epsilon + 2.0 * machine_epsilon
return self.epsilon + 12.0 * self._bound * self.epsilon + 2.0 * machine_epsilon

def _scale_and_offset_value(self, value):
"""
Expand All @@ -98,10 +99,10 @@ def _scale_and_offset_value(self, value):
:return: value offset to be centered on 0 and scaled to sensitivity 1
"""
value_scaled = value / self.sensitivity
return value_scaled - self.bound - (self.lower / self.sensitivity)
return value_scaled - self._bound - (self.lower / self.sensitivity)

def _reverse_scale_and_offset_value(self, value):
return (value + self.bound) * self.sensitivity + self.lower
return (value + self._bound) * self.sensitivity + self.lower

def _get_nearest_power_of_2(self, x):
# todo: extract from class?
Expand All @@ -124,6 +125,7 @@ def _round_to_nearest_power_of_2(self, value):
return value - remainder

def _sample_laplace(self):
# todo: only produces integer multiples of 2^-53; replace with _sample_uniform
unif_rv = self._rng.random() - 0.5
# Using crlibm, as suggested in Mironov paper
# no need for sensitivity already scaled down to sensitivity 1
Expand Down

0 comments on commit 71ac493

Please sign in to comment.