Documentation of 'jsat.linear.Matrix' Java class
Matrix
jsat.linear

Class Matrix

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable
    Direct Known Subclasses:
    GenericMatrix, SparseMatrix


    public abstract class Matrix
    extends java.lang.Object
    implements java.lang.Cloneable, java.io.Serializable
    Generic class with some pre-implemented methods for a Matrix object. Throughout the documentation, the object that has its method called on will be denoted as A. So if you have code that looks like

    Matrix gramHat = gram.subtract(Matrix.eye(gram.rows()));


    Then gram would be the matrix A in the documentation.
    Matrices will use a capital letter, vectors a bold lower case letter, and scalars a normal lower case letter.
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor and Description
      Matrix() 
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method and Description
      Matrix add(double c)
      Creates a new Matrix that stores the result of A+c
      Matrix add(double c, java.util.concurrent.ExecutorService threadPool)
      Creates a new Matrix that stores the result of A+c
      Matrix add(Matrix B)
      Creates a new Matrix that stores the result of A+B
      Matrix add(Matrix B, java.util.concurrent.ExecutorService threadPool)
      Creates a new Matrix that stores the result of A+B
      boolean canBeMutated()
      Indicates whether or not this matrix can be mutated.
      static boolean canMultiply(Matrix A, Matrix B)
      Convenience method that will return true only if the two input matrices have dimensions compatible for multiplying A*B
      abstract void changeSize(int newRows, int newCols)
      This method alters the size of a matrix, either adding or subtracting rows from the internal structure of the matrix.
      abstract Matrix clone() 
      abstract int cols()
      Returns the number of columns stored in this matrix
      void copyTo(Matrix other)
      Copes the values of this matrix into the other matrix of the same dimensions
      static Matrix diag(Vec a)
      Returns a new dense square matrix such that the main diagonal contains the values given in a
      static void diagMult(Matrix A, Vec b)
      Alters the matrix A so that it contains the result of A times a sparse matrix represented by only its diagonal values or A = A*diag(b).
      static void diagMult(Vec b, Matrix A)
      Alters the matrix A so that it contains the result of sparse matrix represented by only its diagonal values times A or A = diag(b)*A.
      boolean equals(java.lang.Object obj) 
      boolean equals(java.lang.Object obj, double range)
      Performs the same as equals(java.lang.Object), but allows a leniency in the differences between matrix values.
      static DenseMatrix eye(int k)
      Creates a new dense identity matrix with k rows and columns.
      abstract double get(int i, int j)
      Returns the value stored at at the matrix position Ai,j
      Vec getColumn(int j)
      Creates a vector that has a copy of the values in column j of this matrix.
      Vec getColumnView(int j)
      Obtains a vector that is backed by this, at very little memory cost.
      Vec getRow(int r)
      Creates a vector that has a copy of the values in row i of this matrix.
      Vec getRowView(int r)
      Obtains a vector that is backed by this, at very little memory cost.
      void increment(int i, int j, double value)
      Alters the current matrix at index (i,j) to be equal to Ai,j = Ai,j + value
      abstract boolean isSparce()
      Returns true if the matrix is sparse, false otherwise
      boolean isSquare()
      Returns true if the matrix is square, meaning it has the same number of rows and columns.
      static boolean isSymmetric(Matrix A)
      Checks to see if the given input is a perfectly symmetric matrix
      static boolean isSymmetric(Matrix A, double eps)
      Checks to see if the given input is approximately symmetric.
      abstract Matrix[] lup() 
      abstract Matrix[] lup(java.util.concurrent.ExecutorService threadPool) 
      Matrix multiply(double c)
      Creates a new Matrix that stores A*c
      Matrix multiply(double c, java.util.concurrent.ExecutorService threadPool)
      Creates a new Matrix that stores A*c
      Matrix multiply(Matrix B)
      Creates a new matrix that stores A*B
      Matrix multiply(Matrix B, java.util.concurrent.ExecutorService threadPool)
      Creates a new matrix that stores A*B
      abstract void multiply(Matrix B, Matrix C)
      Alters the matrix C to be equal to C = C+A*B
      abstract void multiply(Matrix B, Matrix C, java.util.concurrent.ExecutorService threadPool)
      Alters the matrix C to be equal to C = C+A*B
      Vec multiply(Vec b)
      Creates a new vector that is equal to A*b
      abstract void multiply(Vec b, double z, Vec c)
      If this matrix is Am x n, and b has a length of n, and c has a length of m, then this will mutate c to store c = c + A*b*z
      Matrix multiplyTranspose(Matrix B)
      Returns the new matrix C that is C = A*BT
      Matrix multiplyTranspose(Matrix B, java.util.concurrent.ExecutorService threadPool)
      Returns the new matrix C that is C = A*BT
      abstract void multiplyTranspose(Matrix B, Matrix C)
      Alters the matrix C to be equal to C = C+A*BT
      abstract void multiplyTranspose(Matrix B, Matrix C, java.util.concurrent.ExecutorService threadPool)
      Alters the matrix C to be equal to C = C+A*BT
      abstract void mutableAdd(double c)
      Alters the current matrix to store the value A+c
      abstract void mutableAdd(double c, java.util.concurrent.ExecutorService threadPool)
      Alters the current matrix to store the value A+c
      abstract void mutableAdd(double c, Matrix B)
      Alters the current matrix to store the value A+c*B
      abstract void mutableAdd(double c, Matrix B, java.util.concurrent.ExecutorService threadPool)
      Alters the current matrix to store the value A+c*B
      void mutableAdd(Matrix B)
      Alters the current matrix to store the value A+B
      void mutableAdd(Matrix B, java.util.concurrent.ExecutorService threadpool)
      Alters the current matrix to store the value A+B
      abstract void mutableMultiply(double c)
      Alters the current matrix to be equal to A*c
      abstract void mutableMultiply(double c, java.util.concurrent.ExecutorService threadPool)
      Alters the current matrix to be equal to A*c
      void mutableSubtract(double c)
      Alters the current matrix to store A-c
      void mutableSubtract(double c, java.util.concurrent.ExecutorService threadPool)
      Alters the current matrix to store A-c
      void mutableSubtract(double c, Matrix B)
      Alters the current matrix to store A-c*B
      void mutableSubtract(double c, Matrix B, java.util.concurrent.ExecutorService threadPool)
      Alters the current matrix to store A-c*B
      void mutableSubtract(Matrix B)
      Alters the current matrix to store A-B
      void mutableSubtract(Matrix B, java.util.concurrent.ExecutorService threadpool)
      Alters the current matrix to store A-B
      abstract void mutableTranspose()
      Transposes the current matrix in place, altering its value.
      long nnz()
      Returns the number of non zero values stored in this matrix.
      static void OuterProductUpdate(Matrix A, Vec x, Vec y, double c)
      Alters the matrix A such that, A = A + c * x * y'
      static void OuterProductUpdate(Matrix A, Vec x, Vec y, double c, java.util.concurrent.ExecutorService threadpool)
      Alters the matrix A such that, A = A + c * x * y'
      static Matrix pascal(int size)
      Creates a new square matrix that is a pascal matrix.
      abstract Matrix[] qr() 
      abstract Matrix[] qr(java.util.concurrent.ExecutorService threadPool) 
      static DenseMatrix random(int rows, int cols, java.util.Random rand)
      Creates a new dense matrix filled with random values from Random.nextDouble()
      abstract int rows()
      Returns the number of rows stored in this matrix
      static boolean sameDimensions(Matrix A, Matrix B)
      Convenience method that will return true only if the two input matrices have the exact same dimensions.
      abstract void set(int i, int j, double value)
      Sets the value stored at at the matrix position Ai,j
      Matrix subtract(double c)
      Creates a new Matrix that stores the result of A-c
      Matrix subtract(double c, java.util.concurrent.ExecutorService threadPool)
      Creates a new Matrix that stores the result of A-c
      Matrix subtract(Matrix B)
      Creates a new Matrix that stores the result of A-B
      Matrix subtract(Matrix B, java.util.concurrent.ExecutorService threadPool)
      Creates a new Matrix that stores the result of A-B
      abstract void swapRows(int r1, int r2)
      Alters the current matrix by swapping the values stored in two different rows.
      java.lang.String toString() 
      Matrix transpose()
      Returns a new matrix that is the transpose of this matrix.
      abstract void transpose(Matrix C)
      Overwrites the values stored in matrix C to store the value of A'
      Vec transposeMultiply(double c, Vec b)
      Creates a new vector equal to x = A'*b*c
      abstract void transposeMultiply(double c, Vec b, Vec x)
      Alters the vector x to be equal to x = x + A'*b*c
      Matrix transposeMultiply(Matrix B)
      Creates a new matrix equal to A'*B, or the same result as
      A.transpose().multiply(B)
      Matrix transposeMultiply(Matrix B, java.util.concurrent.ExecutorService threadPool)
      Computes the result matrix of A'*B, or the same result as
      A.transpose().multiply(B)
      abstract void transposeMultiply(Matrix B, Matrix C)
      Alters the matrix C so that C = C + A'*B
      abstract void transposeMultiply(Matrix B, Matrix C, java.util.concurrent.ExecutorService threadPool)
      Alters the matrix C so that C = C + A'*B
      void updateRow(int i, double c, Vec b)
      Alters row i of this matrix, such that A[i,:] = A[i,:] + c*b
      abstract void zeroOut()
      Alters the current matrix so that all values are equal to zero.
      • Methods inherited from class java.lang.Object

        getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Matrix

        public Matrix()
    • Method Detail

      • add

        public Matrix add(Matrix B)
        Creates a new Matrix that stores the result of A+B
        Parameters:
        B - the matrix to add this this
        Returns:
        A+B
      • add

        public Matrix add(Matrix B,
                          java.util.concurrent.ExecutorService threadPool)
        Creates a new Matrix that stores the result of A+B
        Parameters:
        B - the matrix to add this this
        threadPool - the source of threads to do computation in parallel
        Returns:
        A+B
      • add

        public Matrix add(double c)
        Creates a new Matrix that stores the result of A+c
        Parameters:
        c - the scalar to add to each value in this
        Returns:
        A+c
      • add

        public Matrix add(double c,
                          java.util.concurrent.ExecutorService threadPool)
        Creates a new Matrix that stores the result of A+c
        Parameters:
        c - the scalar to add to each value in this
        threadPool - the source of threads to do computation in parallel
        Returns:
        A+B
      • mutableAdd

        public void mutableAdd(Matrix B)
        Alters the current matrix to store the value A+B
        Parameters:
        B - the matrix to add this this
      • mutableAdd

        public abstract void mutableAdd(double c,
                                        Matrix B)
        Alters the current matrix to store the value A+c*B
        Parameters:
        c - the scalar constant to multiple B by
        B - the matrix to add to this
      • mutableAdd

        public void mutableAdd(Matrix B,
                               java.util.concurrent.ExecutorService threadpool)
        Alters the current matrix to store the value A+B
        Parameters:
        B - the matrix to add to this
        threadpool - the source of threads to do computation in parallel
      • mutableAdd

        public abstract void mutableAdd(double c,
                                        Matrix B,
                                        java.util.concurrent.ExecutorService threadPool)
        Alters the current matrix to store the value A+c*B
        Parameters:
        c - the scalar constant to multiple B by
        B - the matrix to add to this
        threadPool - the source of threads to do computation in parallel
      • mutableAdd

        public abstract void mutableAdd(double c)
        Alters the current matrix to store the value A+c
        Parameters:
        c - the scalar constant to add to this
      • mutableAdd

        public abstract void mutableAdd(double c,
                                        java.util.concurrent.ExecutorService threadPool)
        Alters the current matrix to store the value A+c
        Parameters:
        c - the scalar constant to add to this
        threadPool - the source of threads to do computation in parallel
      • canBeMutated

        public boolean canBeMutated()
        Indicates whether or not this matrix can be mutated. If false, any method that contains "mutate" will not work.

        By default, this returns true
        Returns:
        true if the matrix supports being altered, false other wise.
      • subtract

        public Matrix subtract(Matrix B)
        Creates a new Matrix that stores the result of A-B
        Parameters:
        B - the matrix to subtract from this.
        Returns:
        a new matrix equal to A-B
      • subtract

        public Matrix subtract(Matrix B,
                               java.util.concurrent.ExecutorService threadPool)
        Creates a new Matrix that stores the result of A-B
        Parameters:
        B - the matrix to subtract from this.
        threadPool - the source of threads to do computation in parallel
        Returns:
        a new matrix equal to A-B
      • subtract

        public Matrix subtract(double c)
        Creates a new Matrix that stores the result of A-c
        Parameters:
        c - the scalar constant to subtract from this
        Returns:
        a new matrix equal to A-B
      • subtract

        public Matrix subtract(double c,
                               java.util.concurrent.ExecutorService threadPool)
        Creates a new Matrix that stores the result of A-c
        Parameters:
        c - the scalar constant to subtract from this
        threadPool - the source of threads to do computation in parallel
        Returns:
        a new matrix equal to A-B
      • mutableSubtract

        public void mutableSubtract(Matrix B)
        Alters the current matrix to store A-B
        Parameters:
        B - the matrix to subtract from this.
      • mutableSubtract

        public void mutableSubtract(double c,
                                    Matrix B)
        Alters the current matrix to store A-c*B
        Parameters:
        c - the scalar constant to multiply B by
        B - the matrix to subtract from this.
      • mutableSubtract

        public void mutableSubtract(Matrix B,
                                    java.util.concurrent.ExecutorService threadpool)
        Alters the current matrix to store A-B
        Parameters:
        B - the matrix to subtract from this.
        threadpool - the source of threads to do computation in parallel
      • mutableSubtract

        public void mutableSubtract(double c,
                                    Matrix B,
                                    java.util.concurrent.ExecutorService threadPool)
        Alters the current matrix to store A-c*B
        Parameters:
        c - the scalar constant to multiply B by
        B - the matrix to subtract from this.
        threadPool - the source of threads to do computation in parallel
      • mutableSubtract

        public void mutableSubtract(double c)
        Alters the current matrix to store A-c
        Parameters:
        c - the scalar constant to subtract from this
      • mutableSubtract

        public void mutableSubtract(double c,
                                    java.util.concurrent.ExecutorService threadPool)
        Alters the current matrix to store A-c
        Parameters:
        c - the scalar constant to subtract from this
        threadPool - the source of threads to do computation in parallel
      • multiply

        public abstract void multiply(Vec b,
                                      double z,
                                      Vec c)
        If this matrix is Am x n, and b has a length of n, and c has a length of m, then this will mutate c to store c = c + A*b*z
        Parameters:
        b - the vector to be treated as a colum vector
        z - the constant to multiply the A*b value by.
        c - where to place the result by addition
        Throws:
        java.lang.ArithmeticException - if the dimensions of A, b, or c do not all agree
      • multiply

        public Vec multiply(Vec b)
        Creates a new vector that is equal to A*b
        Parameters:
        b - the vector to multiply by
        Returns:
        a new vector A*b
      • multiply

        public Matrix multiply(Matrix B)
        Creates a new matrix that stores A*B
        Parameters:
        B - the matrix to multiply by
        Returns:
        a new matrix A*B
      • multiply

        public Matrix multiply(Matrix B,
                               java.util.concurrent.ExecutorService threadPool)
        Creates a new matrix that stores A*B
        Parameters:
        B - the matrix to multiply by
        threadPool - the source of threads to do computation in parallel
        Returns:
        a new matrix A*B
      • multiply

        public abstract void multiply(Matrix B,
                                      Matrix C)
        Alters the matrix C to be equal to C = C+A*B
        Parameters:
        B - the matrix to multiply this with
        C - the matrix to add the result to
      • multiply

        public abstract void multiply(Matrix B,
                                      Matrix C,
                                      java.util.concurrent.ExecutorService threadPool)
        Alters the matrix C to be equal to C = C+A*B
        Parameters:
        B - the matrix to multiply this with
        C - the matrix to add the result to
        threadPool - the source of threads to do computation in parallel
      • multiplyTranspose

        public abstract void multiplyTranspose(Matrix B,
                                               Matrix C)
        Alters the matrix C to be equal to C = C+A*BT
        Parameters:
        B - the matrix to multiply this with
        C - the matrix to add the result to
      • multiplyTranspose

        public Matrix multiplyTranspose(Matrix B)
        Returns the new matrix C that is C = A*BT
        Parameters:
        B - the matrix to multiply by the transpose of
        Returns:
        the result C
      • multiplyTranspose

        public abstract void multiplyTranspose(Matrix B,
                                               Matrix C,
                                               java.util.concurrent.ExecutorService threadPool)
        Alters the matrix C to be equal to C = C+A*BT
        Parameters:
        B - the matrix to multiply this with
        C - the matrix to add the result to
        threadPool - the source of threads to do computation in parallel
      • multiplyTranspose

        public Matrix multiplyTranspose(Matrix B,
                                        java.util.concurrent.ExecutorService threadPool)
        Returns the new matrix C that is C = A*BT
        Parameters:
        B - the matrix to multiply by the transpose of
        threadPool - the source of threads to do computation in parallel
        Returns:
        the result C
      • multiply

        public Matrix multiply(double c)
        Creates a new Matrix that stores A*c
        Parameters:
        c - the scalar constant to multiply by
        Returns:
        a new vector A*c
      • multiply

        public Matrix multiply(double c,
                               java.util.concurrent.ExecutorService threadPool)
        Creates a new Matrix that stores A*c
        Parameters:
        c - the scalar constant to multiply by
        threadPool - the source of threads to do computation in parallel
        Returns:
        a new matrix equal to A*c
      • mutableMultiply

        public abstract void mutableMultiply(double c)
        Alters the current matrix to be equal to A*c
        Parameters:
        c - the scalar constant to multiply by
      • mutableMultiply

        public abstract void mutableMultiply(double c,
                                             java.util.concurrent.ExecutorService threadPool)
        Alters the current matrix to be equal to A*c
        Parameters:
        c - the scalar constant to multiply by
        threadPool - the source of threads to do computation in parallel
      • lup

        public abstract Matrix[] lup()
      • lup

        public abstract Matrix[] lup(java.util.concurrent.ExecutorService threadPool)
      • qr

        public abstract Matrix[] qr()
      • qr

        public abstract Matrix[] qr(java.util.concurrent.ExecutorService threadPool)
      • changeSize

        public abstract void changeSize(int newRows,
                                        int newCols)
        This method alters the size of a matrix, either adding or subtracting rows from the internal structure of the matrix. Every resize call may cause a new allocation internally, and should not be called for excessive changing of a matrix. All added rows/ columns will have values of zero. If a row / column is removed, it is always the bottom/right most row / column removed. Values of the removed rows / columns will be lost.
        Parameters:
        newRows - the new number of rows, must be positive
        newCols - the new number of columns, must be positive.
      • mutableTranspose

        public abstract void mutableTranspose()
        Transposes the current matrix in place, altering its value. Only valid for square matrices
      • transpose

        public Matrix transpose()
        Returns a new matrix that is the transpose of this matrix.
        Returns:
        a new matrix A'
      • transpose

        public abstract void transpose(Matrix C)
        Overwrites the values stored in matrix C to store the value of A'
        Parameters:
        C - the matrix to store the transpose of the current matrix
        Throws:
        java.lang.ArithmeticException - if the dimensions of C do not match the dimensions of this'
      • transposeMultiply

        public Matrix transposeMultiply(Matrix B)
        Creates a new matrix equal to A'*B, or the same result as
        A.transpose().multiply(B)
        Parameters:
        B - the other Matrix
        Returns:
        a new matrix equal to A'*B
      • transposeMultiply

        public abstract void transposeMultiply(Matrix B,
                                               Matrix C)
        Alters the matrix C so that C = C + A'*B
        Parameters:
        B - the matrix to multiply by
        C - the matrix to add the result to
      • transposeMultiply

        public Matrix transposeMultiply(Matrix B,
                                        java.util.concurrent.ExecutorService threadPool)
        Computes the result matrix of A'*B, or the same result as
        A.transpose().multiply(B)
        Parameters:
        B - the matrix to multiply by
        threadPool - the source of threads to do computation in parallel
        Returns:
        a new matrix equal to A'*B
      • transposeMultiply

        public abstract void transposeMultiply(Matrix B,
                                               Matrix C,
                                               java.util.concurrent.ExecutorService threadPool)
        Alters the matrix C so that C = C + A'*B
        Parameters:
        B - the matrix to multiply by
        C - the matrix to place the results in
        threadPool - the source of threads to do computation in parallel
      • transposeMultiply

        public abstract void transposeMultiply(double c,
                                               Vec b,
                                               Vec x)
        Alters the vector x to be equal to x = x + A'*b*c
        Parameters:
        c - the scalar constant to multiply by
        b - the vector to multiply by
        x - the vector the add the result to
      • transposeMultiply

        public Vec transposeMultiply(double c,
                                     Vec b)
        Creates a new vector equal to x = A'*b*c
        Parameters:
        c - the scalar constant to multiply by
        b - the vector to multiply by
        Returns:
        the new vector equal to A'*b*c
      • get

        public abstract double get(int i,
                                   int j)
        Returns the value stored at at the matrix position Ai,j
        Parameters:
        i - the row, starting from 0
        j - the column, starting from 0
        Returns:
        the value at Ai,j
      • set

        public abstract void set(int i,
                                 int j,
                                 double value)
        Sets the value stored at at the matrix position Ai,j
        Parameters:
        i - the row, starting from 0
        j - the column, starting from 0
        value - the value to place at Ai,j
      • increment

        public void increment(int i,
                              int j,
                              double value)
        Alters the current matrix at index (i,j) to be equal to Ai,j = Ai,j + value
        Parameters:
        i - the row, starting from 0
        j - the column, starting from 0
        value - the value to add to the matrix coordinate
      • rows

        public abstract int rows()
        Returns the number of rows stored in this matrix
        Returns:
        the number of rows stored in this matrix
      • cols

        public abstract int cols()
        Returns the number of columns stored in this matrix
        Returns:
        the number of columns stored in this matrix
      • isSparce

        public abstract boolean isSparce()
        Returns true if the matrix is sparse, false otherwise
        Returns:
        true if the matrix is sparse, false otherwise
      • nnz

        public long nnz()
        Returns the number of non zero values stored in this matrix. This is mostly useful for sparse matrices.
        Returns:
        the number of non zero values stored in this matrix.
      • isSquare

        public boolean isSquare()
        Returns true if the matrix is square, meaning it has the same number of rows and columns.
        Returns:
        true if this matrix is square, false if it is rectangular.
      • swapRows

        public abstract void swapRows(int r1,
                                      int r2)
        Alters the current matrix by swapping the values stored in two different rows.
        Parameters:
        r1 - the first row to swap
        r2 - the second row to swap
      • getColumn

        public Vec getColumn(int j)
        Creates a vector that has a copy of the values in column j of this matrix. Altering it will not effect the values in this matrix
        Parameters:
        j - the column to copy
        Returns:
        a clone of the column as a Vec
      • getColumnView

        public Vec getColumnView(int j)
        Obtains a vector that is backed by this, at very little memory cost. Mutations to this vector will alter the values stored in the matrix, and vice versa.
        Parameters:
        j - the column to obtain a view of
        Returns:
        a vector backed by the specified row of the matrix
      • getRow

        public Vec getRow(int r)
        Creates a vector that has a copy of the values in row i of this matrix. Altering it will not effect the values in this matrix.
        Parameters:
        r - the row to copy
        Returns:
        a clone of the row as a Vec
      • getRowView

        public Vec getRowView(int r)
        Obtains a vector that is backed by this, at very little memory cost. Mutations to this vector will alter the values stored in the matrix, and vice versa.
        Parameters:
        r - the row to obtain a view of
        Returns:
        a vector backed by the specified row of the matrix
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • sameDimensions

        public static boolean sameDimensions(Matrix A,
                                             Matrix B)
        Convenience method that will return true only if the two input matrices have the exact same dimensions.
        Parameters:
        A - the first matrix
        B - the second matrix
        Returns:
        true if they have the exact same dimensions, false otherwise.
      • canMultiply

        public static boolean canMultiply(Matrix A,
                                          Matrix B)
        Convenience method that will return true only if the two input matrices have dimensions compatible for multiplying A*B
        Parameters:
        A - the first matrix
        B - the second matrix
        Returns:
        true if they have dimensions allowing multiplication, false otherwise.
      • equals

        public boolean equals(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • equals

        public boolean equals(java.lang.Object obj,
                              double range)
        Performs the same as equals(java.lang.Object), but allows a leniency in the differences between matrix values. This is useful for when some amount of numerical error is expected
        Parameters:
        obj - the other matrix
        range - the max acceptable difference between two cell values
        Returns:
        true if the difference between the values of each pair of matrix elements are less than or equal to range
      • zeroOut

        public abstract void zeroOut()
        Alters the current matrix so that all values are equal to zero.
      • copyTo

        public void copyTo(Matrix other)
        Copes the values of this matrix into the other matrix of the same dimensions
        Parameters:
        other - the matrix to overwrite the values of
      • updateRow

        public void updateRow(int i,
                              double c,
                              Vec b)
        Alters row i of this matrix, such that A[i,:] = A[i,:] + c*b
        Parameters:
        i - the index of the row to update
        c - the scalar constant to multiply the vector by
        b - the vector to add to the specified row
      • OuterProductUpdate

        public static void OuterProductUpdate(Matrix A,
                                              Vec x,
                                              Vec y,
                                              double c)
        Alters the matrix A such that, A = A + c * x * y'
        Parameters:
        A - the matrix to update
        x - the first vector
        y - the second vector
        c - the scalar constant to multiply the outer product by
        Throws:
        java.lang.ArithmeticException - if the vector dimensions are not compatible with the matrix A
      • OuterProductUpdate

        public static void OuterProductUpdate(Matrix A,
                                              Vec x,
                                              Vec y,
                                              double c,
                                              java.util.concurrent.ExecutorService threadpool)
        Alters the matrix A such that, A = A + c * x * y'
        Parameters:
        A - the matrix to update
        x - the first vector
        y - the second vector
        c - the scalar constant to multiply the outer product by
        threadpool - the source of threads to do computation in parallel
      • eye

        public static DenseMatrix eye(int k)
        Creates a new dense identity matrix with k rows and columns.
        Parameters:
        k - the number of rows / columns
        Returns:
        a new dense identity matrix Ik
      • random

        public static DenseMatrix random(int rows,
                                         int cols,
                                         java.util.Random rand)
        Creates a new dense matrix filled with random values from Random.nextDouble()
        Parameters:
        rows - the number of rows for the matrix
        cols - the number of columns for the matrix
        rand - the source of randomness
        Returns:
        a new dense matrix full of random values
      • diag

        public static Matrix diag(Vec a)
        Returns a new dense square matrix such that the main diagonal contains the values given in a
        Parameters:
        a - the diagonal values of a matrix
        Returns:
        the diagonal matrix represent by a
      • diagMult

        public static void diagMult(Matrix A,
                                    Vec b)
        Alters the matrix A so that it contains the result of A times a sparse matrix represented by only its diagonal values or A = A*diag(b). This is equivalent to the code A = A.multiply (diag(b))
        Parameters:
        A - the square matrix to update
        b - the diagonal value vector
      • diagMult

        public static void diagMult(Vec b,
                                    Matrix A)
        Alters the matrix A so that it contains the result of sparse matrix represented by only its diagonal values times A or A = diag(b)*A. This is equivalent to the code b.multiply (diag(A))
        Parameters:
        b - the diagonal value vector
        A - the square matrix to update
      • isSymmetric

        public static boolean isSymmetric(Matrix A,
                                          double eps)
        Checks to see if the given input is approximately symmetric. Rounding errors may cause the computation of a matrix to come out non symmetric, where |a[i,h] - a[j, i]| < eps. Despite these errors, it may be preferred to treat the matrix as perfectly symmetric regardless.
        Parameters:
        A - the input matrix
        eps - the maximum tolerable difference between two entries
        Returns:
        true if the matrix is approximately symmetric
      • isSymmetric

        public static boolean isSymmetric(Matrix A)
        Checks to see if the given input is a perfectly symmetric matrix
        Parameters:
        A - the input matrix
        Returns:
        true if it is perfectly symmetric.
      • pascal

        public static Matrix pascal(int size)
        Creates a new square matrix that is a pascal matrix. The pascal matrix of size n is n by n and symmetric.
        Parameters:
        size - the number of rows and columns for the matrix
        Returns:
        a pascal matrix of the desired size
      • clone

        public abstract Matrix clone()
        Overrides:
        clone in class java.lang.Object

DataMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.