Class MatrixUtil


  • public abstract class MatrixUtil
    extends Object
    This class is designed to extract sub-matrices, in the form of a 2D or 1D array. The assumption is that the sub-matrix is always a square matrix. Note: This class follows the convention of reading/writing matrices in a row-by-row fashion.
    Author:
    Azim Ahmadzadeh, Data Mining Lab, Georgia State University
    • Constructor Detail

      • MatrixUtil

        public MatrixUtil()
    • Method Detail

      • getSubMatrixAsArray

        public static double[] getSubMatrixAsArray​(double[][] m,
                                                   int startingRow,
                                                   int startingCol,
                                                   int pSize)
        For a given 2D matrix, this method returns a sub-matrix in the form of a 1D array. The output array is formed by putting each row of the sub-matrix concatenated to its previous row. (As opposed to a column-by-column concatenation.)
        Parameters:
        m - the given matrix
        startingCol - the starting row (width) where the sub-matrix should be extracted.
        startingRow - the starting col (height) where the sub-matrix should be extracted.
        pSize - the size of the square sub-matrix. (Zero or negative values are not allowed.)
        Returns:
        a 1D array representing the sub-matrix
      • getSubMatrixAsMatrix

        public static double[][] getSubMatrixAsMatrix​(double[][] m,
                                                      int startingRow,
                                                      int startingCol,
                                                      int pSize)
        For a given 2D matrix, this method returns a sub-matrix in the form of a 2D array.
        Parameters:
        m - the given matrix
        startingRow - the starting row (width) where the sub-matrix should be extracted.
        startingCol - the starting col (height) where the sub-matrix should be extracted.
        pSize - the size of the square sub-matrix. (Zero or negative values are not allowed.)
        Returns:
        a 2D array representing the sub-matrix
      • convertTo2DArray

        public static double[][] convertTo2DArray​(double[] array,
                                                  int width,
                                                  int height)
        This method converts a 1D array to a 2D array given the expected width and height
        Parameters:
        array -
        width - is similar to output.length
        height - is similar to output[0].length
        Returns:
        A 2D array of size width X height