Created
February 12, 2020 23:05
-
-
Save riceissa/08cdf34f999ff3cc84be8e84373e47e7 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
#!/usr/bin/env python3 | |
import numpy as np | |
class Organism: | |
def __init__(self, name): | |
self.wealth = 30 | |
self.name = name | |
self.alive = True | |
def takes_bet(self, q1, q2): | |
if not self.alive: | |
return False | |
elif self.name == "log": | |
return 0.5*(np.log(self.wealth + q1) - np.log(self.wealth)) + 0.5*(np.log(self.wealth + q2) - np.log(self.wealth)) > 0 | |
elif self.name == "growth": | |
return (q1 + q2) / 2 > 0 | |
else: | |
return True | |
organisms = [ | |
Organism("log"), | |
Organism("growth"), | |
Organism("yes"), | |
] | |
for _ in range(10000): | |
# q1, q2 = (1/2, -11/30) | |
q1, q2 = (15, -11) | |
# q1 = np.random.uniform(-1, 15) | |
# q2 = np.random.uniform(-1, 15) | |
# offer a positive-EV bet that the log organism is guaranteed to refuse | |
# log_org_wealth = organisms[0].wealth | |
# q1 = log_org_wealth/2 | |
# q2 = log_org_wealth*(-11/30) | |
outcome = np.random.choice([q1, q2]) | |
for org in organisms: | |
if org.takes_bet(q1, q2): | |
org.wealth += outcome | |
if org.wealth < 0: | |
org.alive = False | |
for org in organisms: | |
print(org.name, org.wealth) | |
highest = 0 | |
highest_name = None | |
for org in organisms: | |
if org.wealth > highest: | |
highest = org.wealth | |
highest_name = org.name | |
print(highest_name, "wins") |
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
#!/usr/bin/env python3 | |
# see https://www.greaterwrong.com/posts/gptXmhJxFiEwuPN98/meetup-notes-ole-peters-on-ergodicity | |
import numpy as np | |
class Organism: | |
def __init__(self, name): | |
self.log_wealth = 0 | |
self.name = name | |
def takes_bet(self, f1, f2): | |
if self.name == "log": | |
return np.sqrt(f1 * f2) > 1 | |
elif self.name == "ensemble": | |
return (f1 + f2)/2 > 1 | |
elif self.name == "guaranteed_win": | |
# only take the bet if you are guaranteed to gain money | |
return min(f1, f2) > 1 | |
elif self.name == "test1": | |
return f1 + f2 > 1 | |
elif self.name == "test2": | |
return (f1 + f2)/((1.1 + 2) * 0.75) > 1 | |
else: | |
return True | |
organisms = [ | |
Organism("log"), | |
Organism("ensemble"), | |
Organism("yes"), | |
Organism("test1"), | |
Organism("test2"), | |
Organism("guaranteed_win"), | |
] | |
for _ in range(100000): | |
# f1, f2 = np.random.uniform(0, 1.5, size=2) | |
# f1, f2 = (1.5, 0.6) | |
p1 = np.random.uniform(0, 1.1) | |
p2 = np.random.uniform(0, 2) | |
p3 = np.random.uniform(1, 2) | |
p4 = np.random.uniform(0, 0.7) | |
p5 = np.random.uniform(0, 0.2) | |
p6 = np.random.uniform(0, 3) | |
f1 = np.random.choice([p1, p2, p3]) | |
f2 = np.random.choice([p4, p5, p6]) | |
outcome = np.random.choice([f1, f2]) | |
for org in organisms: | |
if org.takes_bet(f1, f2): | |
org.log_wealth += np.log(outcome) | |
for org in organisms: | |
print(org.name, org.log_wealth) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment