You are here

function Vector::mean in Recommender API 6.2

Same name and namespace in other branches
  1. 7.6 classes/Matrix.php \Vector::mean()

Calculate the mean. This works for SparseMatrix too.

Parameters

$may_cache:

Return value

mean value

2 calls to Vector::mean()
Vector::covariance in ./Matrix.php
Compute covariance with $vector. No caching option. Works for RealVector. SparseVector needs additional handling.
Vector::variance in ./Matrix.php
Calculate the variance. This works for SparseMatrix too.

File

./Matrix.php, line 210

Class

Vector
This is the Vector superclass. @author danithaca

Code

function mean($may_cache = FALSE) {
  if (!$may_cache || $this->mean === NULL) {

    // force calculation
    $count = $this
      ->count($may_cache);
    $this->mean = $count == 0 ? NAN : array_sum($this->values) / $count;
  }
  return $this->mean;
}