Created
March 23, 2011 09:06
-
-
Save zeuxisoo/882820 to your computer and use it in GitHub Desktop.
Reddit Ranking Algorithms in PHP
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
<?php | |
// Zeuxis Lo | |
// Created at 2011-03-23 05:05 PM | |
date_default_timezone_set("Asia/Hong_Kong"); | |
function calculate_rank_sum($score, $created_at) { | |
$order = log10(max(abs($score), 1)); | |
if ($score > 0) { | |
$sign = 1; | |
}elseif ($score < 0) { | |
$sign = -1; | |
}else{ | |
$sign = 0; | |
} | |
$seconds = intval(($created_at - mktime(0, 0, 0, 1, 1, 1970))/86400); | |
$long_number = $order + $sign * $seconds / 45000; | |
return round($long_number, 7); | |
} | |
function confidence($ups, $downs) { | |
if ($ups + $downs == 0) { | |
return 0; | |
}else{ | |
$n = $ups + $downs; | |
if ($n == 0) return 0; | |
$z = 1.0; | |
$phat = (float)$ups / $n; | |
return sqrt($phat+$z*$z/(2*$n)-$z*(($phat*(1-$phat)+$z*$z/(4*$n))/$n))/(1+$z*$z/$n); | |
} | |
} | |
echo calculate_rank_sum(10, time()), "\n"; | |
echo confidence(10, 0), "\n"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also, is there an easy way to make the time decay faster?