Skip to content
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

Include unit of privacy in graphs and output #205

Merged
merged 3 commits into from
Jan 7, 2025
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
7 changes: 6 additions & 1 deletion dp_wizard/app/components/column_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,14 @@ def column_plot():
contributions=contributions,
weighted_epsilon=epsilon * weight / weights_sum,
)
s = "s" if contributions > 1 else ""
title = (
f"Simulated {name}: normal distribution, "
f"{contributions} contribution{s} / invidual"
)
return plot_histogram(
histogram,
error=accuracy,
cutoff=0, # TODO
title=f"Simulated {name}, assuming normal distribution",
title=title,
)
7 changes: 3 additions & 4 deletions dp_wizard/utils/code_generators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ def _make_queries(self):

def _make_query(self, column_name):
indentifier = name_to_identifier(column_name)
title = f"DP counts for {column_name}"
accuracy_name = f"{indentifier}_accuracy"
histogram_name = f"{indentifier}_histogram"
return (
Expand All @@ -117,19 +116,19 @@ def _make_query(self, column_name):
)
.fill_blocks(
OUTPUT_BLOCK=self._make_output(
title=title,
column_name=column_name,
accuracy_name=accuracy_name,
histogram_name=histogram_name,
)
)
.finish()
)

def _make_output(self, title: str, accuracy_name: str, histogram_name: str):
def _make_output(self, column_name: str, accuracy_name: str, histogram_name: str):
return (
Template(f"{self.root_template}_output")
.fill_values(
TITLE=title,
COLUMN_NAME=column_name,
)
.fill_expressions(
ACCURACY_NAME=accuracy_name,
Expand Down
7 changes: 6 additions & 1 deletion dp_wizard/utils/code_generators/no-tests/_notebook_output.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# CONFIDENCE_NOTE
plot_histogram(HISTOGRAM_NAME, error=ACCURACY_NAME, cutoff=0, title=TITLE)
column_name = COLUMN_NAME
title = (
f"DP counts for {column_name}, "
f"assuming {contributions} contributions per invidual"
)
plot_histogram(HISTOGRAM_NAME, error=ACCURACY_NAME, cutoff=0, title=title)
3 changes: 2 additions & 1 deletion dp_wizard/utils/code_generators/no-tests/_privacy_unit.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
privacy_unit = dp.unit_of(contributions=CONTRIBUTIONS)
contributions = CONTRIBUTIONS
privacy_unit = dp.unit_of(contributions=contributions)
1 change: 1 addition & 0 deletions dp_wizard/utils/code_generators/no-tests/_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def flatten_dict(dictionary, parent_key=""):
"data": CSV_PATH,
"epsilon": EPSILON,
"columns": COLUMNS,
"contributions": contributions,
},
"outputs": OUTPUTS,
}
Expand Down
6 changes: 3 additions & 3 deletions dp_wizard/utils/code_generators/no-tests/_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
COLUMNS_BLOCK


def get_context(csv_path):
def get_context_contributions(csv_path):
CONTEXT_BLOCK
return context
return context, contributions


if __name__ == "__main__":
Expand All @@ -18,6 +18,6 @@ def get_context(csv_path):
"--csv", required=True, help="Path to csv containing private data"
)
args = parser.parse_args()
context = get_context(csv_path=args.csv)
context, contributions = get_context_contributions(csv_path=args.csv)

QUERIES_BLOCK
6 changes: 5 additions & 1 deletion dp_wizard/utils/code_generators/no-tests/_script_output.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
print(TITLE)
column_name = COLUMN_NAME
print(
f"DP counts for {column_name}, "
f"assuming {contributions} contributions per invidual"
)
print(CONFIDENCE_NOTE, ACCURACY_NAME)
print(HISTOGRAM_NAME)
6 changes: 3 additions & 3 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def expect_no_error():
expect_not_visible(download_results_text)
page.get_by_label("Contributions").fill("42")
page.get_by_text("Code sample: Unit of Privacy").click()
expect_visible("dp.unit_of(contributions=42)")
expect_visible("contributions = 42")
expect_no_error()

# Button disabled until upload:
Expand Down Expand Up @@ -156,7 +156,7 @@ def expect_no_error():

script_download = script_download_info.value
script = script_download.path().read_text()
assert "privacy_unit = dp.unit_of(contributions=42)" in script
assert "contributions = 42" in script

# Notebook:
with page.expect_download() as notebook_download_info:
Expand All @@ -165,7 +165,7 @@ def expect_no_error():

notebook_download = notebook_download_info.value
notebook = notebook_download.path().read_text()
assert "privacy_unit = dp.unit_of(contributions=42)" in notebook
assert "contributions = 42" in notebook

# -- Feedback --
page.get_by_text("Feedback").click()
Expand Down
Loading