From 1646460de78357e483ea6e48286ff55de9f3b7db Mon Sep 17 00:00:00 2001 From: Chinmay Shah Date: Fri, 14 Aug 2020 01:55:49 +0530 Subject: [PATCH 1/2] change return datatype to double --- src/bindings/PyDP/pydp_lib/algorithm_builder.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/bindings/PyDP/pydp_lib/algorithm_builder.hpp b/src/bindings/PyDP/pydp_lib/algorithm_builder.hpp index 45d5cc99..52197b26 100644 --- a/src/bindings/PyDP/pydp_lib/algorithm_builder.hpp +++ b/src/bindings/PyDP/pydp_lib/algorithm_builder.hpp @@ -119,7 +119,7 @@ class AlgorithmBuilder { throw std::runtime_error(result.status().error_message()); } - return dp::GetValue(result.ValueOrDie()); + return dp::GetValue(result.ValueOrDie()); }); pyself.def("partial_result", [](Algorithm& pythis) { @@ -129,7 +129,7 @@ class AlgorithmBuilder { throw std::runtime_error(result.status().error_message()); } - return dp::GetValue(result.ValueOrDie()); + return dp::GetValue(result.ValueOrDie()); }); pyself.def("partial_result", [](Algorithm& pythis, double privacy_budget) { @@ -143,7 +143,7 @@ class AlgorithmBuilder { throw std::runtime_error(result.status().error_message()); } - return dp::GetValue(result.ValueOrDie()); + return dp::GetValue(result.ValueOrDie()); }); pyself.def("partial_result", [](Algorithm& pythis, double privacy_budget, @@ -158,7 +158,7 @@ class AlgorithmBuilder { throw std::runtime_error(result.status().error_message()); } - return dp::GetValue(result.ValueOrDie()); + return dp::GetValue(result.ValueOrDie()); }); // Other methods From a19b0a5bdd65639dbf00301aa0a9f7806da37e76 Mon Sep 17 00:00:00 2001 From: Chinmay Shah Date: Fri, 14 Aug 2020 01:56:22 +0530 Subject: [PATCH 2/2] added l0&linf sensitivity --- pydp/algorithms/algorithm.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/pydp/algorithms/algorithm.py b/pydp/algorithms/algorithm.py index cfbc2bb1..c534f4d4 100644 --- a/pydp/algorithms/algorithm.py +++ b/pydp/algorithms/algorithm.py @@ -17,6 +17,8 @@ def __init__(self, **kwargs): self.dtype = dtype self.__algorithm = class_(**kwargs) self.epsilon = self.__algorithm.epsilon + self.l0_sensitivity = kwargs["l0_sensitivity"] + self.linf_sensitivity = kwargs["linf_sensitivity"] @staticmethod def __map_dtype_str(dtype): @@ -51,7 +53,7 @@ def add_entry(self, value): """ return self.__algorithm.add_entry(value) - def result(self, list): + def quick_result(self, list): """ Runs the algorithm on the input using the epsilon parameter provided in the constructor and returns output. @@ -59,7 +61,7 @@ def result(self, list): """ return self.__algorithm.result(list) - def partial_result(self, privacy_budget=None, noise_interval_level=None): + def result(self, privacy_budget=None, noise_interval_level=None): """ Gets the algorithm result. @@ -72,11 +74,10 @@ def partial_result(self, privacy_budget=None, noise_interval_level=None): if privacy_budget is None: return self.__algorithm.partial_result() - - if noise_interval_level is None: + elif noise_interval_level is None: return self.__algorithm.partial_result(privacy_budget) - - return self.__algorithm.partial_result(privacy_budget, noise_interval_level) + else: + return self.__algorithm.partial_result(privacy_budget, noise_interval_level) def reset(self): """ @@ -121,10 +122,20 @@ def __init__(self, epsilon=1.0, dtype="int"): class BoundedAlgorithm(MetaAlgorithm): - def __init__(self, epsilon=1.0, lower_bound=None, upper_bound=None, dtype="int"): + def __init__( + self, + epsilon=1.0, + lower_bound=None, + upper_bound=None, + l0_sensitivity=1, + linf_sensitivity=1, + dtype="int", + ): super().__init__( epsilon=epsilon, lower_bound=lower_bound, upper_bound=upper_bound, + l0_sensitivity=l0_sensitivity, + linf_sensitivity=linf_sensitivity, dtype=dtype, )