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