Last active
July 21, 2020 21:05
-
-
Save bridgesign/a9cb3bf2b1081ecff79bc1a23d3f6136 to your computer and use it in GitHub Desktop.
Gist for Simple RTB Game
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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