Documentation of 'medusa.georgios.Distance_Geometry.Distance_Geometry_Matrix' Java class
Distance_Geometry_Matrix
medusa.georgios.Distance_Geometry

Class Distance_Geometry_Matrix

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable


    public class Distance_Geometry_Matrix
    extends java.lang.Object
    implements java.lang.Cloneable, java.io.Serializable
    Jama = Java Distance_Geometry_Matrix class.

    The Java Distance_Geometry_Matrix Class provides the fundamental operations of numerical linear algebra. Various constructors create Matrices from two dimensional arrays of double precision floating point numbers. Various "gets" and "sets" provide access to submatrices and matrix elements. Several methods implement basic matrix arithmetic, including matrix addition and multiplication, matrix norms, and element-by-element array operations. Methods for reading and printing matrices are also included. All the operations in this version of the Distance_Geometry_Matrix Class involve real matrices. Complex matrices may be handled in a future version.

    Five fundamental matrix decompositions, which consist of pairs or triples of matrices, permutation vectors, and the like, produce results in five decomposition classes. These decompositions are accessed by the Distance_Geometry_Matrix class to compute solutions of simultaneous linear equations, determinants, inverses and other matrix functions. The five decompositions are:

    • Cholesky Decomposition of symmetric, positive definite matrices.
    • LU Decomposition of rectangular matrices.
    • QR Decomposition of rectangular matrices.
    • Singular Value Decomposition of rectangular matrices.
    • Eigenvalue Decomposition of both symmetric and nonsymmetric square matrices.
    Example of use:

    Solve a linear system A x = b and compute the residual norm, ||b - A x||.

          double[][] vals = {{1.,2.,3},{4.,5.,6.},{7.,8.,10.}};
          Distance_Geometry_Matrix A = new Distance_Geometry_Matrix(vals);
          Distance_Geometry_Matrix b = Distance_Geometry_Matrix.random(3,1);
          Distance_Geometry_Matrix x = A.solve(b);
          Distance_Geometry_Matrix r = A.times(x).minus(b);
          double rnorm = r.normInf();
     
    See Also:
    Serialized Form
    • Constructor Detail

      • Distance_Geometry_Matrix

        public Distance_Geometry_Matrix(int m,
                                        int n)
        Construct an m-by-n matrix of zeros.
        Parameters:
        m - Number of rows.
        n - Number of colums.
      • Distance_Geometry_Matrix

        public Distance_Geometry_Matrix(int m,
                                        int n,
                                        double s)
        Construct an m-by-n constant matrix.
        Parameters:
        m - Number of rows.
        n - Number of colums.
        s - Fill the matrix with this scalar value.
      • Distance_Geometry_Matrix

        public Distance_Geometry_Matrix(double[][] A)
        Construct a matrix from a 2-D array.
        Parameters:
        A - Two-dimensional array of doubles.
        Throws:
        java.lang.IllegalArgumentException - All rows must have the same length
        See Also:
        constructWithCopy(double[][])
      • Distance_Geometry_Matrix

        public Distance_Geometry_Matrix(double[][] A,
                                        int m,
                                        int n)
        Construct a matrix quickly without checking arguments.
        Parameters:
        A - Two-dimensional array of doubles.
        m - Number of rows.
        n - Number of colums.
      • Distance_Geometry_Matrix

        public Distance_Geometry_Matrix(double[] vals,
                                        int m)
        Construct a matrix from a one-dimensional packed array
        Parameters:
        vals - One-dimensional array of doubles, packed by columns (ala Fortran).
        m - Number of rows.
        Throws:
        java.lang.IllegalArgumentException - Array length must be a multiple of m.
    • Method Detail

      • constructWithCopy

        public static Distance_Geometry_Matrix constructWithCopy(double[][] A)
        Construct a matrix from a copy of a 2-D array.
        Parameters:
        A - Two-dimensional array of doubles.
        Throws:
        java.lang.IllegalArgumentException - All rows must have the same length
      • clone

        public java.lang.Object clone()
        Clone the Distance_Geometry_Matrix object.
        Overrides:
        clone in class java.lang.Object
      • getArray

        public double[][] getArray()
        Access the internal two-dimensional array.
        Returns:
        Pointer to the two-dimensional array of matrix elements.
      • getArrayCopy

        public double[][] getArrayCopy()
        Copy the internal two-dimensional array.
        Returns:
        Two-dimensional array copy of matrix elements.
      • getColumnPackedCopy

        public double[] getColumnPackedCopy()
        Make a one-dimensional column packed copy of the internal array.
        Returns:
        Distance_Geometry_Matrix elements packed in a one-dimensional array by columns.
      • getRowPackedCopy

        public double[] getRowPackedCopy()
        Make a one-dimensional row packed copy of the internal array.
        Returns:
        Distance_Geometry_Matrix elements packed in a one-dimensional array by rows.
      • getRowDimension

        public int getRowDimension()
        Get row dimension.
        Returns:
        m, the number of rows.
      • getColumnDimension

        public int getColumnDimension()
        Get column dimension.
        Returns:
        n, the number of columns.
      • get

        public double get(int i,
                          int j)
        Get a single element.
        Parameters:
        i - Row index.
        j - Column index.
        Returns:
        A(i,j)
        Throws:
        java.lang.ArrayIndexOutOfBoundsException
      • getMatrix

        public Distance_Geometry_Matrix getMatrix(int i0,
                                                  int i1,
                                                  int j0,
                                                  int j1)
        Get a submatrix.
        Parameters:
        i0 - Initial row index
        i1 - Final row index
        j0 - Initial column index
        j1 - Final column index
        Returns:
        A(i0:i1,j0:j1)
        Throws:
        java.lang.ArrayIndexOutOfBoundsException - Submatrix indices
      • getMatrix

        public Distance_Geometry_Matrix getMatrix(int[] r,
                                                  int[] c)
        Get a submatrix.
        Parameters:
        r - Array of row indices.
        c - Array of column indices.
        Returns:
        A(r(:),c(:))
        Throws:
        java.lang.ArrayIndexOutOfBoundsException - Submatrix indices
      • getMatrix

        public Distance_Geometry_Matrix getMatrix(int i0,
                                                  int i1,
                                                  int[] c)
        Get a submatrix.
        Parameters:
        i0 - Initial row index
        i1 - Final row index
        c - Array of column indices.
        Returns:
        A(i0:i1,c(:))
        Throws:
        java.lang.ArrayIndexOutOfBoundsException - Submatrix indices
      • getMatrix

        public Distance_Geometry_Matrix getMatrix(int[] r,
                                                  int j0,
                                                  int j1)
        Get a submatrix.
        Parameters:
        r - Array of row indices.
        i0 - Initial column index
        i1 - Final column index
        Returns:
        A(r(:),j0:j1)
        Throws:
        java.lang.ArrayIndexOutOfBoundsException - Submatrix indices
      • set

        public void set(int i,
                        int j,
                        double s)
        Set a single element.
        Parameters:
        i - Row index.
        j - Column index.
        s - A(i,j).
        Throws:
        java.lang.ArrayIndexOutOfBoundsException
      • setMatrix

        public void setMatrix(int i0,
                              int i1,
                              int j0,
                              int j1,
                              Distance_Geometry_Matrix X)
        Set a submatrix.
        Parameters:
        i0 - Initial row index
        i1 - Final row index
        j0 - Initial column index
        j1 - Final column index
        X - A(i0:i1,j0:j1)
        Throws:
        java.lang.ArrayIndexOutOfBoundsException - Submatrix indices
      • setMatrix

        public void setMatrix(int[] r,
                              int[] c,
                              Distance_Geometry_Matrix X)
        Set a submatrix.
        Parameters:
        r - Array of row indices.
        c - Array of column indices.
        X - A(r(:),c(:))
        Throws:
        java.lang.ArrayIndexOutOfBoundsException - Submatrix indices
      • setMatrix

        public void setMatrix(int[] r,
                              int j0,
                              int j1,
                              Distance_Geometry_Matrix X)
        Set a submatrix.
        Parameters:
        r - Array of row indices.
        j0 - Initial column index
        j1 - Final column index
        X - A(r(:),j0:j1)
        Throws:
        java.lang.ArrayIndexOutOfBoundsException - Submatrix indices
      • setMatrix

        public void setMatrix(int i0,
                              int i1,
                              int[] c,
                              Distance_Geometry_Matrix X)
        Set a submatrix.
        Parameters:
        i0 - Initial row index
        i1 - Final row index
        c - Array of column indices.
        X - A(i0:i1,c(:))
        Throws:
        java.lang.ArrayIndexOutOfBoundsException - Submatrix indices
      • norm1

        public double norm1()
        One norm
        Returns:
        maximum column sum.
      • norm2

        public double norm2()
        Two norm
        Returns:
        maximum singular value.
      • normInf

        public double normInf()
        Infinity norm
        Returns:
        maximum row sum.
      • normF

        public double normF()
        Frobenius norm
        Returns:
        sqrt of sum of squares of all elements.
      • times

        public Distance_Geometry_Matrix times(double s)
        Multiply a matrix by a scalar, C = s*A
        Parameters:
        s - scalar
        Returns:
        s*A
      • timesEquals

        public Distance_Geometry_Matrix timesEquals(double s)
        Multiply a matrix by a scalar in place, A = s*A
        Parameters:
        s - scalar
        Returns:
        replace A by s*A
      • times

        public Distance_Geometry_Matrix times(Distance_Geometry_Matrix B)
        Linear algebraic matrix multiplication, A * B
        Parameters:
        B - another matrix
        Returns:
        Distance_Geometry_Matrix product, A * B
        Throws:
        java.lang.IllegalArgumentException - Distance_Geometry_Matrix inner dimensions must agree.
      • inverse

        public Distance_Geometry_Matrix inverse()
        Distance_Geometry_Matrix inverse or pseudoinverse
        Returns:
        inverse(A) if A is square, pseudoinverse otherwise.
      • det

        public double det()
        Distance_Geometry_Matrix determinant
        Returns:
        determinant
      • rank

        public int rank()
        Distance_Geometry_Matrix rank
        Returns:
        effective numerical rank, obtained from SVD.
      • cond

        public double cond()
        Distance_Geometry_Matrix condition (2 norm)
        Returns:
        ratio of largest to smallest singular value.
      • trace

        public double trace()
        Distance_Geometry_Matrix trace.
        Returns:
        sum of the diagonal elements.
      • random

        public static Distance_Geometry_Matrix random(int m,
                                                      int n)
        Generate matrix with random elements
        Parameters:
        m - Number of rows.
        n - Number of colums.
        Returns:
        An m-by-n matrix with uniformly distributed random elements.
      • identity

        public static Distance_Geometry_Matrix identity(int m,
                                                        int n)
        Generate identity matrix
        Parameters:
        m - Number of rows.
        n - Number of colums.
        Returns:
        An m-by-n matrix with ones on the diagonal and zeros elsewhere.
      • print

        public void print(int w,
                          int d)
        Print the matrix to stdout. Line the elements up in columns with a Fortran-like 'Fw.d' style format.
        Parameters:
        w - Column width.
        d - Number of digits after the decimal.
      • print

        public void print(java.io.PrintWriter output,
                          int w,
                          int d)
        Print the matrix to the output stream. Line the elements up in columns with a Fortran-like 'Fw.d' style format.
        Parameters:
        output - Output stream.
        w - Column width.
        d - Number of digits after the decimal.
      • print

        public void print(java.text.NumberFormat format,
                          int width)
        Print the matrix to stdout. Line the elements up in columns. Use the format object, and right justify within columns of width characters. Note that is the matrix is to be read back in, you probably will want to use a NumberFormat that is set to US Locale.
        Parameters:
        format - A Formatting object for individual elements.
        width - Field width for each column.
        See Also:
        DecimalFormat.setDecimalFormatSymbols(java.text.DecimalFormatSymbols)
      • print

        public void print(java.io.PrintWriter output,
                          java.text.NumberFormat format,
                          int width)
        Print the matrix to the output stream. Line the elements up in columns. Use the format object, and right justify within columns of width characters. Note that is the matrix is to be read back in, you probably will want to use a NumberFormat that is set to US Locale.
        Parameters:
        output - the output stream.
        format - A formatting object to format the matrix elements
        width - Column width.
        See Also:
        DecimalFormat.setDecimalFormatSymbols(java.text.DecimalFormatSymbols)
      • read

        public static Distance_Geometry_Matrix read(java.io.BufferedReader input)
                                             throws java.io.IOException
        Read a matrix from a stream. The format is the same the print method, so printed matrices can be read back in (provided they were printed using US Locale). Elements are separated by whitespace, all the elements for each row appear on a single line, the last row is followed by a blank line.
        Parameters:
        input - the input stream.
        Throws:
        java.io.IOException

DMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.