You are here

protected function Recommender::loadSimilarityMatrix in Recommender API 6.2

2 calls to Recommender::loadSimilarityMatrix()
CorrelationRecommender::computePrediction in ./Recommender.php
Recommender::computePrediction in ./Recommender.php

File

./Recommender.php, line 193

Class

Recommender
The super class for all other Recommender algorithms.

Code

protected function loadSimilarityMatrix() {
  watchdog('recommender', "Please be patient while loading similarity data into memory. This step may fail if you don't have enough memory");
  $sql = "SELECT mouse1_id, mouse2_id, similarity FROM {recommender_similarity} WHERE app_id={$this->appId}";
  $result = db_query($sql);
  $m = $this
    ->getMouseNum();

  // create the matrix, might fail if not enough memory.
  $this->similarityMatrix = Matrix::create('SparseMatrix', $m, $m);
  $this->mouseMap = array();

  // build the matrix
  while ($line = db_fetch_array($result)) {
    $id_mouse1 = $line["mouse1_id"];
    $id_mouse2 = $line["mouse2_id"];
    $weight = $line["similarity"];
    if (!array_key_exists($id_mouse1, $this->mouseMap)) {
      $this->mouseMap[$id_mouse1] = count($this->mouseMap);
    }
    if (!array_key_exists($id_mouse2, $this->mouseMap)) {
      $this->mouseMap[$id_mouse2] = count($this->mouseMap);
    }
    $this->similarityMatrix
      ->set($this->mouseMap[$id_mouse1], $this->mouseMap[$id_mouse2], $weight);
    $this->similarityMatrix
      ->set($this->mouseMap[$id_mouse2], $this->mouseMap[$id_mouse1], $weight);
  }
}