Documentation of 'smile.math.matrix.Matrix' Java class
Matrix
smile.math.matrix

Class Matrix

  • All Implemented Interfaces:
    java.io.Serializable
    Direct Known Subclasses:
    BandMatrix, DenseMatrix, SparseMatrix


    public abstract class Matrix
    extends java.lang.Object
    implements java.io.Serializable
    An abstract interface of matrix. The most important method is the matrix vector multiplication, which is the only operation needed in many iterative matrix algorithms, e.g. biconjugate gradient method for solving linear equations and power iteration and Lanczos algorithm for eigen decomposition, which are usually very efficient for very large and sparse matrices.

    A matrix is a rectangular array of numbers. An item in a matrix is called an entry or an element. Entries are often denoted by a variable with two subscripts. Matrices of the same size can be added and subtracted entrywise and matrices of compatible size can be multiplied. These operations have many of the properties of ordinary arithmetic, except that matrix multiplication is not commutative, that is, AB and BA are not equal in general.

    Matrices are a key tool in linear algebra. One use of matrices is to represent linear transformations and matrix multiplication corresponds to composition of linear transformations. Matrices can also keep track of the coefficients in a system of linear equations. For a square matrix, the determinant and inverse matrix (when it exists) govern the behavior of solutions to the corresponding system of linear equations, and eigenvalues and eigenvectors provide insight into the geometry of the associated linear transformation.

    There are several methods to render matrices into a more easily accessible form. They are generally referred to as matrix transformation or matrix decomposition techniques. The interest of all these decomposition techniques is that they preserve certain properties of the matrices in question, such as determinant, rank or inverse, so that these quantities can be calculated after applying the transformation, or that certain matrix operations are algorithmically easier to carry out for some types of matrices.

    The LU decomposition factors matrices as a product of lower (L) and an upper triangular matrices (U). Once this decomposition is calculated, linear systems can be solved more efficiently, by a simple technique called forward and back substitution. Likewise, inverses of triangular matrices are algorithmically easier to calculate. The QR decomposition factors matrices as a product of an orthogonal (Q) and a right triangular matrix (R). QR decomposition is often used to solve the linear least squares problem, and is the basis for a particular eigenvalue algorithm, the QR algorithm. Singular value decomposition expresses any matrix A as a product UDV', where U and V are unitary matrices and D is a diagonal matrix. The eigendecomposition or diagonalization expresses A as a product VDV-1, where D is a diagonal matrix and V is a suitable invertible matrix. If A can be written in this form, it is called diagonalizable.

    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
      abstract Matrix aat()
      Returns A * A'
      double apply(int i, int j)
      Returns the entry value at row i and column j.
      abstract Matrix ata()
      Returns A' * A
      abstract double[] atx(double[] x, double[] y)
      y = A' * x
      abstract double[] atxpy(double[] x, double[] y)
      y = A' * x + y
      abstract double[] atxpy(double[] x, double[] y, double b)
      y = A' * x + b * y
      abstract double[] ax(double[] x, double[] y)
      y = A * x
      abstract double[] axpy(double[] x, double[] y)
      y = A * x + y
      abstract double[] axpy(double[] x, double[] y, double b)
      y = A * x + b * y
      double[] diag()
      Returns the diagonal elements.
      static DenseMatrix diag(double[] A)
      Returns a square diagonal matrix with the elements of vector diag on the main diagonal.
      EVD eigen(int k)
      Find k largest approximate eigen pairs of a symmetric matrix by the Lanczos algorithm.
      EVD eigen(int k, double kappa, int maxIter)
      Find k largest approximate eigen pairs of a symmetric matrix by the Lanczos algorithm.
      static DenseMatrix eye(int n)
      Returns an n-by-n identity matrix.
      static DenseMatrix eye(int m, int n)
      Returns an m-by-n identity matrix.
      abstract double get(int i, int j)
      Returns the entry value at row i and column j.
      boolean isSymmetric()
      Returns true if the matrix is symmetric.
      abstract int ncols()
      Returns the number of columns.
      static DenseMatrix newInstance(double[] A)
      Returns a column vector/matrix initialized by given one-dimensional array.
      static DenseMatrix newInstance(double[][] A)
      Returns an matrix initialized by given two-dimensional array.
      static DenseMatrix newInstance(int rows, int cols, double value)
      Creates a matrix filled with given value.
      abstract int nrows()
      Returns the number of rows.
      static DenseMatrix ones(int rows, int cols)
      Return an all-one matrix.
      static DenseMatrix randn(int rows, int cols)
      Returns a random matrix of standard normal distributed values with given mean and standard dev.
      static DenseMatrix randn(int rows, int cols, double mu, double sigma)
      Returns a random matrix of normal distributed values with given mean and standard dev.
      void setSymmetric(boolean symmetric)
      Sets if the matrix is symmetric.
      SVD svd(int k)
      Find k largest approximate singular triples of a matrix by the Lanczos algorithm.
      SVD svd(int k, double kappa, int maxIter)
      Find k largest approximate singular triples of a matrix by the Lanczos algorithm.
      java.lang.String toString() 
      java.lang.String toString(boolean full)
      Returns the string representation of matrix.
      double trace()
      Returns the matrix trace.
      abstract Matrix transpose()
      Returns the matrix transpose.
      static DenseMatrix zeros(int rows, int cols)
      Returns all-zero matrix.
      • Methods inherited from class java.lang.Object

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

      • Matrix

        public Matrix()
    • Method Detail

      • newInstance

        public static DenseMatrix newInstance(double[][] A)
        Returns an matrix initialized by given two-dimensional array.
      • newInstance

        public static DenseMatrix newInstance(double[] A)
        Returns a column vector/matrix initialized by given one-dimensional array.
      • newInstance

        public static DenseMatrix newInstance(int rows,
                                              int cols,
                                              double value)
        Creates a matrix filled with given value.
      • zeros

        public static DenseMatrix zeros(int rows,
                                        int cols)
        Returns all-zero matrix.
      • ones

        public static DenseMatrix ones(int rows,
                                       int cols)
        Return an all-one matrix.
      • eye

        public static DenseMatrix eye(int n)
        Returns an n-by-n identity matrix.
      • eye

        public static DenseMatrix eye(int m,
                                      int n)
        Returns an m-by-n identity matrix.
      • diag

        public static DenseMatrix diag(double[] A)
        Returns a square diagonal matrix with the elements of vector diag on the main diagonal.
        Parameters:
        A - the array of diagonal elements.
      • randn

        public static DenseMatrix randn(int rows,
                                        int cols)
        Returns a random matrix of standard normal distributed values with given mean and standard dev.
      • randn

        public static DenseMatrix randn(int rows,
                                        int cols,
                                        double mu,
                                        double sigma)
        Returns a random matrix of normal distributed values with given mean and standard dev.
      • toString

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

        public java.lang.String toString(boolean full)
        Returns the string representation of matrix.
        Parameters:
        full - Print the full matrix if true. Otherwise only print top left 7 x 7 submatrix.
      • isSymmetric

        public boolean isSymmetric()
        Returns true if the matrix is symmetric.
      • setSymmetric

        public void setSymmetric(boolean symmetric)
        Sets if the matrix is symmetric. It is the caller's responability to make sure if the matrix symmetric. Also the matrix won't update this property if the matrix values are changed.
      • nrows

        public abstract int nrows()
        Returns the number of rows.
      • ncols

        public abstract int ncols()
        Returns the number of columns.
      • transpose

        public abstract Matrix transpose()
        Returns the matrix transpose.
      • get

        public abstract double get(int i,
                                   int j)
        Returns the entry value at row i and column j.
      • apply

        public double apply(int i,
                            int j)
        Returns the entry value at row i and column j. For Scala users.
      • diag

        public double[] diag()
        Returns the diagonal elements.
      • trace

        public double trace()
        Returns the matrix trace. The sum of the diagonal elements.
      • ata

        public abstract Matrix ata()
        Returns A' * A
      • aat

        public abstract Matrix aat()
        Returns A * A'
      • ax

        public abstract double[] ax(double[] x,
                                    double[] y)
        y = A * x
        Returns:
        y
      • axpy

        public abstract double[] axpy(double[] x,
                                      double[] y)
        y = A * x + y
        Returns:
        y
      • axpy

        public abstract double[] axpy(double[] x,
                                      double[] y,
                                      double b)
        y = A * x + b * y
        Returns:
        y
      • atx

        public abstract double[] atx(double[] x,
                                     double[] y)
        y = A' * x
        Returns:
        y
      • atxpy

        public abstract double[] atxpy(double[] x,
                                       double[] y)
        y = A' * x + y
        Returns:
        y
      • atxpy

        public abstract double[] atxpy(double[] x,
                                       double[] y,
                                       double b)
        y = A' * x + b * y
        Returns:
        y
      • eigen

        public EVD eigen(int k)
        Find k largest approximate eigen pairs of a symmetric matrix by the Lanczos algorithm.
        Parameters:
        k - the number of eigenvalues we wish to compute for the input matrix. This number cannot exceed the size of A.
      • eigen

        public EVD eigen(int k,
                         double kappa,
                         int maxIter)
        Find k largest approximate eigen pairs of a symmetric matrix by the Lanczos algorithm.
        Parameters:
        k - the number of eigenvalues we wish to compute for the input matrix. This number cannot exceed the size of A.
        kappa - relative accuracy of ritz values acceptable as eigenvalues.
        maxIter - Maximum number of iterations.
      • svd

        public SVD svd(int k)
        Find k largest approximate singular triples of a matrix by the Lanczos algorithm.
        Parameters:
        k - the number of singular triples we wish to compute for the input matrix. This number cannot exceed the size of A.
      • svd

        public SVD svd(int k,
                       double kappa,
                       int maxIter)
        Find k largest approximate singular triples of a matrix by the Lanczos algorithm.
        Parameters:
        k - the number of singular triples we wish to compute for the input matrix. This number cannot exceed the size of A.
        kappa - relative accuracy of ritz values acceptable as singular values.
        maxIter - Maximum number of iterations.

DataMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.