matrix mul
This commit is contained in:
parent
4297f47fd1
commit
8fe117a027
1 changed files with 31 additions and 12 deletions
|
@ -15,6 +15,7 @@
|
|||
$pr = array();
|
||||
$fcount = array();
|
||||
$frs = array();
|
||||
$matrixe = array();
|
||||
|
||||
foreach ($result as $usern) {
|
||||
$fn = $usern['username'];
|
||||
|
@ -30,22 +31,40 @@
|
|||
$stmt->execute([$fn]);
|
||||
|
||||
$frs[$fn] = $stmt->fetchAll(PDO::FETCH_DEFAULT);
|
||||
|
||||
$matrixe[$fn] = array();
|
||||
$matrixe[$fn][$fn] = 1;
|
||||
}
|
||||
|
||||
foreach ($result as $usern) {
|
||||
$theuser = $usern['username'];
|
||||
|
||||
$followers = $frs[$theuser];
|
||||
foreach ($followers as $follown) {
|
||||
$fn = $follown['target'];
|
||||
|
||||
if ($usern['username'] == $fn) continue;
|
||||
$dst = $fcount[$fn];
|
||||
|
||||
$matrixe[$usern['username']][$fn] = 1 + 1 / ($dst + 10) / 10;
|
||||
|
||||
///$pr[$usern['username']] += $pr[$fn] / ($dst + 10) / 10;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for ($i = 0; $i < 20; $i++) {
|
||||
foreach ($result as $usern) {
|
||||
$theuser = $usern['username'];
|
||||
$prold = $pr;
|
||||
$matrixf = $matrixe;
|
||||
|
||||
$followers = $frs[$theuser];
|
||||
|
||||
foreach ($followers as $follown) {
|
||||
$fn = $follown['target'];
|
||||
|
||||
if ($usern['username'] == $fn) continue;
|
||||
|
||||
$dst = $fcount[$fn];
|
||||
|
||||
$pr[$usern['username']] += $pr[$fn] / ($dst + 10) / 10;
|
||||
foreach ($result as $usera) {
|
||||
$pr[$usera['username']] = 0;
|
||||
foreach ($result as $userb) {
|
||||
$matrixe[$usera['username']][$userb['username']] = 0;
|
||||
foreach ($result as $userc) {
|
||||
$matrixe[$usera['username']][$userb['username']] += $matrixf[$usera['username']][$userc['username']] * $matrixf[$userc['username']][$userb['username']];
|
||||
}
|
||||
$pr[$usera['username']] += $matrixe[$usera['username']][$userb['username']];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -54,7 +73,7 @@
|
|||
$new_sum = array_sum($pr);
|
||||
foreach ($result as $usern) {
|
||||
$h = $pr[$usern['username']];
|
||||
$pr[$usern['username']] = (pow($h / $new_sum,1.32) * 100) * $dist + ($h * (1 - $dist));
|
||||
$pr[$usern['username']] = (pow($h / $new_sum,1 /* 1.32 */) * 100) * $dist + ($h * (1 - $dist));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue