Skip to content

Instantly share code, notes, and snippets.

@bridgesign
Created July 21, 2020 21:21
Show Gist options
  • Save bridgesign/2ad1046b4ab6ac05f59f067e7dd69cf8 to your computer and use it in GitHub Desktop.
Save bridgesign/2ad1046b4ab6ac05f59f067e7dd69cf8 to your computer and use it in GitHub Desktop.
GIst for Simple RTB Game
class generator:
"""
The generator creates a single ad slot with a random user and
makes the bidders to bid for the slot. Depending on the result,
it sends back the result to the individual bidders.
"""
def __init__(self, users, bidders):
self.users = users
self.bidders = bidders
self.bidders_num = len(bidders)
self.users_num = len(users)
def generate(self):
ruser = np.random.choice(self.users)
clicks, views_n, clicks_n = ruser.toss()
bidi = 0
bidder_index = -1
advec_index = -1
index = -1
for i in range(self.bidders_num):
b = self.bidders[i]
b.predict(views_n, clicks_n)
maxi = torch.max(b.bid)
if maxi>bidi:
bidi = float(maxi)
advec_index = torch.argmax(b.bid)
index = b.advec[advec_index]
bidder_index = i
ruser.update(index, clicks[index])
for i in range(self.bidders_num):
if i==bidder_index:
self.bidders[i].backprop(advec_index, clicks[index])
else:
self.bidders[i].backprop(-1, 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment