Skip to content

Add DPEvent to the state in DifferentiallyPrivateFactory's next_fn. This requires implementing initial_sample_state in TreeRangeSumQuery for tests to pass. #333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 5 additions & 4 deletions tensorflow_privacy/privacy/dp_query/dp_query.py
Original file line number Diff line number Diff line change
@@ -268,10 +268,11 @@ def derive_metrics(self, global_state):

def _zeros_like(arg):
"""A `zeros_like` function that also works for `tf.TensorSpec`s."""
try:
arg = tf.convert_to_tensor(value=arg)
except TypeError:
pass
if not isinstance(arg, tf.TensorSpec):
try:
arg = tf.convert_to_tensor(value=arg)
except TypeError:
pass
return tf.zeros(arg.shape, arg.dtype)


8 changes: 7 additions & 1 deletion tensorflow_privacy/privacy/dp_query/tree_range_query.py
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@

import distutils
import math
from typing import Optional
from typing import Any, Optional

import attr
import dp_accounting
@@ -136,6 +136,12 @@ def initial_global_state(self):
arity=self._arity,
inner_query_state=self._inner_query.initial_global_state())

def initial_sample_state(self, template: Optional[Any] = None):
"""Implements `tensorflow_privacy.DPQuery.initial_sample_state`."""
return self.preprocess_record(
self.derive_sample_params(self.initial_global_state()),
super().initial_sample_state(template))

def derive_sample_params(self, global_state):
"""Implements `tensorflow_privacy.DPQuery.derive_sample_params`."""
return (global_state.arity,