Skip to content

Instantly share code, notes, and snippets.

@bridgesign
Last active July 21, 2020 21:05
Show Gist options
  • Save bridgesign/a9cb3bf2b1081ecff79bc1a23d3f6136 to your computer and use it in GitHub Desktop.
Save bridgesign/a9cb3bf2b1081ecff79bc1a23d3f6136 to your computer and use it in GitHub Desktop.
Gist for Simple RTB Game
class user:
"""
The user class defines a user which are a part of the game
It keeps the views and clicks vector for all the ads and shares the
data to the bidder only about the ads the bidder owns
It also determines whether it will see the ad or not depending on
the overall clicks and views of all ads.
It also updates the vectors based on the view and click. The data about
other preferences of the user is not revealed and the bidder never stores the
user data, thus maintaing privacy
"""
def __init__(self, view_vec, click_vec):
self.view_vec = view_vec
self.click_vec = click_vec
def toss(self):
clicks = np.zeros(self.view_vec.size)
views_n = self.view_vec+0.1
views_n = views_n/np.linalg.norm(views_n, 1)
clicks_n = self.click_vec+0.1
clicks_n = clicks_n/np.linalg.norm(clicks_n, 1)
r = views_n/clicks_n
prob = abs((1-r)/(1+r))
for j in range(clicks.size):
clicks[j] = np.random.binomial(1, prob[j])
return clicks, views_n, clicks_n
def update(self, view, click):
if view>-1:
self.view_vec[view]+=1
if click==1:
self.click_vec[view]+=1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment