You are here

function Vector::mean in Recommender API 7.6

Same name and namespace in other branches
  1. 6.2 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 classes/Matrix.php
Compute covariance with $vector. No caching option. Works for RealVector. SparseVector needs additional handling.
Vector::variance in classes/Matrix.php
Calculate the variance. This works for SparseMatrix too.

File

classes/Matrix.php, line 205

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;
}