You are here

static function Matrix::create in Recommender API 7.6

Same name and namespace in other branches
  1. 6.2 Matrix.php \Matrix::create()
3 calls to Matrix::create()
CFRecommender::computePrediction in classes/Recommender.php
CFRecommender::loadPreference in classes/Recommender.php
Load matrix from the database into a matrix class in memory
Matrix::correlation in classes/Matrix.php
Compute the covariance matrix for the row vectors.

File

classes/Matrix.php, line 21

Class

Matrix
This PHP file does not require Drupal. Including both Matrix and Vector implementation. Missing data are treated as NAN. Some extra complexity comes from trying to increase memory/cpu performance Note, this implementation does check input parameters.…

Code

static function create($type, $row, $column, $value = 0) {
  if ($type == 'SparseMatrix') {
    $matrix = new SparseMatrix();
    $matrix->values = array();
  }
  elseif ($type == 'RealMatrix') {
    $matrix = new RealMatrix();
    $matrix->values = array_fill(0, $row, array_fill(0, $column, $value));

    // #794284, need to assert $row and $column are greater than 0
  }
  else {
    trigger_error('Matrix type not recognized', E_USER_ERROR);
  }

  // $row, $column are the expected dimensions.
  // for SparseMatrix, $row[x]->count() might return 0, but the expected column number is still $column
  $matrix->row = $row;
  $matrix->column = $column;
  return $matrix;
}