Skip to content

Commit

Permalink
Fix noise_std computation in analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
dvadym committed Nov 14, 2023
1 parent 52e210b commit 3c2be74
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion analysis/parameter_tuning.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def _find_candidate_parameters(
max_sum_per_partition_bounds = min_sum_per_partition_bounds = None

if calculate_sum_per_partition_param:
if hist.linf_sum_contributions_histogram.bins[0].lower >= 0:
if hist.linf_sum_contributions_histogram.bins[0].lower < 0:
logging.warning(
"max_sum_per_partition should not contain negative sums because"
" min_sum_per_partition tuning is not supported yet and "
Expand Down
15 changes: 15 additions & 0 deletions analysis/per_partition_combiners.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,10 @@ def compute_metrics(self, acc: AccumulatorType) -> metrics.SumMetrics:
std_noise=std_noise,
noise_kind=self._params.aggregate_params.noise_kind)

def get_sensitivities(self) -> dp_computations.Sensitivities:
return dp_computations.compute_sensitivities_for_sum(
self._params.aggregate_params)


class CountCombiner(SumCombiner):
"""A combiner for utility analysis counts."""
Expand All @@ -298,6 +302,10 @@ def create_accumulator(
self._params.aggregate_params.max_sum_per_partition = self._params.aggregate_params.max_contributions_per_partition
return super().create_accumulator(data)

def get_sensitivities(self) -> dp_computations.Sensitivities:
return dp_computations.compute_sensitivities_for_count(
self._params.aggregate_params)


class PrivacyIdCountCombiner(SumCombiner):
"""A combiner for utility analysis privacy ID counts."""
Expand All @@ -319,6 +327,10 @@ def create_accumulator(
self._params.aggregate_params.max_sum_per_partition = 1.0
return super().create_accumulator(data)

def get_sensitivities(self) -> dp_computations.Sensitivities:
return dp_computations.compute_sensitivities_for_privacy_id_count(
self._params.aggregate_params)


class RawStatisticsCombiner(UtilityAnalysisCombiner):
"""A combiner for computing per-partition raw statistics (count etc)."""
Expand All @@ -335,6 +347,9 @@ def compute_metrics(self, acc: AccumulatorType):
privacy_id_count, count = acc
return metrics.RawStatistics(privacy_id_count, count)

def get_sensitivities(self) -> dp_computations.Sensitivities:
raise NotImplementedError("It's DP mechanism.")


class CompoundCombiner(pipeline_dp.combiners.CompoundCombiner):
"""Compound combiner for Utility analysis per partition metrics."""
Expand Down
6 changes: 3 additions & 3 deletions pipeline_dp/combiners.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,16 @@ class CombinerParams:

def __init__(self, spec: budget_accounting.MechanismSpec,
aggregate_params: pipeline_dp.AggregateParams):
self._mechanism_spec = spec
self.mechanism_spec = spec
self.aggregate_params = copy.copy(aggregate_params)

@property
def eps(self):
return self._mechanism_spec.eps
return self.mechanism_spec.eps

@property
def delta(self):
return self._mechanism_spec.delta
return self.mechanism_spec.delta

@property
def scalar_noise_params(self):
Expand Down

0 comments on commit 3c2be74

Please sign in to comment.