Last active
December 26, 2015 23:29
-
-
Save m1el/7230992 to your computer and use it in GitHub Desktop.
rating function for entries using algorithm described in http://www.evanmiller.org/how-not-to-sort-by-average-rating.html
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
rating :: Integer -> Integer -> Double | |
rating pos neg = rating' 1 2.24 (pos+neg) (fromIntegral pos) | |
-- 2.24 is quantile function for 0.9875, 97.5% certainity | |
-- {max}-star rating system | |
rating' :: Double -> Double -> Integer -> Double -> Double | |
rating' _ _ 0 _ = 0 | |
rating' max z cnt total | |
| max > 0 && z > 0 && cnt > 0 && total >= 0 = | |
let cnt' = fromIntegral cnt | |
t = 2 * (total/max) / (z^2) | |
ph = (total/max) / cnt' | |
in max * (t*ph+1-sqrt(2*t*ph*(1-ph)+1))/(t+2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment