Skip to content

Commit

Permalink
fix(protos): pass subsampling
Browse files Browse the repository at this point in the history
  • Loading branch information
Dariush Wahdany committed Dec 22, 2023
1 parent b75a94b commit 74aae5c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/dp_learning_ff/mechanisms.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def __init__(self, Ps: list, p_sampling: float = 1, name: str = "CoinpressGM"):
Args:
Ps (list): List of privacy costs per step in (0,rho)-zCDP.
p_sampling (float, optional): Probability of sampling. Defaults to 1.
name (str, optional): Name of the object. Defaults to "CoinpressGM".
"""
assert p_sampling <= 1, "p_sampling must be <= 1"
Expand All @@ -36,6 +37,7 @@ def __init__(
steps: int = 10,
dist: Literal["lin", "exp", "log", "eq"] = "exp",
ord: float = 1,
p_sampling: float = 1,
name="ScaledCoinpressGM",
Ps: Optional[Iterable[float]] = None,
):
Expand All @@ -48,6 +50,7 @@ def __init__(
dist (Literal["lin", "exp", "log", "eq"]): The distribution type. Ignored if Ps is set. Defaults to "exp".
ord (float, optional): The order of the distribution. Ignored if Ps is set. Defaults to 1.
name (str, optional): The name of the mechanism. Defaults to "ScaledCoinpressGM".
p_sampling (float, optional): The probability of sampling. Defaults to 1.
Ps (Optional[Iterable[float]], optional): The privacy costs per step. Overwrites steps, dist, ord. Defaults to None.
"""
assert scale > 0, "scale must be positive"
Expand All @@ -64,7 +67,7 @@ def __init__(
Ps = [math.pow(scale * math.log(t + 1), ord) for t in range(steps)]
elif dist == "eq":
Ps = [scale] * steps
super().__init__(name=name, Ps=Ps)
super().__init__(name=name, p_sampling=p_sampling, Ps=Ps)


def calibrate_single_param(mechanism_class, epsilon, delta, verbose: bool = False):
Expand Down
7 changes: 6 additions & 1 deletion src/dp_learning_ff/prototypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ def prototypes(self, train_preds, train_targets):
if self.mechanism is None:
raise ValueError("Mechanism not calibrated")
return give_private_prototypes(
train_preds, train_targets, self.mechanism.params["Ps"], seed=self.seed
train_preds,
train_targets,
self.mechanism.params["Ps"],
seed=self.seed,
subsampling=self.p_sampling,
poisson_sampling=True,
)

@property
Expand Down

0 comments on commit 74aae5c

Please sign in to comment.