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();
|
$pr = array();
|
||||||
$fcount = array();
|
$fcount = array();
|
||||||
$frs = array();
|
$frs = array();
|
||||||
|
$matrixe = array();
|
||||||
|
|
||||||
foreach ($result as $usern) {
|
foreach ($result as $usern) {
|
||||||
$fn = $usern['username'];
|
$fn = $usern['username'];
|
||||||
|
@ -30,22 +31,40 @@
|
||||||
$stmt->execute([$fn]);
|
$stmt->execute([$fn]);
|
||||||
|
|
||||||
$frs[$fn] = $stmt->fetchAll(PDO::FETCH_DEFAULT);
|
$frs[$fn] = $stmt->fetchAll(PDO::FETCH_DEFAULT);
|
||||||
|
|
||||||
|
$matrixe[$fn] = array();
|
||||||
|
$matrixe[$fn][$fn] = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for ($i = 0; $i < 20; $i++) {
|
foreach ($result as $usern) {
|
||||||
foreach ($result as $usern) {
|
$theuser = $usern['username'];
|
||||||
$theuser = $usern['username'];
|
|
||||||
|
$followers = $frs[$theuser];
|
||||||
$followers = $frs[$theuser];
|
foreach ($followers as $follown) {
|
||||||
|
$fn = $follown['target'];
|
||||||
foreach ($followers as $follown) {
|
|
||||||
$fn = $follown['target'];
|
|
||||||
|
|
||||||
if ($usern['username'] == $fn) continue;
|
if ($usern['username'] == $fn) continue;
|
||||||
|
$dst = $fcount[$fn];
|
||||||
|
|
||||||
$dst = $fcount[$fn];
|
$matrixe[$usern['username']][$fn] = 1 + 1 / ($dst + 10) / 10;
|
||||||
|
|
||||||
$pr[$usern['username']] += $pr[$fn] / ($dst + 10) / 10;
|
///$pr[$usern['username']] += $pr[$fn] / ($dst + 10) / 10;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for ($i = 0; $i < 20; $i++) {
|
||||||
|
$prold = $pr;
|
||||||
|
$matrixf = $matrixe;
|
||||||
|
|
||||||
|
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);
|
$new_sum = array_sum($pr);
|
||||||
foreach ($result as $usern) {
|
foreach ($result as $usern) {
|
||||||
$h = $pr[$usern['username']];
|
$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