-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
user provided contributions flows all the way to the generated code (#41
) * input for unit-of-privacy, and show code * factor out code sample into helper * value is now in generated code * rename CLI param * add a test * use shiny code instead of pre * privacy unit template * renaming: unit -> contributions * use contributions on results page * test that user input shows up in generated notebook * better unit tests for template filling * flush instead of close so we will cleanup on exit * check that script is what we expect * finally style script correctly?
- Loading branch information
Showing
12 changed files
with
143 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from htmltools.tags import details, summary | ||
from shiny import ui | ||
|
||
|
||
def output_code_sample(name_of_render_function): | ||
return details( | ||
summary("Code sample"), | ||
ui.output_code(name_of_render_function), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
PRIVACY_UNIT_BLOCK | ||
context = dp.Context.compositor( | ||
data=pl.scan_csv(CSV_PATH, encoding="utf8-lossy"), | ||
privacy_unit=dp.unit_of(contributions=UNIT), | ||
privacy_unit=privacy_unit, | ||
privacy_loss=dp.loss_of(epsilon=LOSS), | ||
split_by_weights=WEIGHTS, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
privacy_unit = dp.unit_of(contributions=CONTRIBUTIONS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from argparse import ArgumentParser | ||
|
||
import polars as pl | ||
import opendp.prelude as dp | ||
|
||
dp.enable_features("contrib") | ||
|
||
|
||
def get_context(csv_path): | ||
privacy_unit = dp.unit_of(contributions=1) | ||
|
||
context = dp.Context.compositor( | ||
data=pl.scan_csv(csv_path, encoding="utf8-lossy"), | ||
privacy_unit=privacy_unit, | ||
privacy_loss=dp.loss_of(epsilon=1), | ||
split_by_weights=[1], | ||
) | ||
|
||
return context | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = ArgumentParser( | ||
description="Creates a differentially private release from a csv" | ||
) | ||
parser.add_argument("--csv", help="Path to csv containing private data") | ||
args = parser.parse_args() | ||
context = get_context(csv_path=args.csv) | ||
print(context) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters