Skip to content

Instantly share code, notes, and snippets.

Avatar

Abhishek Tandon Tandon-A

View GitHub Profile
View DP_analysis.py
def analysis(db_size,query,noise_percentage=0.5):
db = create_db(db_size)
augmented_db = modify_db(db,noise_percentage)
true_output = query(db)
augmented_output = query(augmented_db)
analysis_output = (augmented_output - (1 - noise_percentage) * 0.5)/noise
print ("size = %r orginal_db result = %r augmented_db result = %r deskewed analysis result = %r" %(db_size,true_output,augmented_output,analysis_output))
View Augmented_Database.py
def modify_db(db,noise=0.5):
first_coin_flip = (torch.rand(len(db)) < noise).float()
second_coin_flip = (torch.rand(len(db)) < 0.5).float()
augmented_database = db.float()*first_coin_flip + (1-first_coin_flip)*second_coin_flip
#augmented database can also be created using this other way
'''
augmented_database = db.copy()
augmented_database[first_coin_flip == 0] = second_coin_flip[first_coin_flip == 0]
View randomized_response.py
import torch
def create_db(db_size):
db = torch.rand(n) >= 0.5
return db
def modify_db(db,noise=0.5):
first_coin_flip = (torch.rand(len(db)) < noise).float()
second_coin_flip = (torch.rand(len(db)) < 0.5).float()
You can’t perform that action at this time.