You are here

function Vector::correlation in Recommender API 7.6

Same name and namespace in other branches
  1. 6.2 Matrix.php \Vector::correlation()

Compute correlation with $vector. No caching option. Works for RealVector. SparseVector needs additional handling.

Parameters

$vector it has to be the same type (either SparseVector or RealVector) as $this:

Return value

correlation value

1 method overrides Vector::correlation()
SparseVector::correlation in classes/Matrix.php
Compute correlation with $vector. No caching option. Works for RealVector. SparseVector needs additional handling.

File

classes/Matrix.php, line 271

Class

Vector
This is the Vector superclass. @author danithaca

Code

function correlation(&$vector) {
  $covariance = $this
    ->covariance($vector);
  if (is_nan($covariance)) {
    return NAN;
  }

  // might use cached std.
  $std_a = $this
    ->std(TRUE);
  $std_b = $vector
    ->std(TRUE);
  return $std_a == 0 || $std_b == 0 ? NAN : $covariance / ($std_a * $std_b);
}