Last active
July 5, 2022 17:27
-
-
Save Shoeboxam/b0bd274a7c9824551da63ba73f5318f7 to your computer and use it in GitHub Desktop.
Mock Measurement
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dataclasses import dataclass | |
from typing import Callable, Any | |
@dataclass | |
class MockMeasurement(object): | |
input_domain: Any | |
output_domain: Any | |
function: Callable | |
input_metric: Any | |
output_measure: Any | |
privacy_map: Callable | |
def __call__(self, arg): | |
return self.function(arg) | |
def map(self, d_in): | |
return self.privacy_map(d_in) | |
def make_ci(d_in_limit, d_out_limit, MO): | |
"""Constructs a measurement that releases the mean and a CI radius. | |
:param d_in_limit: the maximum input distance | |
:param d_out_limit: the maximum output distance in terms of MO when inputs differ by at most d_in_limit | |
:param MO: output measure | |
""" | |
def function(arg): | |
# implemented such that d_out_limit in terms of MO is respected, when neighbors differ by no more than d_in_limit | |
return arg + 1 | |
if MO == "ZeroConcentratedDivergence[f64]": | |
def privacy_map(d_in): | |
assert d_in <= d_in_limit | |
return d_out_limit | |
else: | |
raise NotImplementedError("unrecognized output measure!") | |
return MockMeasurement( | |
input_domain="VectorDomain[AllDomain[f64]]", | |
output_domain="PairDomain[AllDomain[f64], AllDomain[f64]]", | |
function=function, | |
input_metric="SymmetricDistance", | |
output_measure=MO, | |
privacy_map=privacy_map) | |
meas = make_ci(d_in_limit=2, d_out_limit=1., MO="ZeroConcentratedDivergence[f64]") | |
# evaluate function | |
data = [1., 2., 3.] | |
print(meas(data)) | |
# find the output distance d_out in terms of MO | |
# MO is ZeroConcentratedDivergence, so d_out is in terms of rho | |
print(meas.map(d_in=2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment