Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self):
super().__init__()
TruncationAndFoldingMixin.__init__(self)
"""
self.check_inputs(value)
if self._scale is None:
self._scale = - self._epsilon / self._sensitivity
# Need to account for overlap of 0-value between distributions of different sign
unif_rv = random() - 0.5
unif_rv *= 1 + np.exp(self._scale)
sgn = -1 if unif_rv < 0 else 1
# Use formula for geometric distribution, with ratio of exp(-epsilon/sensitivity)
return int(np.round(value + sgn * np.floor(np.log(sgn * unif_rv) / self._scale)))
class GeometricTruncated(Geometric, TruncationAndFoldingMixin):
"""
The truncated geometric mechanism, where values that fall outside a pre-described range are mapped back to the
closest point within the range.
"""
def __init__(self):
super().__init__()
TruncationAndFoldingMixin.__init__(self)
def __repr__(self):
output = super().__repr__()
output += TruncationAndFoldingMixin.__repr__(self)
return output
def set_bounds(self, lower, upper):
"""Sets the lower and upper bounds of the mechanism.
def __repr__(self):
output = super().__repr__()
output += TruncationAndFoldingMixin.__repr__(self)
return output
def __init__(self):
super().__init__()
TruncationAndFoldingMixin.__init__(self)
return super().set_bounds(lower, upper)
@copy_docstring(DPMechanism.get_bias)
def get_bias(self, value):
pass
@copy_docstring(Geometric.randomise)
def randomise(self, value):
TruncationAndFoldingMixin.check_inputs(self, value)
noisy_value = super().randomise(value)
return int(np.round(self._truncate(noisy_value)))
class GeometricFolded(Geometric, TruncationAndFoldingMixin):
"""
The folded geometric mechanism, where values outside a pre-described range are folded back toward the domain around
the closest point within the domain.
Half-integer bounds are permitted.
"""
def __init__(self):
super().__init__()
TruncationAndFoldingMixin.__init__(self)
def __repr__(self):
output = super().__repr__()
output += TruncationAndFoldingMixin.__repr__(self)
return output
def set_bounds(self, lower, upper):
def __repr__(self):
output = super().__repr__()
output += TruncationAndFoldingMixin.__repr__(self)
return output
@copy_docstring(Laplace.check_inputs)
def check_inputs(self, value):
super().check_inputs(value)
TruncationAndFoldingMixin.check_inputs(self, value)
return True
@copy_docstring(Laplace.randomise)
def randomise(self, value):
TruncationAndFoldingMixin.check_inputs(self, value)
noisy_value = super().randomise(value)
return self._truncate(noisy_value)
class LaplaceFolded(Laplace, TruncationAndFoldingMixin):
"""
The folded Laplace mechanism, where values outside a pre-described domain are folded around the domain until they
fall within.
"""
def __init__(self):
super().__init__()
TruncationAndFoldingMixin.__init__(self)
def __repr__(self):
output = super().__repr__()
output += TruncationAndFoldingMixin.__repr__(self)
return output
@copy_docstring(Laplace.get_bias)
def get_bias(self, value):