document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #Rewritten code from /r2/r2/lib/db/_sorts.pyx
  2.  
  3. from math import sqrt
  4.  
  5. def _confidence(ups, downs):
  6.     n = ups + downs
  7.  
  8.     if n == 0:
  9.         return 0
  10.  
  11.     z = 1.0 #1.0 = 85%, 1.6 = 95%
  12.     phat = float(ups) / n
  13.     return sqrt(phat+z*z/(2*n)-z*((phat*(1-phat)+z*z/(4*n))/n))/(1+z*z/n)
  14.  
  15. def confidence(ups, downs):
  16.     if ups + downs == 0:
  17.         return 0
  18.     else:
  19.         return _confidence(ups, downs)
');