Np

matrix extends nd
in package
Uses ops, linAlg

Matrix A fast lite memory efficient Scientific Computing for php

Tags
category

Scientific Computing

author

ghost (Shubham Chaudhary)

email

ghost.jat@gmail.com

copyright

(c) 2020-2021, Shubham Chaudhary

Table of Contents

DOUBLE  = 2
EPSILON  = 1.0E-8
FLOAT  = 1
INT  = 3
TWO_PI  = 2.0 * M_PI
$data  : mixed
$_mem  : mixed
$_time  : mixed
__toString()  : mixed
abs()  : matrix|vector
acos()  : matrix|vector
addScaleRow()  : mixed
ar()  : matrix
create 2d matrix using php array
argMax()  : vector
Return the index of the maximum element in every row of the matrix.
argMin()  : vector
Return the index of the minimum element in every row of the matrix.
asArray()  : array<string|int, mixed>
Return the elements of the matrix in a 2-d array.
asin()  : matrix|vector
asVector()  : vector
Flatten i.e unravel the matrix into a vector.
atan()  : matrix|vector
ceil()  : matrix|vector
checkDimensions()  : mixed
checkDtype()  : mixed
checkShape()  : mixed
cholesky()  : matrix|null
Return the lower triangular matrix of the Cholesky decomposition.
clip()  : matrix
Clip the elements in the matrix to be between given minimum and maximum and return a new matrix.
clipLower()  : matrix
Clip the matrix|vector to be lower bounded by a given minimum.
clipUpper()  : matrix
Clip the matrix|vector to be upper bounded by a given maximum.
colAsVector()  : vector
Return a col as vector from the matrix.
convolve()  : matrix
2D convolution between a matrix ma and kernel kb, with a given stride.
copy()  : matrix|vector
make a copy of matrix|vector;
cos()  : matrix|vector
covariance()  : matrix
Compute the covariance matrix.
degToRad()  : matrix|vector
det()  : float
Calculate the determinant of the matrix.
diagonal()  : matrix
create a diagonal 2d matrix with given 1d array;
diagonalAsVector()  : vector
Return the diagonal elements of a square matrix as a vector.
dignoalInterChange()  : mixed
dignoalInterChange
diminish_left()  : matrix
diminish_right()  : matrix
divide()  : matrix
Return the division of two elements, element-wise.
dot()  : matrix|vector
get dot product of m.m | m.v | v.v
eign()  : eigen
Compute the eigen decomposition of a general matrix.
equal()  : matrix
exp()  : matrix|vector
exp1()  : matrix|vector
factory()  : matrix
create empty 2d matrix for given data type
floor()  : matrix|vector
free()  : void
full()  : matrix
create a 2d matrix with given scalar value
gaussian()  : matrix
Return a standard normally distributed random matrix i.e values between -1 and 1.
getDiagonalVal()  : float
get a diagonal value from matrix
getDtype()  : int
get the matrix data type
getMemory()  : mixed
set memory dog, get total memory
getShape()  : object
get the shape of matrix
getSize()  : int
get the number of elements in the matrix.
greater()  : matrix
has_ZeroRow()  : bool
identity()  : matrix
create an identity matrix with the given dimensions.
inverse()  : matrix|null
FIXEME:-Bug noticed on 10/06/21 Compute the multiplicative inverse of the matrix.
is_rowZero()  : bool
is row zero
is_zero()  : bool
isSquare()  : bool
is matrix squred
isSymmetric()  : bool
Is the matrix symmetric i.e. is it equal to its own transpose?
joinAbove()  : matrix
Join matrix m Above this matrix.
joinBelow()  : matrix
Join matrix m below this matrix.
joinLeft()  : matrix
Attach given matrix to the left of this matrix.
joinRight()  : matrix
Join matrix m to the Right of this matrix.
less()  : matrix
log()  : matrix|vector
log1p()  : matrix|vector
lu()  : lu
Compute the LU factorization of matrix.
map()  : matrix|vector
Run a function over all of the elements in the matrix|vector.
max()  : matrix|vector
Return the element-wise maximum of two matrices| two vectors.
mean()  : vector
Compute the means of each row and return them in a vector.
median()  : vector
Return the median vector of this matrix.
min()  : matrix|vector
Return the element-wise minimum of two matrices|two vectors.
mod()  : matrix
Calculate the modulus i.e remainder of division between this matrix and another matrix.
multiply()  : matrix|vector
multiply this matrix with another matrix|scalar element-wise Matrix Scalar\Matrix multiplication
normFrob()  : float
Return the Frobenius norm of the matrix.
normINF()  : float
Return the L1 norm of the matrix.
normL1()  : float
Return the L1 norm of the matrix.
normL2()  : float
Return the L2 norm of the matrix.
null()  : matrix
create a null like 2d matrix
ones()  : matrix
create one like 2d matrix
poisson()  : matrix
Generate a m x n matrix with elements from a Poisson distribution.
pow()  : matrix
Raise this matrix to the power of the element-wise entry in another matrix.
printMatrix()  : mixed
print the matrix in consol
pseudoInverse()  : matrix|null
FIXEME:-Bug noticed on 10/06/21 Compute the (Moore-Penrose) pseudo inverse of the general matrix.
radToDeg()  : matrix|vector
randn()  : matrix
Create Matrix with random values
reciprocal()  : matrix
Return the element-wise reciprocal of the matrix.
ref()  : matrix|null
Calculate the row echelon form of the matrix.
reshape()  : matrix
return a reshaped data buffer as matrix
rowAsVector()  : vector
Return a row as vector from the matrix.
rref()  : matrix
FIXME-------------- RREF The reduced row echelon form (RREF) of a matrix.
scale()  : matrix
scaleCol()  : mixed
scale all the elements of
scaleDigonalCol()  : mixed
Scale digonally
scaleRow()  : mixed
scale all the elements of a row
setData()  : void
Set given data in matrix
sin()  : matrix|vector
sqrt()  : matrix|vector
square()  : matrix
Square of matrix
subtract()  : matrix
subtract another matrix, vector or a scalar to this matrix
subtractColumnVector()  : matrix
sum()  : matrix
Sum of two matrix, vector or a scalar to current matrix
sumRows()  : vector
Sum of Rows of matrix
svd()  : object
Compute the singular value decomposition of a matrix and return an object of the singular values and unitary matrices
swapCols()  : mixed
swap specific cols in matrix
swapRows()  : mixed
swap specific rows in matrix
swapValue()  : mixed
swap specific values in matrix
tan()  : matrix|vector
time()  : mixed
set Timer, get total time
trace()  : float
Return the trace of the matrix i.e the sum of all diagonal elements of a square matrix.
transpose()  : matrix
Transpose the matrix i.e row become cols and cols become rows.
uniform()  : matrix
Return 2d matrix with uniform values
variance()  : vector
Compute the row variance of the matrix.
zeros()  : matrix
Return a zero matrix with the given dimensions.
__construct()  : $this
_dimensionaMisMatchErr()  : dimensionalityMismatch
_dtypeErr()  : dtypeException
_err()  : runtimeException
_invalidArgument()  : invalidArgumentException
_ndDouble()  : mixed
_ndFloat()  : mixed
_ndInt()  : mixed
divideMatrix()  : matrix
divideScalar()  : matrix
divideVector()  : matrix
dotMatrix()  : matrix
get matrix & matrix dot product
dotVector()  : vector
get dot product of matrix & a vector
equalMatrix()  : matrix
equalScalar()  : matrix
equalVector()  : matrix
greaterMatrix()  : matrix
greaterScalar()  : matrix
greaterVector()  : matrix
modMatrix()  : matrix
modScalar()  : matrix
modVector()  : matrix
multiplyMatrix()  : matrix
multiplyVector()  : matrix
powMatrix()  : matrix
powScalar()  : matrix
powVector()  : matrix
subtractMatrix()  : matrix
subtractScalar()  : matrix
subtractVector()  : matrix
sumMatrix()  : matrix
sumScalar()  : matrix
sumVector()  : matrix
flattenArray()  : mixed

Constants

DOUBLE

public mixed DOUBLE = 2

EPSILON

public mixed EPSILON = 1.0E-8

FLOAT

public mixed FLOAT = 1

INT

public mixed INT = 3

TWO_PI

public mixed TWO_PI = 2.0 * M_PI

Properties

$data

public mixed $data

$_mem

protected mixed $_mem = null

$_time

protected mixed $_time = null

Methods

__toString()

public __toString() : mixed
Return values
mixed

addScaleRow()

public addScaleRow(int $r1, int $r2, float $c) : mixed
Parameters
$r1 : int
$r2 : int
$c : float
Return values
mixed

ar()

create 2d matrix using php array

public static ar(array<string|int, mixed> $data[, int $dtype = self::FLOAT ]) : matrix
Parameters
$data : array<string|int, mixed>
$dtype : int = self::FLOAT

matrix data type float|double

Return values
matrix

argMax()

Return the index of the maximum element in every row of the matrix.

public argMax() : vector
Return values
vector

int

argMin()

Return the index of the minimum element in every row of the matrix.

public argMin() : vector
Return values
vector

int

asArray()

Return the elements of the matrix in a 2-d array.

public asArray() : array<string|int, mixed>
Return values
array<string|int, mixed>

asVector()

Flatten i.e unravel the matrix into a vector.

public asVector() : vector
Return values
vector

cholesky()

Return the lower triangular matrix of the Cholesky decomposition.

public cholesky() : matrix|null
Return values
matrix|null

clip()

Clip the elements in the matrix to be between given minimum and maximum and return a new matrix.

public clip(float $min, float $max) : matrix
Parameters
$min : float
$max : float
Return values
matrix

clipLower()

Clip the matrix|vector to be lower bounded by a given minimum.

public clipLower(float $min) : matrix
Parameters
$min : float
Return values
matrix

clipUpper()

Clip the matrix|vector to be upper bounded by a given maximum.

public clipUpper(float $max) : matrix
Parameters
$max : float
Return values
matrix

colAsVector()

Return a col as vector from the matrix.

public colAsVector(int $index) : vector
Parameters
$index : int
Return values
vector

convolve()

2D convolution between a matrix ma and kernel kb, with a given stride.

public convolve(matrix $m[, int $stride = 1 ]) : matrix
Parameters
$m : matrix
$stride : int = 1
Return values
matrix

covariance()

Compute the covariance matrix.

public covariance([vector|null $mean = null ]) : matrix
Parameters
$mean : vector|null = null
Return values
matrix

det()

Calculate the determinant of the matrix.

public det() : float
Return values
float

diagonal()

create a diagonal 2d matrix with given 1d array;

public static diagonal(array<string|int, mixed> $elements[, int $dtype = self::FLOAT ]) : matrix
Parameters
$elements : array<string|int, mixed>
$dtype : int = self::FLOAT
Return values
matrix

diagonalAsVector()

Return the diagonal elements of a square matrix as a vector.

public diagonalAsVector() : vector
Return values
vector

dignoalInterChange()

dignoalInterChange

public dignoalInterChange() : mixed
Return values
mixed

diminish_left()

public diminish_left(int $cols) : matrix
Parameters
$cols : int
Return values
matrix

diminish_right()

public diminish_right(int $cols) : matrix
Parameters
$cols : int
Return values
matrix

divide()

Return the division of two elements, element-wise.

public divide(int|float|matrix $d) : matrix
Parameters
$d : int|float|matrix
Return values
matrix

eign()

Compute the eigen decomposition of a general matrix.

public eign([bool $symmetric = false ]) : eigen

return the eigenvalues and eigenvectors as object

Parameters
$symmetric : bool = false
Return values
eigen

factory()

create empty 2d matrix for given data type

public static factory(int $row, int $col[, int $dtype = self::FLOAT ]) : matrix
Parameters
$row : int

num of rows

$col : int

num of cols

$dtype : int = self::FLOAT

matrix data type float|double

Return values
matrix

free()

public free() : void
Return values
void

full()

create a 2d matrix with given scalar value

public static full(int $row, int $col, int|float $val[, int $dtype = self::FLOAT ]) : matrix
Parameters
$row : int
$col : int
$val : int|float
$dtype : int = self::FLOAT
Return values
matrix

gaussian()

Return a standard normally distributed random matrix i.e values between -1 and 1.

public static gaussian(int $row, int $col[, int $dtype = self::FLOAT ]) : matrix
Parameters
$row : int
$col : int
$dtype : int = self::FLOAT

Description

Return values
matrix

getDiagonalVal()

get a diagonal value from matrix

public getDiagonalVal(int $i) : float
Parameters
$i : int
Return values
float

getDtype()

get the matrix data type

public getDtype() : int
Return values
int

getMemory()

set memory dog, get total memory

public getMemory() : mixed
Return values
mixed

getShape()

get the shape of matrix

public getShape() : object
Return values
object

getSize()

get the number of elements in the matrix.

public getSize() : int
Return values
int

has_ZeroRow()

public has_ZeroRow() : bool
Return values
bool

identity()

create an identity matrix with the given dimensions.

public static identity(int $n[, int $dtype = self::FLOAT ]) : matrix
Parameters
$n : int
$dtype : int = self::FLOAT
Tags
throws
InvalidArgumentException
Return values
matrix

inverse()

FIXEME:-Bug noticed on 10/06/21 Compute the multiplicative inverse of the matrix.

public inverse() : matrix|null
Return values
matrix|null

is_rowZero()

is row zero

public is_rowZero(int $row) : bool
Parameters
$row : int
Return values
bool

is_zero()

public static is_zero(int|float $d) : bool
Parameters
$d : int|float
Return values
bool

isSquare()

is matrix squred

public isSquare() : bool
Return values
bool

isSymmetric()

Is the matrix symmetric i.e. is it equal to its own transpose?

public isSymmetric() : bool
Return values
bool

lu()

Compute the LU factorization of matrix.

public lu() : lu

return lower, upper, and permutation matrices as object.

Return values
lu

map()

Run a function over all of the elements in the matrix|vector.

public map(callable $func) : matrix|vector
Parameters
$func : callable
Return values
matrix|vector

mean()

Compute the means of each row and return them in a vector.

public mean() : vector
Return values
vector

median()

Return the median vector of this matrix.

public median() : vector
Return values
vector

normFrob()

Return the Frobenius norm of the matrix.

public normFrob() : float
Return values
float

normINF()

Return the L1 norm of the matrix.

public normINF() : float
Return values
float

normL1()

Return the L1 norm of the matrix.

public normL1() : float
Return values
float

normL2()

Return the L2 norm of the matrix.

public normL2() : float
Return values
float

null()

create a null like 2d matrix

public static null(int $row, int $col[, int $dtype = self::FLOAT ]) : matrix
Parameters
$row : int
$col : int
$dtype : int = self::FLOAT
Return values
matrix

ones()

create one like 2d matrix

public static ones(int $row, int $col[, int $dtype = self::FLOAT ]) : matrix
Parameters
$row : int
$col : int
$dtype : int = self::FLOAT
Return values
matrix

poisson()

Generate a m x n matrix with elements from a Poisson distribution.

public static poisson(int $row, int $col[, float $lambda = 1.0 ][, int $dtype = self::FLOAT ]) : matrix
Parameters
$row : int
$col : int
$lambda : float = 1.0
$dtype : int = self::FLOAT
Return values
matrix

printMatrix()

print the matrix in consol

public printMatrix() : mixed
Return values
mixed

pseudoInverse()

FIXEME:-Bug noticed on 10/06/21 Compute the (Moore-Penrose) pseudo inverse of the general matrix.

public pseudoInverse() : matrix|null
Return values
matrix|null

randn()

Create Matrix with random values

public static randn(int $row, int $col[, int $dtype = self::FLOAT ]) : matrix
Parameters
$row : int
$col : int
$dtype : int = self::FLOAT

Float|Double

Return values
matrix

reciprocal()

Return the element-wise reciprocal of the matrix.

public reciprocal() : matrix
Return values
matrix

ref()

Calculate the row echelon form of the matrix.

public ref() : matrix|null

Return the reduced matrix.

Return values
matrix|null

reshape()

return a reshaped data buffer as matrix

public reshape(int $row, int $col) : matrix
Parameters
$row : int
$col : int
Return values
matrix

rowAsVector()

Return a row as vector from the matrix.

public rowAsVector(int $index) : vector
Parameters
$index : int
Return values
vector

rref()

FIXME-------------- RREF The reduced row echelon form (RREF) of a matrix.

public rref() : matrix
Return values
matrix

scale()

public scale(int|float $scalar) : matrix
Parameters
$scalar : int|float
Return values
matrix

scaleCol()

scale all the elements of

public scaleCol(int $col, int|float $c) : mixed
Parameters
$col : int
$c : int|float
Return values
mixed

scaleDigonalCol()

Scale digonally

public scaleDigonalCol(int|float $c[, bool $lDig = true ]) : mixed
Parameters
$c : int|float
$lDig : bool = true
Return values
mixed

scaleRow()

scale all the elements of a row

public scaleRow(int $row, int|float $c) : mixed
Parameters
$row : int
$c : int|float
Return values
mixed

setData()

Set given data in matrix

public setData(int|float|array<string|int, mixed> $data[, bool $dignoal = false ]) : void
Parameters
$data : int|float|array<string|int, mixed>
$dignoal : bool = false
Return values
void

subtract()

subtract another matrix, vector or a scalar to this matrix

public subtract(int|float|matrix|vector $d) : matrix
Parameters
$d : int|float|matrix|vector

matrix|$scalar to subtract this matrix

Return values
matrix

svd()

Compute the singular value decomposition of a matrix and return an object of the singular values and unitary matrices

public svd() : object
Return values
object

(u,s,v)

swapCols()

swap specific cols in matrix

public swapCols(int $c1, int $c2) : mixed
Parameters
$c1 : int
$c2 : int
Return values
mixed

swapRows()

swap specific rows in matrix

public swapRows(int $r1, int $r2) : mixed
Parameters
$r1 : int
$r2 : int
Return values
mixed

swapValue()

swap specific values in matrix

public swapValue(int $i1, int $i2) : mixed
Parameters
$i1 : int
$i2 : int
Return values
mixed

time()

set Timer, get total time

public time() : mixed
Return values
mixed

trace()

Return the trace of the matrix i.e the sum of all diagonal elements of a square matrix.

public trace() : float
Return values
float

transpose()

Transpose the matrix i.e row become cols and cols become rows.

public transpose() : matrix
Return values
matrix

uniform()

Return 2d matrix with uniform values

public static uniform(int $row, int $col[, int $dtype = self::FLOAT ]) : matrix
Parameters
$row : int
$col : int
$dtype : int = self::FLOAT
Return values
matrix

variance()

Compute the row variance of the matrix.

public variance([vector|null $mean = null ]) : vector
Parameters
$mean : vector|null = null
Return values
vector

zeros()

Return a zero matrix with the given dimensions.

public static zeros(int $row, int $col[, int $dtype = self::FLOAT ]) : matrix
Parameters
$row : int
$col : int
$dtype : int = self::FLOAT
Return values
matrix

__construct()

protected __construct(int $row, int $col[, int $dtype = self::Float ]) : $this
Parameters
$row : int
$col : int
$dtype : int = self::Float
Return values
$this

_ndDouble()

protected static _ndDouble(int $size) : mixed
Parameters
$size : int
Return values
mixed

_ndFloat()

protected static _ndFloat(int $size) : mixed
Parameters
$size : int
Return values
mixed

_ndInt()

protected static _ndInt(int $size) : mixed
Parameters
$size : int
Return values
mixed

divideScalar()

protected divideScalar(int|float $s) : matrix
Parameters
$s : int|float
Return values
matrix

equalScalar()

protected equalScalar(int|float $s) : matrix
Parameters
$s : int|float
Return values
matrix

greaterScalar()

protected greaterScalar(int|float $s) : matrix
Parameters
$s : int|float
Return values
matrix

modScalar()

protected modScalar(int|float $s) : matrix
Parameters
$s : int|float
Return values
matrix

powScalar()

protected powScalar(int|float $s) : matrix
Parameters
$s : int|float
Return values
matrix

subtractScalar()

protected subtractScalar(int|float $s) : matrix
Parameters
$s : int|float
Return values
matrix

sumScalar()

protected sumScalar(int|float $s) : matrix
Parameters
$s : int|float
Return values
matrix

flattenArray()

private flattenArray(array<string|int, mixed> $ar) : mixed
Parameters
$ar : array<string|int, mixed>
Return values
mixed

Search results