Skip to content

Instantly share code, notes, and snippets.

@liyuqian
Last active November 21, 2019 08:23
Show Gist options
  • Save liyuqian/74de4405e82ea22e26d45c49ddf7420c to your computer and use it in GitHub Desktop.
Save liyuqian/74de4405e82ea22e26d45c49ddf7420c to your computer and use it in GitHub Desktop.
import random
def sample():
phase = random.random()
if phase < 3/8.0:
return random.random(), random.random()
elif phase < 6/8.0:
return random.random() + 1, random.random() + 1
elif phase < 7/8.0:
return random.random() + 1, random.random()
else:
return random.random(), random.random() + 1
def main():
N = 1000 * 1000
# r = 2/3 should be optimal with the max expected revenue = 89/108 ~= 0.824074.
#
# For comparison, r = 1 should only get an expected revenue = 0.75. Note that
# r = 1 is optimal if two bidders are independently and uniformly distributed
# between [0, 2). The marginal PDF of each bidder in our setup is indeed
# uniform between [0, 2). (However, our bidders are not independent.)
#
# Please feel free to change r and see how the revenue changes.
#
# BTW, see the calculation of 89/108 on
# https://www.wolframcloud.com/obj/21f990d3-95bb-4895-b7ae-59379cf9ce11
r = 2/3.0
sum = 0.0
for i in range(N):
x, y = sample()
first, second = max(x, y), min(x, y)
if second >= r:
sum += second;
elif first >= r:
sum += r
print( 'r = %s has expected revenue %s' % (r, sum / N) )
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment