function SparseVector::common_items in Recommender API 6.2
Same name and namespace in other branches
- 7.6 classes/Matrix.php \SparseVector::common_items()
2 calls to SparseVector::common_items()
- SparseVector::correlation in ./
Matrix.php - Compute correlation with $vector. No caching option. Works for RealVector. SparseVector needs additional handling.
- SparseVector::covariance in ./
Matrix.php - Compute covariance with $vector. No caching option. Works for RealVector. SparseVector needs additional handling.
File
- ./
Matrix.php, line 301
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;
}