Class DistanceMatrix

Hierarchy

Constructors

Properties

Methods

[iterator] abs acos acosh add addColumnVector addCross addRowVector and apply applyMask asin asinh atan atanh cbrt ceil center clone clz32 cos cosh cumulativeSum diag diagonal div divColumnVector divRowVector divide dot echelonForm entries exp expm1 fill flipColumns flipRows floor fround get getColumn getColumnVector getRow getRowVector isColumnVector isDistance isEchelonForm isEmpty isReducedEchelonForm isRowVector isSquare isSymmetric isVector kroneckerProduct kroneckerSum leftShift log log10 log1p log2 max maxColumn maxColumnIndex maxIndex maxRow maxRowIndex mean min minColumn minColumnIndex minIndex minRow minRowIndex mmul mmulStrassen mod modulus mpow mul mulColumn mulColumnVector mulRow mulRowVector multiply neg negate norm not or pow product reducedEchelonForm removeCross repeat rightShift round scale scaleColumns scaleRows selection set setColumn setRow setSubMatrix sign signPropagatingRightShift sin sinh sortColumns sortRows sqrt standardDeviation strassen2x2 strassen3x3 sub subColumnVector subMatrix subMatrixColumn subMatrixRow subRowVector subtract sum swapColumns swapRows tan tanh tensorProduct to1DArray to2DArray toCompact toJSON toMatrix toString toSymmetricMatrix trace transpose trunc upperRightEntries upperRightValues values variance xor zeroFillRightShift abs acos acosh add and asin asinh atan atanh cbrt ceil checkMatrix clz32 columnVector copy cos cosh diag diagonal div divide exp expm1 eye floor from1DArray fromCompact fround identity isDistanceMatrix isMatrix isSymmetricMatrix leftShift log log10 log1p log2 max min mod modulus mul multiply not ones or pow rand randInt random rightShift round rowVector sign signPropagatingRightShift sin sinh sqrt sub subtract tan tanh trunc xor zeroFillRightShift zeros

Constructors

Properties

columns: number

Number of columns of the matrix.

diagonalSize: number

alias for rows or columns (square matrix so equals)

rows: number

Number of rows of the matrix.

size: number

Total number of elements in the matrix.

Methods

  • iterator from left to right, from top to bottom yield [row, column, value]

    Returns Generator<[row: number, column: number, value: number], void, void>

  • Applies a callback for each element of the matrix. The function is called in the matrix (this) context.

    Parameters

    • callback: ((row, column) => void)

      Function that will be called for each element in the matrix.

        • (row, column): void
        • Parameters

          • row: number
          • column: number

          Returns void

    Returns DistanceMatrix

  • remove sides (rows / columns) with falsy value from mask.

    Parameters

    • mask: Mask

    Returns DistanceMatrix

    Example

    const matrix = new SymmetricMatrix([
    [0,1,2,3],
    [1,0,4,5],
    [2,4,0,6],
    [3,5,6,0],
    ]);
    matrix.applyMask([1,0,0,1]);
    assert.deepEqual(matrix.toCompact(), new SymmetricMatrix([
    [0,3],
    [3,0],
    ]).toCompact());

    Throws

    RangeError if mask length is different of matrix sideSize

  • iterator from left to right, from top to bottom yield [row, column, value]

    Returns Generator<[row: number, column: number, value: number], void, void>

  • Returns the value of the given element of the matrix.

    Parameters

    • rowIndex: number

      Index of the element's row.

    • columnIndex: number

      Index of the element's column.

    Returns number

    • The value of the element.
  • Returns a new array with the values from the given column index.

    Parameters

    • index: number

      Column index.

    Returns number[]

  • Returns a new array with the values from the given row index.

    Parameters

    • index: number

      Row index.

    Returns number[]

  • Returns the index of the maximum value of one column.

    Parameters

    • column: number

      Column index.

    Returns [number, number]

  • Returns the index of the maximum value of one row.

    Parameters

    • row: number

      Row index.

    Returns [number, number]

  • Returns the index of the minimum value of one column.

    Parameters

    • column: number

      Column index.

    Returns [number, number]

  • Returns the index of the maximum value of one row.

    Parameters

    • row: number

      Row index.

    Returns [number, number]

  • Returns the norm of a matrix.

    Parameters

    • Optional type: "max" | "frobenius"

      Norm type. Default: 'frobenius'.

    Returns number

  • Creates a new matrix that is a repetition of the current matrix. New matrix has rows times the number of rows of the original matrix, and columns times the number of columns of the original matrix.

    Parameters

    Returns Matrix

    Example

    var matrix = new Matrix([[1, 2]]);
    matrix.repeat({ rows: 2 }); // [[1, 2], [1, 2]]
  • Return a new matrix based on a selection of rows and columns. Order of the indices matters and the same index can be used more than once.

    Parameters

    • rowIndices: ArrayLike<number>

      The row indices to select.

    • columnIndices: ArrayLike<number>

      The column indices to select.

    Returns Matrix

  • Set a part of the matrix to the given sub-matrix.

    Parameters

    • matrix: MaybeMatrix

      The source matrix from which to extract values.

    • startRow: number

      The index of the first row to set.

    • startColumn: number

      The index of the first column to set.

    Returns DistanceMatrix

  • Returns a subset of the matrix.

    Parameters

    • startRow: number

      First row index.

    • endRow: number

      Last row index.

    • startColumn: number

      First column index.

    • endColumn: number

      Last column index.

    Returns Matrix

  • Returns a subset of the matrix based on an array of column indices.

    Parameters

    • indices: ArrayLike<number>

      Array containing the column indices.

    • Optional startRow: number

      First row index. Default: 0.

    • Optional endRow: number

      Last row index. Default: this.rows - 1.

    Returns Matrix

  • Returns a subset of the matrix based on an array of row indices.

    Parameters

    • indices: ArrayLike<number>

      Array containing the row indices.

    • Optional startColumn: number

      First column index. Default: 0.

    • Optional endColumn: number

      Last column index. Default: this.columns - 1.

    Returns Matrix

  • Compact format upper-right corner of matrix no diagonal (because only store zeros) iterable from left to right, from top to bottom.

      A B C D
    A 0 1 2 3
    B 1 0 4 5
    C 2 4 0 6
    D 3 5 6 0

    will return compact 1D array [1, 2, 3, 4, 5, 6]

    length is S(i=0, n=sideSize-1) => 6 for a 4 side sized matrix

    Returns number[]

  • half iterator upper-right-corner from left to right, from top to bottom yield [row, column, value]

    Returns Generator<[row: number, column: number, value: number], void, void>

  • half iterator upper-right-corner from left to right, from top to bottom yield value

    Returns Generator<number, void, void>

  • iterator from left to right, from top to bottom yield value

    Returns Generator<number, void, void>

  • Creates a diagonal matrix based on the given array.

    Parameters

    • data: ArrayLike<number>

      Array containing the data for the diagonal.

    • Optional rows: number

      Number of rows. Default: data.length.

    • Optional columns: number

      Number of columns. Default: rows.

    Returns Matrix

    • The new diagonal matrix.
  • Creates an identity matrix with the given dimension. Values of the diagonal will be 1 and others will be 0.

    Parameters

    • rows: number

      Number of rows.

    • Optional columns: number

      Number of columns. Default: rows.

    • Optional value: number

      Value to fill the diagonal with. Default: 1.

    Returns Matrix

    • The new identity matrix.
  • Constructs a matrix with the chosen dimensions from a 1D array.

    Parameters

    • newRows: number

      Number of rows.

    • newColumns: number

      Number of columns.

    • newData: ArrayLike<number>

      A 1D array containing data for the matrix.

    Returns Matrix

    The new matrix.

  • Returns a matrix whose elements are the maximum between matrix1 and matrix2.

    Parameters

    • matrix1: MaybeMatrix
    • matrix2: MaybeMatrix

    Returns Matrix

  • Returns a matrix whose elements are the minimum between matrix1 and matrix2.

    Parameters

    • matrix1: MaybeMatrix
    • matrix2: MaybeMatrix

    Returns Matrix

  • Creates a symmetric matrix with the given dimensions. Values will be set to one.

    Type Parameters

    Parameters

    • sidesSize: number

      Number of rows or columns (square).

    Returns _M

    The new symmetric matrix.

  • Creates a matrix with the given dimensions. Values will be randomly set.

    Parameters

    • rows: number

      Number of rows.

    • columns: number

      Number of columns.

    • Optional options: IRandomOptions

      Options object.

    Returns Matrix

    The new matrix.

  • Creates a distance matrix with the given dimensions. Values will be set to zero. This is equivalent to calling the Matrix constructor.

    Type Parameters

    Parameters

    • sidesSize: number

      Number of rows or columns (square).

    Returns _M

    The new symmetric matrix.