Created
March 24, 2013 02:13
-
-
Save amix/5230160 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
#Rewritten code from /r2/r2/lib/db/_sorts.pyx | |
from math import sqrt | |
def _confidence(ups, downs): | |
n = ups + downs | |
if n == 0: | |
return 0 | |
z = 1.0 #1.0 = 85%, 1.6 = 95% | |
phat = float(ups) / n | |
return sqrt(phat+z*z/(2*n)-z*((phat*(1-phat)+z*z/(4*n))/n))/(1+z*z/n) | |
def confidence(ups, downs): | |
if ups + downs == 0: | |
return 0 | |
else: | |
return _confidence(ups, downs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment