UNPKG

@ai-on-browser/data-analysis-models

Version:

Data analysis model package without any dependencies

1,365 lines 58.3 kB
/** * Exception for matrix class */ export class MatrixException extends Error { /** * @param {string} message Error message * @param {*} value Some value */ constructor(message: string, value: any); value: any; } /** * Matrix class * @template [T=number] */ export default class Matrix<T = number> { /** * Returns a matrix filled with 0. * @overload * @param {number} rows Number of rows * @param {number} cols Number of columns * @returns {Matrix<number>} Matrix filled with 0 */ static zeros(rows: number, cols: number): Matrix<number>; /** * Returns a matrix filled with 0. * @overload * @param {[number, number]} size Sizes for each dimension * @returns {Matrix<number>} Matrix filled with 0 */ static zeros(size: [number, number]): Matrix<number>; /** * Returns a matrix filled with 1. * @overload * @param {number} rows Number of rows * @param {number} cols Number of columns * @returns {Matrix<number>} Matrix filled with 1 */ static ones(rows: number, cols: number): Matrix<number>; /** * Returns a matrix filled with 1. * @overload * @param {[number, number]} size Sizes for each dimension * @returns {Matrix<number>} Matrix filled with 1 */ static ones(size: [number, number]): Matrix<number>; /** * Returns a identity matrix. * @overload * @param {number} rows Number of rows * @param {number} cols Number of columns * @param {number} [init] Diagonal values * @returns {Matrix<number>} Identity matrix */ static eye(rows: number, cols: number, init?: number): Matrix<number>; /** * Returns a identity matrix. * @overload * @param {[number, number]} size Sizes for each dimension * @param {number} [init] Diagonal values * @returns {Matrix<number>} Identity matrix */ static eye(size: [number, number], init?: number): Matrix<number>; /** * Returns a matrix initialized uniform random values. * @overload * @param {number} rows Number of rows * @param {number} cols Number of columns * @param {number} [min] Minimum value of the Matrix (include) * @param {number} [max] Maximum value of the Matrix (exclude) * @returns {Matrix<number>} Matrix initialized uniform random values */ static random(rows: number, cols: number, min?: number, max?: number): Matrix<number>; /** * Returns a matrix initialized uniform random values. * @overload * @param {[number, number]} size Sizes for each dimension * @param {number} [min] Minimum value of the Matrix (include) * @param {number} [max] Maximum value of the Matrix (exclude) * @returns {Matrix<number>} Matrix initialized uniform random values */ static random(size: [number, number], min?: number, max?: number): Matrix<number>; /** * Returns a matrix initialized uniform random integer values. * @overload * @param {number} rows Number of rows * @param {number} cols Number of columns * @param {number} [min] Minimum value of the Matrix (include) * @param {number} [max] Maximum value of the Matrix (include) * @returns {Matrix<number>} Matrix initialized uniform random values */ static randint(rows: number, cols: number, min?: number, max?: number): Matrix<number>; /** * Returns a matrix initialized uniform random integer values. * @overload * @param {[number, number]} size Sizes for each dimension * @param {number} [min] Minimum value of the Matrix (include) * @param {number} [max] Maximum value of the Matrix (include) * @returns {Matrix<number>} Matrix initialized uniform random values */ static randint(size: [number, number], min?: number, max?: number): Matrix<number>; /** * Returns a matrix initialized normal random values. * @overload * @param {number} rows Number of rows * @param {number} cols Number of columns * @param {number | number[]} [myu] Mean value(s) of each columns * @param {number | Array<Array<number>>} [sigma] Variance value or covariance matrix of each columns * @returns {Matrix<number>} Matrix initialized normal random values */ static randn(rows: number, cols: number, myu?: number | number[], sigma?: number | Array<Array<number>>): Matrix<number>; /** * Returns a matrix initialized normal random values. * @overload * @param {[number, number]} rows Sizes for each dimension * @param {number | number[]} [myu] Mean value(s) of each columns * @param {number | Array<Array<number>>} [sigma] Variance value or covariance matrix of each columns * @returns {Matrix<number>} Matrix initialized normal random values */ static randn(rows: [number, number], myu?: number | number[], sigma?: number | Array<Array<number>>): Matrix<number>; /** * Returns a diagonal matrix. * @template T * @param {(T | Matrix<T>)[]} d Diagonal values * @returns {Matrix<T>} Diagonal matrix */ static diag<T_1>(d: (T_1 | Matrix<T_1>)[]): Matrix<T_1>; /** * Returns a matrix from some value. * @template T * @param {Matrix<T> | Array<Array<T>> | Array<T> | T} arr Original values * @returns {Matrix<T>} Matrix from some value */ static fromArray<T_2>(arr: T_2 | Matrix<T_2> | T_2[] | T_2[][]): Matrix<T_2>; /** * Returns a matrix that replace all the elements. * @template T,U * @param {Matrix<T>} mat Original matrix * @param {function (T, number[], Matrix<T>): U} cb Mapping function * @returns {Matrix<U>} Mapped matrix */ static map<T_3, U_2>(mat: Matrix<T_3>, cb: (arg0: T_3, arg1: number[], arg2: Matrix<T_3>) => U_2): Matrix<U_2>; /** * Return resized matrix. * @template T * @overload * @param {Matrix<T>} mat Original matrix * @param {number} rows New row size * @param {number} cols New column size * @param {T} [init] Value of the extended region * @returns {Matrix<T>} Resized matrix */ static resize<T_4>(mat: Matrix<T_4>, rows: number, cols: number, init?: T_4): Matrix<T_4>; /** * Return resized matrix. * @template T * @overload * @param {Matrix<T>} mat Original matrix * @param {[number, number]} rows New sizes for each dimension * @param {T} [init] Value of the extended region * @returns {Matrix<T>} Resized matrix */ static resize<T_4>(mat: Matrix<T_4>, rows: [number, number], init?: T_4): Matrix<T_4>; /** * Returns a matrix that repeat the elements n times along the axis. * @template T * @overload * @param {Matrix<T>} mat Original matrix * @param {number} n Repeated count * @param {number} [axis] Axis to be repeated * @returns {Matrix<T>} Repeated matrix */ static repeat<T_5>(mat: Matrix<T_5>, n: number, axis?: number): Matrix<T_5>; /** * Returns a matrix that repeat the elements n times along the axis. * @template T * @overload * @param {Matrix<T>} mat Original matrix * @param {number[]} n Repeated counts for each axis * @returns {Matrix<T>} Repeated matrix */ static repeat<T_5>(mat: Matrix<T_5>, n: number[]): Matrix<T_5>; /** * Returns a matrix concatenated this and m. * @template T,U * @param {Matrix<T>} a Original matrix * @param {Matrix<U>} b Concatenate matrix * @param {number} [axis] Axis to be concatenated * @returns {Matrix<T | U>} Concatenated matrix */ static concat<T_6, U_3>(a: Matrix<T_6>, b: Matrix<U_3>, axis?: number): Matrix<T_6 | U_3>; /** * Returns a matrix that add two values. * @param {Matrix<number> | number} a Left value * @param {Matrix<number> | number} b Right value * @returns {Matrix<number>} Added matrix */ static add(a: Matrix<number> | number, b: Matrix<number> | number): Matrix<number>; /** * Returns a matrix that subtract two values. * @param {Matrix<number> | number} a Left value * @param {Matrix<number> | number} b Right value * @returns {Matrix<number>} Subtracted matrix */ static sub(a: Matrix<number> | number, b: Matrix<number> | number): Matrix<number>; /** * Returns a matrix that multiplies by two values element-wise. * @param {Matrix<number> | number} a Left value * @param {Matrix<number> | number} b Right value * @returns {Matrix<number>} Multiplied matrix */ static mult(a: Matrix<number> | number, b: Matrix<number> | number): Matrix<number>; /** * Returns a matrix that divides by two values element-wise. * @param {Matrix<number> | number} a Left value * @param {Matrix<number> | number} b Right value * @returns {Matrix<number>} Divided matrix */ static div(a: Matrix<number> | number, b: Matrix<number> | number): Matrix<number>; /** * Returns a matrix that takes a remainder divided by two values element-wise. * @param {Matrix<number> | number} a Left value * @param {Matrix<number> | number} b Right value * @returns {Matrix<number>} Remainder matrix */ static mod(a: Matrix<number> | number, b: Matrix<number> | number): Matrix<number>; /** * Returns a matrix that takes logical AND two values. * @param {Matrix<unknown> | number} a Left value * @param {Matrix<unknown> | number} b Right value * @returns {Matrix<number>} Logical AND matrix */ static and(a: Matrix<unknown> | number, b: Matrix<unknown> | number): Matrix<number>; /** * Returns a matrix that takes logical OR two values. * @param {Matrix<unknown> | number} a Left value * @param {Matrix<unknown> | number} b Right value * @returns {Matrix<number>} Logical OR matrix */ static or(a: Matrix<unknown> | number, b: Matrix<unknown> | number): Matrix<number>; /** * Returns a matrix that takes bitwise AND two values. * @param {Matrix<number> | number} a Left value * @param {Matrix<number> | number} b Right value * @returns {Matrix<number>} Bitwise AND matrix */ static bitand(a: Matrix<number> | number, b: Matrix<number> | number): Matrix<number>; /** * Returns a matrix that takes bitwise OR two values. * @param {Matrix<number> | number} a Left value * @param {Matrix<number> | number} b Right value * @returns {Matrix<number>} Bitwise OR matrix */ static bitor(a: Matrix<number> | number, b: Matrix<number> | number): Matrix<number>; /** * Returns a matrix that takes bitwise XOR two values. * @param {Matrix<number> | number} a Left value * @param {Matrix<number> | number} b Right value * @returns {Matrix<number>} Bitwise XOR matrix */ static bitxor(a: Matrix<number> | number, b: Matrix<number> | number): Matrix<number>; /** * @overload * @param {number} rows Number of rows * @param {number} cols Number of columns * @param {T | Array<T> | Array<Array<T>>} [values] Initial values */ constructor(rows: number, cols: number, values?: T | Array<T> | Array<Array<T>>); /** * @overload * @param {[number, number]} size Sizes for each dimension * @param {T | Array<T> | Array<Array<T>>} [values] Initial values */ constructor(size: [number, number], values?: T | Array<T> | Array<Array<T>>); /** @private */ private _value; /** @private */ private _size; /** * Dimension of the matrix. * @type {number} */ get dimension(): number; /** * Sizes of the matrix. * @type {number[]} */ get sizes(): number[]; /** * Number of all elements in the matrix. * @type {number} */ get length(): number; /** * Number of rows of the matrix. * @type {number} */ get rows(): number; /** * Number of columns of the matrix. * @type {number} */ get cols(): number; /** * Elements in the matrix. * @type {T[]} */ get value(): T[]; /** * Transpose matrix. * @type {Matrix<T>} */ get t(): Matrix<T>; /** * Returns a nested array represented this matrix. * @returns {Array<Array<T>>} Nested array */ toArray(): Array<Array<T>>; /** * Returns the only element. * @returns {T} The only element */ toScaler(): T; /** * Returns a string represented this matrix. * @returns {string} String represented this matrix */ toString(): string; /** * Returns a copy of this matrix. * @param {Matrix<T>} [dst] Destination matrix * @returns {Matrix<T>} Copied matrix */ copy(dst?: Matrix<T>): Matrix<T>; /** * Returns this matrix is equals to the others. * @param {*} other Check tensor * @param {number} [tol] Tolerance to be recognized as the same * @returns {boolean} `true` if equal */ equals(other: any, tol?: number): boolean; /** * Returns a value at the position. * @overload * @param {number} r Row index * @param {number} c Column index * @returns {T} Value at the position */ at(r: number, c: number): T; /** * Returns a value at the position. * @overload * @param {[number, number]} index Index values * @returns {T} Value at the position */ at(index: [number, number]): T; /** * Set a value at the position. * @overload * @param {number} r Row index * @param {number} c Column index * @param {T | Matrix<T>} value The value to be set * @returns {T=} Old value */ set(r: number, c: number, value: T | Matrix<T>): T | undefined; /** * Set a value at the position. * @overload * @param {[number, number]} r Index values * @param {T | Matrix<T>} value The value to be set * @returns {T=} Old value */ set(r: [number, number], value: T | Matrix<T>): T | undefined; /** * Returns a row matrix at r. * @param {number | number[] | boolean[]} r Indexes of rows, or an array of boolean values where the row to be selected is true. * @returns {Matrix<T>} Row selected matrix */ row(r: number | number[] | boolean[]): Matrix<T>; /** * Returns a col matrix at c. * @param {number | number[] | boolean[]} c Indexes of columns, or an array of boolean values where the column to be selected is true. * @returns {Matrix<T>} Column selected matrix */ col(c: number | number[] | boolean[]): Matrix<T>; /** * Returns sliced matrix. * @param {number} from Start index * @param {number} to End index * @param {number} [axis] Axis to be sliced * @returns {Matrix<T>} Sliced matrix */ slice(from: number, to: number, axis?: number): Matrix<T>; /** * Returns the sub-matrix corresponding to position. * @param {number} [rows_from] Start row index * @param {number} [cols_from] Start column index * @param {number} [rows_to] End row index(exclusive) * @param {number} [cols_to] End column index(exclusive) * @returns {Matrix<T>} Sub matrix */ block(rows_from?: number, cols_from?: number, rows_to?: number, cols_to?: number): Matrix<T>; /** * Remove specified indexes. * @param {number | number[]} idx Remove index * @param {number<T>} [axis] Axis to be removed */ remove(idx: number | number[], axis?: number): void; /** * Remove specified indexes. * @param {function (Matrix<T>): boolean} cond Remove condition function. Remove if it returns `true` * @param {number<T>} [axis] Axis to be removed */ removeIf(cond: (arg0: Matrix<T>) => boolean, axis?: number): void; /** * Returns a matrix that sampled along the axis. * @param {number} n Sampled size * @param {number} [axis] Axis to be sampled * @param {boolean} [duplicate] Allow duplicate index or not * @returns {[Matrix<T>, number[]]} Sampled matrix and its original indexes */ sample(n: number, axis?: number, duplicate?: boolean): [Matrix<T>, number[]]; /** * Fill in all the elements with the value. * @param {T} value Filled value */ fill(value: T): void; /** * Iterate over all the elements and replace the value. * @param {function (T, number[], Matrix<T>): T} cb Mapping function */ map(cb: (arg0: T, arg1: number[], arg2: Matrix<T>) => T): void; /** * Iterate over all the elements. * @param {function (T, number[], Matrix<T>): *} cb Callback function */ forEach(cb: (arg0: T, arg1: number[], arg2: Matrix<T>) => any): void; /** * Returns transpose matrix. * @returns {Matrix<T>} Transposed matrix */ transpose(): Matrix<T>; /** * Returns adjoint matrix. * @returns {Matrix<T>} Adjoint matrix */ adjoint(): Matrix<T>; /** * Flip values along the axis. * @param {number} [axis] Axis to be flipped */ flip(axis?: number): void; /** * Swap the index a and b along the axis. * @param {number} a First index * @param {number} b Second index * @param {number} [axis] Axis to be swapped */ swap(a: number, b: number, axis?: number): void; /** * Sort values along the axis. * @param {number} [axis] Axis to be sorted * @returns {number[]} Original index. */ sort(axis?: number): number[]; /** * Shuffle values along the axis. * @param {number} [axis] Axis to be shuffled * @returns {number[]} Original index. */ shuffle(axis?: number): number[]; /** * Make it unique in the specified axis. * @param {number} [axis] Axis to be uniqued * @param {number} [tol] Tolerance to be recognized as the same * @returns {number[]} Selected indexes */ unique(axis?: number, tol?: number): number[]; /** * Resize this matrix. * @overload * @param {number} rows New row size * @param {number} cols New column size * @param {T} [init] Value of the extended region */ resize(rows: number, cols: number, init?: T): any; /** * Resize this matrix. * @overload * @param {[number, number]} size New sizes for each dimension * @param {T} [init] Value of the extended region */ resize(size: [number, number], init?: T): any; /** * Reshape this. * @overload * @param {number} rows New row size * @param {number} cols New column size */ reshape(rows: number, cols: number): any; /** * Reshape this. * @overload * @param {[number, number]} sizes New sizes for each dimension */ reshape(sizes: [number, number]): any; /** * Repeat the elements n times along the axis this. * @overload * @param {number} n Repeated count * @param {number} [axis] Axis to be repeated * @returns {void} No return */ repeat(n: number, axis?: number): void; /** * Repeat the elements n times along the axis this. * @overload * @param {number[]} n Repeated counts for each axis * @returns {void} No return */ repeat(n: number[]): void; /** * Concatenate this and m. * @param {Matrix<T>} m Concatenate matrix * @param {number} [axis] Axis to be concatenated */ concat(m: Matrix<T>, axis?: number): void; /** * Returns a matrix reduced along all element with the callback function. * @template U * @overload * @param {function (U, T, number[], Matrix<T>): U} cb Reducing function * @param {U} [init] Initial value * @returns {U} Reduced value */ reduce<U>(cb: (arg0: U, arg1: T, arg2: number[], arg3: Matrix<T>) => U, init?: U): U; /** * Returns a matrix reduced along the axis with the callback function. * @template U * @overload * @param {function (U, T, number[], Matrix<T>): U} cb Reducing function * @param {U} init Initial value * @param {0 | 1} axis Axis to be reduced * @param {boolean} [keepdims] Keep dimensions or not. If null, negative axis retuns number and other axis returns Matrix. * @returns {Matrix<U>} Reduced matrix */ reduce<U>(cb: (arg0: U, arg1: T, arg2: number[], arg3: Matrix<T>) => U, init: U, axis: 0 | 1, keepdims?: boolean): Matrix<U>; /** * Returns a matrix reduced along the axis with the callback function. * @template U * @overload * @param {function (U, T, number[], Matrix<T>): U} cb Reducing function * @param {U} init Initial value * @param {number | number[]} axis Axis to be reduced. If negative, reduce along all elements. * @param {boolean} [keepdims] Keep dimensions or not. If null, negative axis retuns number and other axis returns Matrix. * @returns {Matrix<U> | U} Reduced matrix or value */ reduce<U>(cb: (arg0: U, arg1: T, arg2: number[], arg3: Matrix<T>) => U, init: U, axis: number | number[], keepdims?: boolean): U | Matrix<U>; /** * Determines whether all the members of a matrix satisfy the specified test. * @overload * @param {function (T, number[], Matrix<T>): boolean} cb Check function * @returns {boolean} Reduced value or matrix */ every(cb: (arg0: T, arg1: number[], arg2: Matrix<T>) => boolean): boolean; /** * Determines whether all the members of a matrix satisfy the specified test. * @overload * @param {function (T, number[], Matrix<T>): boolean} cb Check function * @param {0 | 1} axis Axis to be reduced * @returns {Matrix<boolean>} Reduced value or matrix */ every(cb: (arg0: T, arg1: number[], arg2: Matrix<T>) => boolean, axis: 0 | 1): Matrix<boolean>; /** * Determines whether all the members of a matrix satisfy the specified test. * @overload * @param {function (T, number[], Matrix<T>): boolean} cb Check function * @param {number} axis Axis to be reduced * @returns {boolean | Matrix<boolean>} Reduced value or matrix */ every(cb: (arg0: T, arg1: number[], arg2: Matrix<T>) => boolean, axis: number): boolean | Matrix<boolean>; /** * Determines whether the specified callback function returns true for any element of a matrix. * @overload * @param {function (T, number[], Matrix<T>): boolean} cb Check function * @returns {boolean} Reduced value or matrix */ some(cb: (arg0: T, arg1: number[], arg2: Matrix<T>) => boolean): boolean; /** * Determines whether the specified callback function returns true for any element of a matrix. * @overload * @param {function (T, number[], Matrix<T>): boolean} cb Check function * @param {0 | 1} axis Axis to be reduced * @returns {Matrix<boolean>} Reduced value or matrix */ some(cb: (arg0: T, arg1: number[], arg2: Matrix<T>) => boolean, axis: 0 | 1): Matrix<boolean>; /** * Determines whether the specified callback function returns true for any element of a matrix. * @overload * @param {function (T, number[], Matrix<T>): boolean} cb Check function * @param {number} axis Axis to be reduced * @returns {boolean | Matrix<boolean>} Reduced value or matrix */ some(cb: (arg0: T, arg1: number[], arg2: Matrix<T>) => boolean, axis: number): boolean | Matrix<boolean>; /** * Returns maximum value of all element. * @overload * @returns {number} Maximum value */ max(): number; /** * Returns maximum values along the axis. * @overload * @param {0 | 1} axis Axis to be reduced * @returns {Matrix<number>} Maximum values */ max(axis: 0 | 1): Matrix<number>; /** * Returns maximum values along the axis. * @overload * @param {number} axis Axis to be reduced. If negative, returns the maximum value of the all element. * @returns {Matrix<number> | number} Maximum values */ max(axis: number): Matrix<number> | number; /** * Returns minimum value of all element. * @overload * @returns {number} Minimum value */ min(): number; /** * Returns minimum values along the axis. * @overload * @param {0 | 1} axis Axis to be reduced * @returns {Matrix<number>} Minimum values */ min(axis: 0 | 1): Matrix<number>; /** * Returns minimum values along the axis. * @overload * @param {number} axis Axis to be reduced. If negative, returns the minimum value of the all element. * @returns {Matrix<number> | number} Minimum values */ min(axis: number): Matrix<number> | number; /** * Returns median of all element. * @overload * @returns {number} Median value */ median(): number; /** * Returns medians along the axis. * @overload * @param {0 | 1} axis Axis to be reduced * @returns {Matrix<number>} Median values */ median(axis: 0 | 1): Matrix<number>; /** * Returns medians along the axis. * @overload * @param {number} axis Axis to be reduced. If negative, returns a median of the all element. * @returns {Matrix<number> | number} Median values */ median(axis: number): Matrix<number> | number; /** * Returns quantile value of all element. * @overload * @param {number} q Partition rate * @returns {number} Quantile value */ quantile(q: number): number; /** * Returns quantile values along the axis. * @overload * @param {number} q Partition rate * @param {0 | 1} axis Axis to be reduced * @returns {Matrix<number>} Quantile values */ quantile(q: number, axis: 0 | 1): Matrix<number>; /** * Returns quantile values along the axis. * @overload * @param {number} q Partition rate * @param {number} axis Axis to be reduced. If negative, returns the quantile value of the all element. * @returns {Matrix<number> | number} Quantile values */ quantile(q: number, axis: number): Matrix<number> | number; /** * Returns maximum indexes along the axis. * @param {number} axis Axis to be reduced * @returns {Matrix<number>} Argmax values */ argmax(axis: number): Matrix<number>; /** * Returns minimum indexes along the axis. * @param {number} axis Axis to be reduced * @returns {Matrix<number>} Argmin values */ argmin(axis: number): Matrix<number>; /** * Returns summation value of all element. * @overload * @returns {number} Summation value */ sum(): number; /** * Returns summation values along the axis. * @overload * @param {0 | 1} axis Axis to be reduced * @returns {Matrix<number>} Summation values */ sum(axis: 0 | 1): Matrix<number>; /** * Returns summation values along the axis. * @overload * @param {number} axis Axis to be reduced. If negative, returns a summation value of the all element. * @returns {Matrix<number> | number} Summation values */ sum(axis: number): Matrix<number> | number; /** * Returns mean of all element. * @overload * @returns {number} Mean value */ mean(): number; /** * Returns means along the axis. * @overload * @param {0 | 1} axis Axis to be reduced * @returns {Matrix<number>} Mean values */ mean(axis: 0 | 1): Matrix<number>; /** * Returns means along the axis. * @overload * @param {number} axis Axis to be reduced. If negative, returns a mean value of the all element. * @returns {Matrix<number> | number} Mean values */ mean(axis: number): Matrix<number> | number; /** * Returns producted value of all element. * @overload * @returns {number} Producted value */ prod(): number; /** * Returns producted values along the axis. * @overload * @param {0 | 1} axis Axis to be reduced * @returns {Matrix<number>} Producted values */ prod(axis: 0 | 1): Matrix<number>; /** * Returns producted values along the axis. * @overload * @param {number} axis Axis to be reduced. If negative, returns a producted value of the all element. * @returns {Matrix<number> | number} Producted values */ prod(axis: number): Matrix<number> | number; /** * Returns variance of all element. * @overload * @returns {number} Variance value */ variance(): number; /** * Returns variances along the axis. * @overload * @param {0 | 1} axis Axis to be reduced. * @param {number} [ddof] Delta Degrees of Freedom * @returns {Matrix<number>} Variance values */ variance(axis: 0 | 1, ddof?: number): Matrix<number>; /** * Returns variances along the axis. * @overload * @param {number} axis Axis to be reduced. If negative, returns a variance of the all element. * @param {number} [ddof] Delta Degrees of Freedom * @returns {Matrix<number> | number} Variance values */ variance(axis: number, ddof?: number): Matrix<number> | number; /** * Returns standard deviation of all element. * @overload * @returns {number} Standard deviation value */ std(): number; /** * Returns standard deviations along the axis. * @overload * @param {0 | 1} axis Axis to be reduced * @param {number} [ddof] Delta Degrees of Freedom * @returns {Matrix<number>} Standard deviation values */ std(axis: 0 | 1, ddof?: number): Matrix<number>; /** * Returns standard deviations along the axis. * @overload * @param {number} axis Axis to be reduced. If negative, returns a standard deviation of the all element. * @param {number} [ddof] Delta Degrees of Freedom * @returns {Matrix<number> | number} Standard deviation values */ std(axis: number, ddof?: number): Matrix<number> | number; /** * Returns if this is square matrix or not. * @returns {boolean} `true` if this is square matrix */ isSquare(): boolean; /** * Returns if this is diagonal matrix or not. * @param {number} [tol] Tolerance to be recognized as 0 * @returns {boolean} `true` if this is diagonal matrix */ isDiag(tol?: number): boolean; /** * Returns if this is identity matrix or not. * @param {number} [tol] Tolerance to be recognized as 0 or 1 * @returns {boolean} `true` if this is identity matrix */ isIdentity(tol?: number): boolean; /** * Returns if this is zero matrix or not. * @param {number} [tol] Tolerance to be recognized as 0 * @returns {boolean} `true` if this is zero matrix */ isZero(tol?: number): boolean; /** * Returns if this is triangular matrix or not. * @param {number} [tol] Tolerance to be recognized as 0 * @returns {boolean} `true` if this is triangular matrix */ isTriangular(tol?: number): boolean; /** * Returns if this is lower triangular matrix or not. * @param {number} [tol] Tolerance to be recognized as 0 * @returns {boolean} `true` if this is lower triangular matrix */ isLowerTriangular(tol?: number): boolean; /** * Returns if this is upper triangular matrix or not. * @param {number} [tol] Tolerance to be recognized as 0 * @returns {boolean} `true` if this is upper triangular matrix */ isUpperTriangular(tol?: number): boolean; /** * Returns if this is symmetric matrix or not. * @param {number} [tol] Tolerance to be recognized as the same * @returns {boolean} `true` if this is symmetric matrix */ isSymmetric(tol?: number): boolean; /** * Returns if this is hermitian matrix or not. * @param {number} [tol] Tolerance to be recognized as the same * @returns {boolean} `true` if this is hermitian matrix */ isHermitian(tol?: number): boolean; /** * Returns if this is alternating matrix or not. * @param {number} [tol] Tolerance within which sign-reversed values are recognized as the same * @returns {boolean} `true` if this is alternating matrix */ isAlternating(tol?: number): boolean; /** * Returns if this is skew-hermitian matrix or not. * @param {number} [tol] Tolerance within which sign-reversed values are recognized as the same * @returns {boolean} `true` if this is skew-hermitian matrix */ isSkewHermitian(tol?: number): boolean; /** * Returns if this is regular matrix or not. * @param {number} [tol] Tolerance to recognize the determinant as 0 * @returns {boolean} `true` if this is regular matrix */ isRegular(tol?: number): boolean; /** * Returns if this is normal matrix or not. * @param {number} [tol] Tolerance to be recognized as the same * @returns {boolean} `true` if this is normal matrix */ isNormal(tol?: number): boolean; /** * Returns if this is orthogonal matrix or not. * @param {number} [tol] Tolerance to be recognized as 0 or 1 * @returns {boolean} `true` if this is orthogonal matrix */ isOrthogonal(tol?: number): boolean; /** * Returns if this is unitary matrix or not. * @param {number} [tol] Tolerance to be recognized as 0 or 1 * @returns {boolean} `true` if this is unitary matrix */ isUnitary(tol?: number): boolean; /** * Returns if this is nilpotent matrix or not. * @param {number} [tol] Tolerance to be recognized as 0 * @returns {boolean} `true` if this is nilpotent matrix */ isNilpotent(tol?: number): boolean; /** * Returns diagonal elements. * @returns {number[]} Diagonal values */ diag(): number[]; /** * Returns a trace. * @returns {number} Trace value */ trace(): number; /** * Returns a p-norm. * @param {number} [p] p-norm * @returns {number} Entry-wise norm */ norm(p?: number): number; /** * Returns induced norm. * @param {number} [p] p-norm * @returns {number} Induced norm */ normInduced(p?: number): number; /** * Returns spectral norm. * @returns {number} Spectral norm */ normSpectral(): number; /** * Returns a entry-wise norm * @param {number} [p] p-norm * @returns {number} Entry-wise norm */ normEntrywise(p?: number): number; /** * Returns frobenius norm. * @returns {number} Frobenius norm */ normFrobenius(): number; /** * Returns max norm. * @returns {number} Max norm */ normMax(): number; /** * Returns schatten norm. * @param {number} [p] p-norm * @returns {number} Schatten norm */ normSchatten(p?: number): number; /** * Returns nuclear norm. * @returns {number} Nuclear norm */ normNuclear(): number; /** * Returns a rank of this matrix. * @param {number} [tol] Tolerance to be recognized as the same * @returns {number} Rank of this matrix */ rank(tol?: number): number; /** * Returns a determinant. * @returns {number} Determinant value */ det(): number; /** * Returns a spectral radius. * @returns {number} Spectral radius */ spectralRadius(): number; /** * Multiply all elements by -1 in-place. */ negative(): void; /** * Set all elements to their logical NOT values. */ not(): void; /** * Set all elements to their bitwise NOT values. */ bitnot(): void; /** * Set all elements to their absolute values. */ abs(): void; /** * Set all elements to their rounded values. */ round(): void; /** * Set all elements to their floored values. */ floor(): void; /** * Set all elements to their ceil values. */ ceil(): void; /** * Set all elements to their left shift values. * @param {number} n Shift amount */ leftShift(n: number): void; /** * Set all elements to their right shift values. * @param {number} n Shift amount */ signedRightShift(n: number): void; /** * Set all elements to their unsigned right shift values. * @param {number} n Shift amount */ unsignedRightShift(n: number): void; /** * Apply function for all elements with broadcasting. * @template U * @param {Matrix<U> | Tensor | U} o Applied value * @param {function (T, U): T} fn Applied function */ broadcastOperate<U_1>(o: Tensor | U_1 | Matrix<U_1>, fn: (arg0: T, arg1: U_1) => T): void; /** * Apply function to the position. * @overload * @param {number} r Index of the row to apply function to * @param {number} c Index of the column to apply function to * @param {function (T): T} [fn] Applied function * @returns {T} Old value */ operateAt(r: number, c: number, fn?: (arg0: T) => T): T; /** * Apply function to the position. * @overload * @param {[number, number]} index Index to apply function to * @param {function (T): T} fn Applied function * @returns {T} Old value */ operateAt(index: [number, number], fn: (arg0: T) => T): T; /** * Add a value or matrix. * @param {Matrix<number> | Tensor | number} o Value to add */ add(o: Matrix<number> | Tensor | number): void; /** * Add a value to the position. * @param {number} r Index of the row to add the value to * @param {number} c Index of the column to add the value to * @param {number} v Value to add * @returns {number} Old value */ addAt(r: number, c: number, v: number): number; /** * Subtract a value or matrix. * @param {Matrix<number> | Tensor | number} o Value to subtract */ sub(o: Matrix<number> | Tensor | number): void; /** * Subtract this matrix from a value or matrix. * @param {Matrix<number> | Tensor | number} o Value to be subtracted */ isub(o: Matrix<number> | Tensor | number): void; /** * Subtract a value from the value at the position. * @param {number} r Index of the row to subtract the value to * @param {number} c Index of the column to subtract the value to * @param {number} v Value to subtract * @returns {number} Old value */ subAt(r: number, c: number, v: number): number; /** * Subtract the value at the position from a value. * @param {number} r Index of the row whose value is to be subtracted * @param {number} c Index of the column whose value is to be subtracted * @param {number} v Value to be subtracted * @returns {number} Old value */ isubAt(r: number, c: number, v: number): number; /** * Multiplies by a value element-wise. * @param {Matrix<number> | Tensor | number} o Value to multiply */ mult(o: Matrix<number> | Tensor | number): void; /** * Multiplies a value to the position. * @param {number} r Index of the row to multiply the value by * @param {number} c Index of the column to multiply the value by * @param {number} v Value to multiply * @returns {number} Old value */ multAt(r: number, c: number, v: number): number; /** * Divides by a value element-wise. * @param {Matrix<number> | Tensor | number} o Value to divide */ div(o: Matrix<number> | Tensor | number): void; /** * Divides a value by this matrix element-wise. * @param {Matrix<number> | Tensor | number} o Value to be divided */ idiv(o: Matrix<number> | Tensor | number): void; /** * Divides the value at the position by a value. * @param {number} r Index of the row to divide the value by * @param {number} c Index of the column to divide the value by * @param {number} v Value to divide * @returns {number} Old value */ divAt(r: number, c: number, v: number): number; /** * Divides a value by the value at the position. * @param {number} r Index of the row whose value is to be divided * @param {number} c Index of the column whose value is to be divided * @param {number} v Value to be divided * @returns {number} Old value */ idivAt(r: number, c: number, v: number): number; /** * Take a remainder divided by a value element-wise. * @param {Matrix<number> | Tensor | number} o Value to divide */ mod(o: Matrix<number> | Tensor | number): void; /** * Take a remainder divided a value by this matrix element-wise. * @param {Matrix<number> | Tensor | number} o Value to be divided */ imod(o: Matrix<number> | Tensor | number): void; /** * Take a remainder divided the value at the position by a value. * @param {number} r Index of the row to divide the value by * @param {number} c Index of the column to divide the value by * @param {number} v Value to divide * @returns {number} Old value */ modAt(r: number, c: number, v: number): number; /** * Take a remainder divided a value by the value at the position. * @param {number} r Index of the row whose value is to be divided * @param {number} c Index of the column whose value is to be divided * @param {number} v Value to be divided * @returns {number} Old value */ imodAt(r: number, c: number, v: number): number; /** * Take a logical AND with a value or matrix. * @param {Matrix<unknown> | Tensor | number} o Value to take a logical AND */ and(o: Matrix<unknown> | Tensor | number): void; /** * Take logical AND with a value to the position. * @param {number} r Index of the row to take a logical AND with * @param {number} c Index of the column to take a logical AND with * @param {number} v Value to take a logical AND * @returns {T} Old value */ andAt(r: number, c: number, v: number): T; /** * Take a logical OR with a value or matrix. * @param {Matrix<unknown> | Tensor | number} o Value to take a logical OR */ or(o: Matrix<unknown> | Tensor | number): void; /** * Take logical OR with a value to the position. * @param {number} r Index of the row to take a logical OR with * @param {number} c Index of the column to take a logical OR with * @param {number} v Value to take a logical OR * @returns {T} Old value */ orAt(r: number, c: number, v: number): T; /** * Take a bitwise AND with a value or matrix. * @param {Matrix<number> | Tensor | number} o Value to take a bitwise AND */ bitand(o: Matrix<number> | Tensor | number): void; /** * Take bitwise AND with a value to the position. * @param {number} r Index of the row to take a bitwise AND with * @param {number} c Index of the column to take a bitwise AND with * @param {number} v Value to take a bitwise AND * @returns {T} Old value */ bitandAt(r: number, c: number, v: number): T; /** * Take a bitwise OR with a value or matrix. * @param {Matrix<number> | Tensor | number} o Value to take a bitwise OR */ bitor(o: Matrix<number> | Tensor | number): void; /** * Take bitwise OR with a value to the position. * @param {number} r Index of the row to take a bitwise OR with * @param {number} c Index of the column to take a bitwise OR with * @param {number} v Value to take a bitwise OR * @returns {T} Old value */ bitorAt(r: number, c: number, v: number): T; /** * Take a bitwise XOR with a value or matrix. * @param {Matrix<number> | Tensor | number} o Value to take a bitwise XOR */ bitxor(o: Matrix<number> | Tensor | number): void; /** * Take bitwise XOR with a value to the position. * @param {number} r Index of the row to take a bitwise XOR with * @param {number} c Index of the column to take a bitwise XOR with * @param {number} v Value to take a bitwise XOR * @returns {T} Old value */ bitxorAt(r: number, c: number, v: number): T; /** * Returns a matrix product value. * @param {Matrix<number>} o Right matrix * @returns {Matrix<number>} Producted matrix */ dot(o: Matrix<number>): Matrix<number>; /** * Returns a matrix product of the transposed matrix of this and input. * @param {Matrix<number>} o Right matrix * @returns {Matrix<number>} Producted matrix */ tDot(o: Matrix<number>): Matrix<number>; /** * Returns kronecker producted value. * @param {Matrix<number>} mat Right matrix * @returns {Matrix<number>} Kronecker producted matrix */ kron(mat: Matrix<number>): Matrix<number>; /** * Convoluted by a kernel. * @param {Array<Array<number>>} kernel Kernel matrix * @param {boolean} [normalize] Normalize kernel or not */ convolute(kernel: Array<Array<number>>, normalize?: boolean): void; /** * Calculate reduced row echelon form in-place. * @param {number} [tol] Tolerance to be recognized as 0 */ reducedRowEchelonForm(tol?: number): void; /** * Returns a inverse matrix. * @returns {Matrix<number>} Inversed matrix */ inv(): Matrix<number>; /** * Returns a inverse matrix for lower triangular matrix. * @returns {Matrix<number>} Inversed matrix */ invLowerTriangular(): Matrix<number>; /** * Returns a inverse matrix for upper triangular matrix. * @returns {Matrix<number>} Inversed matrix */ invUpperTriangular(): Matrix<number>; /** * Returns a inverse matrix by row reduction. * @returns {Matrix<number>} Inversed matrix */ invRowReduction(): Matrix<number>; /** * Returns a inverse matrix by LU decompositioin. * @returns {Matrix<number>} Inversed matrix */ invLU(): Matrix<number>; /** * Returns a pseudo inverse matrix. * @returns {Matrix<number>} pseudo inverse matrix */ pseudoInv(): Matrix<number>; /** * Returns a pseudo inverse matrix. * @returns {Matrix<number>} pseudo inverse matrix */ pseudoInvNaive(): Matrix<number>; /** * Returns a Moore–Penrose inverse matrix by QR decomposition. * @returns {Matrix<number>} Moore–Penrose inverse matrix */ pseudoInvQR(): Matrix<number>; /** * Returns a Moore–Penrose inverse matrix by SVD decomposition. * @returns {Matrix<number>} Moore–Penrose inverse matrix */ pseudoInvSVD(): Matrix<number>; /** * Returns a Moore–Penrose inverse matrix by Ben-Israel and Cohen iterative method. * @returns {Matrix<number>} Moore–Penrose inverse matrix */ pseudoInvBenIsraelCohen(): Matrix<number>; /** * Returns a square root of this matrix. * @returns {Matrix<number>} Squared matrix */ sqrt(): Matrix<number>; /** * Returns a power of this matrix. * @param {number} p Power exponent value * @returns {Matrix<number>} Powered matrix */ power(p: number): Matrix<number>; /** * Returns a exponential matrix * @returns {Matrix<number>} Exponential matrix */ exp(): Matrix<number>; /** * Returns a logarithm matrix * @returns {Matrix<number>} Logarithm matrix */ log(): Matrix<number>; /** * Returns a covariance matrix. * @param {number} [ddof] Delta Degrees of Freedom * @returns {Matrix<number>} Covariance matrix */ cov(ddof?: number): Matrix<number>; /** * Returns a gram matrix. * @returns {Matrix<number>} Gram matrix */ gram(): Matrix<number>; /** * Returns a solved value A of a equation XA=B. * @param {Matrix<number>} b Dependent variable values * @returns {Matrix<number>} Solved matrix */ solve(b: Matrix<number>): Matrix<number>; /** * Returns a solved value for lower triangular matrix. * @param {Matrix<number>} b Dependent variable values * @returns {Matrix<number>} Solved matrix */ solveLowerTriangular(b: Matrix<number>): Matrix<number>; /** * Returns a solved value for upper triangular matrix. * @param {Matrix<number>} b Dependent variable values * @returns {Matrix<number>} Solved matrix */ solveUpperTriangular(b: Matrix<number>): Matrix<number>; /** * Returns a solved value with Jacobi method. * @param {Matrix<number>} b Dependent variable values * @param {number} [maxIteration] Maximum iteration * @returns {Matrix<number>} Solved matrix */ solveJacobi(b: Matrix<number>, maxIteration?: number): Matrix<number>; /** * Returns a solved value with Gauss-Seidel method. * @param {Matrix<number>} b Dependent variable values * @param {number} [maxIteration] Maximum iteration * @returns {Matrix<number>} Solved matrix */ solveGaussSeidel(b: Matrix<number>, maxIteration?: number): Matrix<number>; /** * Returns a solved value with Successive Over-Relaxation method. * @param {Matrix<number>} b Dependent variable values * @param {Matrix<number>} w Relaxation factor * @param {number} [maxIteration] Maximum iteration * @returns {Matrix<number>} Solved matrix */ solveSOR(b: Matrix<number>, w: Matrix<number>, maxIteration?: number): Matrix<number>; /** * Returns a bidiagonal matrix. * @returns {Matrix<number>} Bidiagonal matrix */ bidiag(): Matrix<number>; /** * Returns a bidiagonal matrix by Householder method. * @overload * @param {false} [return_uv] Returns orthogonal matrixes * @returns {Matrix<number>} Bidiagonal matrix,