Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement