Mercurial > hg > rlgallery-misc
comparison py/stats.py @ 33:25843238434a
Change the Python module's name back to rlgall.
It is no longer an experimental variant. Using a database as a backend
is a settled feature.
author | John "Elwin" Edwards |
---|---|
date | Thu, 02 Jan 2014 13:09:48 -0500 |
parents | 5ba2123d2c20 |
children | c045d4dcf88a |
comparison
equal
deleted
inserted
replaced
32:05a4afbe6299 | 33:25843238434a |
---|---|
1 #!/usr/bin/python3 | |
2 | |
1 import math | 3 import math |
2 import psycopg2 | 4 import psycopg2 |
3 import rlgalldb as rlgall | 5 import rlgall |
4 | 6 |
5 def makeExpPDF(lbd): | 7 def makeExpPDF(lbd): |
6 def lpdf(x): | 8 def lpdf(x): |
7 return lbd * math.exp(-lbd * x) | 9 return lbd * math.exp(-lbd * x) |
8 return lpdf | 10 return lpdf |
20 scores = [ r[0] for r in cur.fetchall() ] | 22 scores = [ r[0] for r in cur.fetchall() ] |
21 count = len(scores) | 23 count = len(scores) |
22 total = sum(scores) | 24 total = sum(scores) |
23 lbd = float(count) / total | 25 lbd = float(count) / total |
24 cdf = makeExpCDF(lbd) | 26 cdf = makeExpCDF(lbd) |
25 print "{0}: {1} games, average {2}".format(game.name, count, int(1/lbd)) | 27 print("{0}: {1} games, average {2}".format(game.name, count, int(1/lbd))) |
26 for i in range(0, 10000, 1000): | 28 for i in range(0, 10000, 1000): |
27 actual = len([ s for s in scores if i <= s < i + 1000 ]) | 29 actual = len([ s for s in scores if i <= s < i + 1000 ]) |
28 predicted = (cdf(i + 1000) - cdf(i)) * count | 30 predicted = (cdf(i + 1000) - cdf(i)) * count |
29 print "{0:5}: {1:4} {2}".format(i, actual, predicted) | 31 print("{0:5}: {1:4} {2}".format(i, actual, predicted)) |
30 high = max(scores) | 32 high = max(scores) |
31 print "Max: {0} {1}\n".format(high, 1 - cdf(high)) | 33 print("Max: {0} {1}\n".format(high, 1 - cdf(high))) |
32 | 34 |
33 cur.close() | 35 cur.close() |
34 conn.close() | 36 conn.close() |
35 exit() | 37 exit() |