Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions pydp/algorithms/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -51,15 +53,15 @@ 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.

Consumes 100% of the privacy budget.
"""
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.

Expand All @@ -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):
"""
Expand Down Expand Up @@ -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,
)
8 changes: 4 additions & 4 deletions src/bindings/PyDP/pydp_lib/algorithm_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class AlgorithmBuilder {
throw std::runtime_error(result.status().error_message());
}

return dp::GetValue<T>(result.ValueOrDie());
return dp::GetValue<double>(result.ValueOrDie());
});

pyself.def("partial_result", [](Algorithm& pythis) {
Expand All @@ -129,7 +129,7 @@ class AlgorithmBuilder {
throw std::runtime_error(result.status().error_message());
}

return dp::GetValue<T>(result.ValueOrDie());
return dp::GetValue<double>(result.ValueOrDie());
});

pyself.def("partial_result", [](Algorithm& pythis, double privacy_budget) {
Expand All @@ -143,7 +143,7 @@ class AlgorithmBuilder {
throw std::runtime_error(result.status().error_message());
}

return dp::GetValue<T>(result.ValueOrDie());
return dp::GetValue<double>(result.ValueOrDie());
});

pyself.def("partial_result", [](Algorithm& pythis, double privacy_budget,
Expand All @@ -158,7 +158,7 @@ class AlgorithmBuilder {
throw std::runtime_error(result.status().error_message());
}

return dp::GetValue<T>(result.ValueOrDie());
return dp::GetValue<double>(result.ValueOrDie());
});

// Other methods
Expand Down