protected function Recommender::saveSimilarityMatrix in Recommender API 6.2
1 call to Recommender::saveSimilarityMatrix()
File
- ./
Recommender.php, line 170
Class
- Recommender
- The super class for all other Recommender algorithms.
Code
protected function saveSimilarityMatrix($lowerbound = 0) {
watchdog('recommender', "Saving similarity result to database. Please wait.");
$map = array_flip($this->mouseMap);
//$m = $this->getMouseNum();
$data = array();
$values = $this->similarityMatrix
->raw_values();
//for ($v1=0; $v1<$m; $v1++) {
// for ($v2=0; $v2<$m; $v2++) {
foreach ($map as $v1 => $mouse1) {
foreach ($map as $v2 => $mouse2) {
if (!isset($values[$v1][$v2])) {
continue;
}
// we might skip if it's undefined.
$score = $values[$v1][$v2];
if (!is_nan($score) && $score >= $lowerbound) {
$data[] = "({$this->appId}, {$mouse1}, {$mouse2}, {$score}, {$this->created})";
}
// end of if (score)
}
// end of for($v2)
}
// end of for($v1)
$this
->batchInsert("INSERT INTO {recommender_similarity}(app_id, mouse1_id, mouse2_id, similarity, created) VALUES", $data);
}