SHARE
TWEET

Untitled

a guest Sep 19th, 2019 94 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import torch
  2.  
  3. def create_db(db_size):
  4.   db = torch.rand(n) >= 0.5
  5.   return db
  6.  
  7. def modify_db(db,noise=0.5):
  8.   first_coin_flip = (torch.rand(len(db)) < noise).float()
  9.   second_coin_flip = (torch.rand(len(db)) < 0.5).float()
  10.  
  11.   augmented_database = db.float()*first_coin_flip + (1-first_coin_flip)*second_coin_flip
  12.  
  13.   #augmented database can also be created using this other way
  14.   '''
  15.   augmented_database = db.copy()
  16.   augmented_database[first_coin_flip == 0] = second_coin_flip[first_coin_flip == 0]
  17.   '''
  18.   return augmented_database
  19.  
  20. def mean_query(db):
  21.   return db.float().mean()
  22.  
  23. def analysis(db_size,query,noise_percentage=0.5):
  24.   db = create_db(db_size)
  25.   augmented_db = modify_db(db,noise_percentage)
  26.   true_output = query(db)
  27.   augmented_output = query(augmented_db)
  28.   analysis_output = (augmented_output - (1 - noise_percentage) * 0.5)/noise
  29.   print ("size = %r orginal_db result = %r augmented_db result = %r deskewed analysis result = %r" %(db_size,true_output,augmented_output,analysis_output))
  30.  
  31.  
  32. db_size = 100  
  33. analysis(db_size,mean_query,0.5)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top