You are here

function SparseVector::common_items in Recommender API 7.6

Same name and namespace in other branches
  1. 6.2 Matrix.php \SparseVector::common_items()
3 calls to SparseVector::common_items()
SparseVector::correlation in classes/Matrix.php
Compute correlation with $vector. No caching option. Works for RealVector. SparseVector needs additional handling.
SparseVector::covariance in classes/Matrix.php
Compute covariance with $vector. No caching option. Works for RealVector. SparseVector needs additional handling.
SparseVector::intersect_mean in classes/Matrix.php

File

classes/Matrix.php, line 297

Class

SparseVector
Sparse Vector takes care of missing data.

Code

function common_items(&$vector) {

  // for compatibility, we don't use pass by reference

  //$keys = array_intersect_key(&$this->values, &$vector->values);
  $keys = array_intersect_key($this->values, $vector->values);
  if (count($keys) == 0) {
    return NULL;
  }
  $array_a = array();
  $array_b = array();
  foreach ($keys as $key => $value) {
    $array_a[] = $this->values[$key];
    $array_b[] = $vector->values[$key];
  }
  $subset = array();
  $subset[] = Vector::wrap('RealVector', $array_a);
  $subset[] = Vector::wrap('RealVector', $array_b);
  return $subset;
}