Skip to content

Instantly share code, notes, and snippets.

View Shoeboxam's full-sized avatar

Michael Shoemate Shoeboxam

View GitHub Profile
@Shoeboxam
Shoeboxam / pca.py
Created April 9, 2024 19:39
OpenDP PCA
import opendp.prelude as dp
model = dp.sklearn.PCA(
epsilon=1.,
row_norm=1.,
n_samples=num_rows,
n_features=4,
)
import faker
import opendp.prelude as dp
counter = dp.t.make_count_by(
dp.vector_domain(dp.atom_domain(T=str)),
dp.symmetric_distance(),
MO=dp.L1Distance[int])
alp_meas = counter >> dp.m.then_alp_queryable(
scale=1.,
@Shoeboxam
Shoeboxam / dp_grouping_columns.py
Created April 9, 2024 17:10
OpenDP Select Grouping Columns
import opendp.prelude as dp
import pandas as pd
import faker
import random
# first, write constructors that will be used to build the mechanism
def make_grouping_cols_score(candidates, min_bin_contributions):
r"""Create a transformation that assesses the utility of each candidate in `candidates`.
@Shoeboxam
Shoeboxam / dp_quantile.py
Last active April 9, 2024 15:46
OpenDP Quantile
import opendp.prelude as dp
dp.enable_features("contrib")
# define privacy guarantee
max_contributions = 1
epsilon = 0.1
# public information
candidates = [10, 30, 50, 70, 90]
@Shoeboxam
Shoeboxam / bench.py
Created February 1, 2023 23:48
simple memory+time benchmark
def bench(function, iterations):
import time
elapsed_times = []
import tracemalloc
tracemalloc.start()
for _ in range(iterations):
prev_snap = tracemalloc.take_snapshot()
prev_time = time.time()
@Shoeboxam
Shoeboxam / mock_measurement.py
Last active July 5, 2022 17:27
Mock Measurement
from dataclasses import dataclass
from typing import Callable, Any
@dataclass
class MockMeasurement(object):
input_domain: Any
output_domain: Any
function: Callable
input_metric: Any
@Shoeboxam
Shoeboxam / make_stable_constructor.py
Last active October 22, 2021 02:07
Pseudocode of an OpenDP combinator for privatizing a certain class of vector-valued transformations
# Pseudocode of an OpenDP combinator for privatizing a certain class of vector-valued transformations
def make_some_transformation_stable(trans_query: Transformation, scale, threshold):
assert trans_query.input_metric == SymmetricDistance
assert trans_query.output_metric == L1Distance
# must be equivalent to representation 2 in https://arxiv.org/pdf/1709.05396.pdf, Section 2.2.1
assert trans_query.output_domain == HashMapDomain[AllDomain[KeyType], AllDomain[FloatCountType]]
def function(data):
noised = {k: v + sample_laplace(scale) for k, v in trans_query.invoke(data)}
import pandas as pd
import matplotlib.pyplot as plt
from dateutil import parser
plt.style.use("bmh")
data = pd.read_excel("/Users/michael/Downloads/MD 4 year.XLS", parse_dates=['Gift Date'])
def plot_cumulative_per_year(event_days, min_delta, max_delta):
cumulative_sums = []
@Shoeboxam
Shoeboxam / README.md
Last active May 18, 2020 20:36
markdown test

Build Status

WhiteNoise Core
Differential Privacy Library Python Bindings

This repository contains python bindings to Whitenoise-Core and its underlying Rust binaries.

  • For examples of this library in action, please see the Python notebooks in WhiteNoise-Samples.
  • In addition, see the accompanying WhiteNoise-System repository which includes WhiteNoise tools for differential privacy.

@Shoeboxam
Shoeboxam / pipeline_grpc_demo.py
Last active June 21, 2019 17:47
Construct pipelines in the ta2ta3-api specification to be passed over GRPC
import d3m
from d3m.metadata.pipeline import Pipeline, PrimitiveStep
from d3m.metadata.base import ArgumentType
from google.protobuf.json_format import MessageToJson
from ta3ta2_api import utils
import json
types = [
utils.ValueType.RAW,