Skip to content
Merged
Show file tree
Hide file tree
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
14 changes: 6 additions & 8 deletions dpsynth/bin/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import dpsynth
from dpsynth.bin import _read_csv_args
import fancyflags as ff
import numpy as np
import pandas as pd


Expand Down Expand Up @@ -87,23 +88,20 @@


def main(_):
np.random.seed(_SEED.value)
read_csv_kwargs = _READ_CSV_ARGS.value().to_read_csv_kwargs()
df = pd.read_csv(_DATASET_PATH.value, **read_csv_kwargs)
attribute_domains = dpsynth.domain.from_yaml_file(_DOMAIN_PATH.value)

match _MECHANISM.value:
case 'mst':
mechanism_config = dpsynth.discrete_mechanisms.MSTConfig(seed=_SEED.value)
mechanism_config = dpsynth.discrete_mechanisms.MSTConfig()
case 'aim':
mechanism_config = dpsynth.discrete_mechanisms.AIMConfig(seed=_SEED.value)
mechanism_config = dpsynth.discrete_mechanisms.AIMConfig()
case 'independent':
mechanism_config = dpsynth.discrete_mechanisms.IndependentConfig(
seed=_SEED.value
)
mechanism_config = dpsynth.discrete_mechanisms.IndependentConfig()
case 'aim_gdp':
mechanism_config = dpsynth.discrete_mechanisms.AIMGDPConfig(
seed=_SEED.value
)
mechanism_config = dpsynth.discrete_mechanisms.AIMGDPConfig()
case _:
raise ValueError(f'Unknown mechanism: {_MECHANISM.value}')

Expand Down
18 changes: 10 additions & 8 deletions dpsynth/data_generation_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def _compute_privacy_parameters(
epsilon: float,
delta: float,
one_way_marginal_budget_fraction: float,
discrete_config: discrete_mechanisms.DiscreteMechanismConfig,
discrete_config: discrete_mechanisms.DiscreteMechanism,
) -> tuple[float, float]:
"""Compute privacy parameters for one-way marginals and discrete mechanism."""

Expand All @@ -77,10 +77,12 @@ def _compute_privacy_parameters(

def make_event_from_param(zcdp_rho):
event1 = dp_accounting.GaussianDpEvent(one_way_marginal_sigma)
event2 = discrete_config.dp_event(zcdp_rho)
event2 = discrete_config.calibrate(zcdp_rho=zcdp_rho).dp_event
return dp_accounting.ComposedDpEvent([event1, event2])

if isinstance(discrete_config.dp_event(1.0), dp_accounting.ZCDpEvent):
if isinstance(
discrete_config.calibrate(zcdp_rho=1.0).dp_event, dp_accounting.ZCDpEvent
):
make_fresh_accountant = dp_accounting.rdp.RdpAccountant
else:
make_fresh_accountant = dp_accounting.pld.PLDAccountant
Expand All @@ -102,7 +104,7 @@ def generate(
epsilon: float,
delta: float,
*,
discrete_config: discrete_mechanisms.DiscreteMechanismConfig = discrete_mechanisms.MSTConfig(),
discrete_config: discrete_mechanisms.DiscreteMechanism = discrete_mechanisms.MSTMechanism(),
numerical_bins: int = 32,
one_way_marginal_budget_fraction: float = 0.1,
cross_attribute_constraints: Sequence[constraints.Constraint] = (),
Expand Down Expand Up @@ -245,8 +247,9 @@ def generate(
#######################################################################
one_way_marginal_queries = [(col,) for col in discrete.domain]
gdp_sigma = accounting.gdp_gaussian_sigma(one_way_marginal_gdp_mu)
rng = np.random.default_rng()
one_way_measurements = common.measure_marginals_with_noise(
discrete, one_way_marginal_queries, gdp_sigma
rng, discrete, one_way_marginal_queries, gdp_sigma
)
logging.info('[SynthKit Tabular]: Measured one-way marginals.')

Expand All @@ -262,10 +265,9 @@ def generate(
cross_attribute_constraints, discrete.domain
)

model = discrete_mechanisms.run_mechanism(
model = discrete_config.calibrate(zcdp_rho=discrete_zcdp_rho)(
rng,
data=discrete,
zcdp_rho=discrete_zcdp_rho,
config=discrete_config,
initial_measurements=one_way_measurements,
initial_potentials=initial_potentials,
)
Expand Down
22 changes: 15 additions & 7 deletions dpsynth/discrete_mechanisms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,18 @@

# pylint: disable=g-importing-member

from dpsynth.discrete_mechanisms.aim import AIMConfig
from dpsynth.discrete_mechanisms.aim_gdp import AIMGDPConfig
from dpsynth.discrete_mechanisms.api import DiscreteMechanismConfig
from dpsynth.discrete_mechanisms.api import run_mechanism
from dpsynth.discrete_mechanisms.direct import DirectConfig
from dpsynth.discrete_mechanisms.independent import IndependentConfig
from dpsynth.discrete_mechanisms.mst import MSTConfig
from dpsynth.discrete_mechanisms.aim import AIMMechanism
from dpsynth.discrete_mechanisms.aim_gdp import AIMGDPMechanism
from dpsynth.discrete_mechanisms.direct import DirectMechanism
from dpsynth.discrete_mechanisms.independent import IndependentMechanism
from dpsynth.discrete_mechanisms.mst import MSTMechanism
from dpsynth.discrete_mechanisms.swift import SWIFTMechanism
from dpsynth.local_mode.primitives import DPMechanism as DiscreteMechanism

# Backwards-compatible aliases.
AIMConfig = AIMMechanism
AIMGDPConfig = AIMGDPMechanism
DirectConfig = DirectMechanism
IndependentConfig = IndependentMechanism
MSTConfig = MSTMechanism
SWIFTConfig = SWIFTMechanism
Loading
Loading