Last active
December 23, 2015 02:29
-
-
Save jamii/6567205 to your computer and use it in GitHub Desktop.
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
import random | |
import numpy.random | |
total_gain_from_swapping = 0 | |
number_of_rounds = 0 | |
while True: | |
# small_envelope = random.uniform(0, 1000) # this is well-behaved - the running mean eventually converges to 0 | |
small_envelope = 2 ** numpy.random.geometric(0.5, 1)[0] # P($2^i) = 1/(2^i) - this is not well-behaved - the running mean wanders around forever | |
large_envelope = 2 * small_envelope | |
my_envelope, other_envelope = random.sample([small_envelope, large_envelope], 2) | |
total_gain_from_swapping += other_envelope - my_envelope | |
number_of_rounds += 1 | |
if number_of_rounds % 10000 == 0: | |
print 'running mean gain from swapping is', float(total_gain_from_swapping) / number_of_rounds |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment