Skip to content

Commit

Permalink
feat(protos): subsampled mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
Dariush Wahdany committed Dec 22, 2023
1 parent 5c8bf95 commit 702c4bb
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/dp_learning_ff/mechanisms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,30 @@

from autodp.autodp_core import Mechanism
from autodp.mechanism_zoo import GaussianMechanism
from autodp.transformer_zoo import ComposeGaussian
from autodp.transformer_zoo import ComposeGaussian, AmplificationBySampling
import math


class CoinpressGM(Mechanism):
def __init__(self, Ps: list, name: str = "CoinpressGM"):
def __init__(self, Ps: list, p_sampling: float = 1, name: str = "CoinpressGM"):
"""
Initialize the CoinpressGM object.
Args:
Ps (list): List of privacy costs per step in (0,rho)-zCDP.
name (str, optional): Name of the object. Defaults to "CoinpressGM".
"""
assert p_sampling <= 1, "p_sampling must be <= 1"
assert p_sampling > 0, "p_sampling must be positive"
assert all(p > 0 for p in Ps), "Ps must be positive"
self.params = {"Ps": Ps}
self.name = name
mechanisms = [GaussianMechanism(1 / math.sqrt(2 * p)) for p in Ps]
compose = ComposeGaussian()
mech = compose(mechanisms, [1 for _ in mechanisms])
if p_sampling < 1:
preprocessing = AmplificationBySampling()
mech = preprocessing.amplify(mech, p_sampling)
self.set_all_representation(mech)


Expand Down

0 comments on commit 702c4bb

Please sign in to comment.