"""
...the example I've seen is that a loss-averse agent may evaluate a sequence
of say ten coinflips with -$15/+$20 payoffs positively at the same time as
evaluating each individual such coinflip negatively.
- steven, http://lesswrong.com/lw/gi/dissenting_views/dlu?context=3
"""
from math import log
def util(x):
if x > 0:
return log(x + 1)
elif x < 0:
return -2 * log(abs(x) + 1)
else:
return 0.
print "single flip EU =",
print 0.5 * util(20) + 0.5 * util(-15)
fac = lambda x: 1 if x==0 else x*fac(x-1)
binom = lambda n,k: fac(n) / (fac(n-k) * fac(k))
eu = 0.
for n_wins in xrange(11):
payoff = 20 * n_wins - 15 * (10 - n_wins)
p = binom(10, n_wins) / 1024.
eu += util(payoff) * p
print "multi-flip EU =", eu