Friday, August 28, 2015

Up Vote and Down Vote Algorithm Using Wilson Score interval (in PHP codes)

Today I wanna share how does Reddit's comment algorithm works. As you might know, Reddit has Up Vote and Down Vote for their comment score. Now, what is the best way to count for comment score?

Scoring base up vote and down vote is not only difference of up vote and down vote. Why? There are something problem with this. For example:

Up : 10
down: 0
diff: 10 - 0 = 10 
score: 10
-----

Up : 20
Down : 10
Diff: 20 - 10 = 10
Score: 10

Look, 2 case above has same score. Of course that's invalid.
So, what is the correct way for this?. The answer is  Wilson Score Interval. Mathematical notation can be written as below:




You can see source codes of reddit's comment originally written in python here, but here is rewritten of that (credit):


and the finally codes in PHP is like this:




No comments:

Post a Comment