Class: Matrix

Matrix(elements, useClone)

Class representing a Matrix and some of the possible operations.

Constructor

new Matrix(elements, useClone)

Constructor of the class
Parameters:
Name Type Default Description
elements Array.<Array.<Number>> | Matrix Elements for initializing the matrix.
useClone boolean true If true, the input array is cloned. If false, it uses the elements input directly by reference.
Source:

Methods

(static) fill(n, m, v) → {Array.<Array.<Number>>|Matrix}

Creates a new Matrix with given dimensions and filled with the cell value.
Parameters:
Name Type Description
n Number Amount of rows.
m Number Amount of columns.
v Number Cell value.
Source:
Returns:
Matrix with given dimensions and cell value.
Type
Array.<Array.<Number>> | Matrix

(static) one(n, m) → {Matrix}

Creates a new Matrix with given dimensions and filled with 1.
Parameters:
Name Type Description
n Number Amount of rows.
m Number Amount of columns.
Source:
Returns:
Matrix with given dimensions filled with 1.
Type
Matrix

(static) zero(n, m) → {Matrix}

Creates a new Matrix with given dimensions and filled with 0.
Parameters:
Name Type Description
n Number Amount of rows.
m Number Amount of columns.
Source:
Returns:
Matrix with given dimensions filled with 0.
Type
Matrix

augment(matrix) → {Matrix}

Return a matrix where is row is augmented with the corresponding row of the input matrix.
Parameters:
Name Type Description
matrix Array.<Array.<Number>> | Matrix Input matrix.
Source:
Returns:
Matrix that is this one augmented with the input one.
Type
Matrix

column(j) → {Vector}

Return a column of the matrix as a vector.
Parameters:
Name Type Description
j Number Column number.
Source:
Returns:
Column of the matrix as a vector.
Type
Vector

isSameColumnToRowSize(matrix) → {boolean}

Indicates if another matrix has exactly same amount of rows as this matrix amount of columns.
Parameters:
Name Type Description
matrix Array.<Array.<Number>> | Array.<Number> | Matrix | Vector Input matrix.
Source:
Returns:
True if this one column count equals input row count.
Type
boolean

isSameSizeAs(matrix) → {boolean}

Indicates if another matrix has exactly same dimensions as this one.
Parameters:
Name Type Description
matrix Array.<Array.<Number>> | Array.<Number> | Matrix | Vector Input matrix.
Source:
Returns:
True if both have same number of rows and columns.
Type
boolean

log() → {Matrix}

Returns a new matrix where each cell is the natural logarithm of the input element.
Source:
Returns:
Logarithm matrix.
Type
Matrix

map(fn) → {Matrix}

Creates a new matrix where each element is the result of executiong the provided function with signature (element, i, j).
Parameters:
Name Type Description
fn function Function for calculating each element.
Source:
Returns:
Resulting mapped matrix.
Type
Matrix

mulOp(matrix, op) → {Matrix}

Given a matrix an an operation function, applies this operation multiplying this matrix with the provided one.
Parameters:
Name Type Description
matrix Matrix Matrix to operate with this.
op function Multiply operation.
Source:
Returns:
Result matrix of multiplying both matrix.
Type
Matrix

multiply(matrix, activation) → {Matrix}

Multiply two matrix.
Parameters:
Name Type Description
matrix Matrix Input matrix.
activation function Optional activation fucntion.
Source:
Returns:
Multiplication of the matrix.
Type
Matrix

row(i) → {Vector}

Return a row of the matrix as a vector.
Parameters:
Name Type Description
i Number Row number.
Source:
Returns:
Row of the matrix as a vector.
Type
Vector

rowCount() → {Number}

Return the amount of rows of the matrix.
Source:
Returns:
Amount of rows of the matrix.
Type
Number

setElements(els)

Clone the input elemnts and assign to this instance elements.
Parameters:
Name Type Description
els Array.<Array.<Number>> | Matrix Input elements.
Source:

subtract(matrix)

Performs a substraction element by element between two matrix.
Parameters:
Name Type Description
matrix Matrix Input matrix.
Source:

transpose() → {Matrix}

Creates a new Matrix that is the transposed of this one (rows become columns).
Source:
Returns:
Matrix that is transposed of this one.
Type
Matrix