diff --git a/src/dp_learning_ff/mechanisms.py b/src/dp_learning_ff/mechanisms.py index 82519fc..9dc583f 100644 --- a/src/dp_learning_ff/mechanisms.py +++ b/src/dp_learning_ff/mechanisms.py @@ -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" @@ -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, ): @@ -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" @@ -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): diff --git a/src/dp_learning_ff/prototypes.py b/src/dp_learning_ff/prototypes.py index e051507..b2984f5 100644 --- a/src/dp_learning_ff/prototypes.py +++ b/src/dp_learning_ff/prototypes.py @@ -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