Skip to content

Instantly share code, notes, and snippets.

@Tandon-A
Last active September 9, 2019 13:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tandon-A/c5a2fafb15982ed5c1d543ba9331d57b to your computer and use it in GitHub Desktop.
Save Tandon-A/c5a2fafb15982ed5c1d543ba9331d57b to your computer and use it in GitHub Desktop.
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()
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]
'''
return augmented_database
def mean_query(db):
return db.float().mean()
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))
db_size = 100
analysis(db_size,mean_query,0.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment