comparison py/stats.py @ 0:5ba2123d2c20

Put this project under version control, finally. Scripts for rlgallery.org, using a PostgreSQL backend. The recorder system is in py/, CGI scripts are in web/.
author John "Elwin" Edwards <elwin@sdf.org>
date Wed, 25 Jul 2012 21:59:42 -0700
parents
children 25843238434a
comparison
equal deleted inserted replaced
-1:000000000000 0:5ba2123d2c20
1 import math
2 import psycopg2
3 import rlgalldb as rlgall
4
5 def makeExpPDF(lbd):
6 def lpdf(x):
7 return lbd * math.exp(-lbd * x)
8 return lpdf
9
10 def makeExpCDF(lbd):
11 def lcdf(x):
12 return 1 - math.exp(-lbd * x)
13 return lcdf
14
15 conn = psycopg2.connect("dbname=rlg")
16 cur = conn.cursor()
17 for game in rlgall.gamelist:
18 query = "SELECT score FROM {0};".format(game.uname)
19 cur.execute(query)
20 scores = [ r[0] for r in cur.fetchall() ]
21 count = len(scores)
22 total = sum(scores)
23 lbd = float(count) / total
24 cdf = makeExpCDF(lbd)
25 print "{0}: {1} games, average {2}".format(game.name, count, int(1/lbd))
26 for i in range(0, 10000, 1000):
27 actual = len([ s for s in scores if i <= s < i + 1000 ])
28 predicted = (cdf(i + 1000) - cdf(i)) * count
29 print "{0:5}: {1:4} {2}".format(i, actual, predicted)
30 high = max(scores)
31 print "Max: {0} {1}\n".format(high, 1 - cdf(high))
32
33 cur.close()
34 conn.close()
35 exit()