SimpleBase
org.ejml.simple

Class SimpleBase<T extends SimpleBase>

  • All Implemented Interfaces:
    Serializable
    Direct Known Subclasses:
    SimpleMatrix


    public abstract class SimpleBase<T extends SimpleBase>extends Objectimplements Serializable
    Parent of SimpleMatrix implements all the standard matrix operations and uses generics to allow the returned matrix type to be changed. This class should be extended instead of SimpleMatrix.
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor and Description
      SimpleBase(int numRows, int numCols) 
    • Method Summary

      Methods 
      Modifier and TypeMethod and Description
      Tcombine(int insertRow, int insertCol, T B)
      Creates a new matrix that is a combination of this matrix and matrix B.
      doubleconditionP2()
      The condition p = 2 number of a matrix is used to measure the sensitivity of the linear system Ax=b.
      Tcopy()
      Creates and returns a matrix which is idential to this one.
      doubledeterminant()
      Computes the determinant of the matrix.
      Tdivide(double val)
      Returns the result of dividing each element by 'val': bi,j = ai,j/val
      doubledot(T v)
      Computes the dot product (a.k.a.
      SimpleEVDeig()
      Returns the Eigen Value Decomposition (EVD) of this matrix.
      doubleelementMaxAbs()
      Returns the maximum absolute value of all the elements in this matrix.
      TelementMult(T b)
      Returns a matrix which is the result of an element by element multiplication of 'this' and 'b': ci,j = ai,j*bi,j
      doubleelementSum()
      Computes the sum of all the elements in the matrix.
      TextractDiag()
      Extracts the diagonal from this matrix and returns them inside a column vector.
      TextractMatrix(int y0, int y1, int x0, int x1)
      Creates a new SimpleMatrix which is a submatrix of this matrix.
      TextractVector(boolean extractRow, int element)
      Extracts a row or column from this matrix.
      doubleget(int index)
      Returns the value of the matrix at the specified index of the 1D row major array.
      doubleget(int row, int col)
      Returns the value of the specified matrix element.
      intgetIndex(int row, int col)
      Returns the index in the matrix's array.
      DenseMatrix64FgetMatrix()
      Returns a reference to the matrix that it uses internally.
      intgetNumElements()
      Returns the number of elements in this matrix, which is equal to the number of rows times the number of columns.
      booleanhasUncountable()
      Checks to see if any of the elements in this matrix are either NaN or infinite.
      voidinsertIntoThis(int insertRow, int insertCol, T B)
      Copy matrix B into this matrix at location (insertRow, insertCol).
      Tinvert()
      Returns the inverse of this matrix.

      b = a-1
      booleanisIdentical(T a, double tol)
      Checks to see if matrix 'a' is the same as this matrix within the specified tolerance.
      booleanisInBounds(int row, int col)
      Returns true of the specified matrix element is valid element inside this matrix.
      booleanisVector()
      Returns true if this matrix is a vector.
      MatrixIteratoriterator(boolean rowMajor, int minRow, int minCol, int maxRow, int maxCol)
      Creates a new iterator for traversing through a submatrix inside this matrix.
      Tkron(T B)
      Computes the Kronecker product between this matrix and the provided B matrix:

      C = kron(A,B)
      static SimpleMatrixloadBinary(String fileName)
      Loads a new matrix from a serialized binary file.
      static SimpleMatrixloadCSV(String fileName)
      Loads a new matrix from a CSV file.
      Tminus(T b)
      Returns the result of matrix subtraction:

      c = a - b

      where c is the returned matrix, a is this matrix, and b is the passed in matrix.
      Tmult(T b)
      Returns a matrix which is the result of matrix multiplication:

      c = a * b

      where c is the returned matrix, a is this matrix, and b is the passed in matrix.
      Tnegative()
      Returns a new matrix whose elements are the negative of 'this' matrix's elements.

      bij = -aij
      doublenormF()
      Computes the Frobenius normal of the matrix:

      normF = Sqrt{ ∑i=1:mj=1:n { aij2} }
      intnumCols()
      Returns the number of columns in this matrix.
      intnumRows()
      Returns the number of rows in this matrix.
      Tplus(double beta, T b)
      Performs a matrix addition and scale operation.

      c = a + β*b

      where c is the returned matrix, a is this matrix, and b is the passed in matrix.
      Tplus(T b)
      Returns the result of matrix addition:

      c = a + b

      where c is the returned matrix, a is this matrix, and b is the passed in matrix.
      voidprint()
      Prints the matrix to standard out.
      voidprint(int numChar, int precision)
      Prints the matrix to standard out with the specified precision.
      voidprint(String format)
      Prints the matrix to standard out given a {@link java.io.PrintStream#printf) style floating point format, e.g.
      voidprintDimensions()
      Prints the number of rows and column in this matrix.
      TpseudoInverse()
      Computes the Moore-Penrose pseudo-inverse
      voidreshape(int numRows, int numCols)
      Reshapes the matrix to the specified number of rows and columns.
      voidsaveToFileBinary(String fileName)
      Saves this matrix to a file as a serialized binary object.
      voidsaveToFileCSV(String fileName)
      Saves this matrix to a file in a CSV format.
      Tscale(double val)
      Returns the result of scaling each element by 'val':
      bi,j = val*ai,j
      voidset(double val)
      Sets all the elements in this matrix equal to the specified value.

      aij = val
      voidset(int index, double value)
      Assigns an element a value based on its index in the internal array..
      voidset(int row, int col, double value)
      Assigns the element in the Matrix to the specified value.
      voidset(T a)
      Sets the elements in this matrix to be equal to the elements in the passed in matrix.
      voidsetColumn(int column, int offset, double... values)
      Assigns consecutive elements inside a column to the provided array.

      A(offset:(offset + values.length),column) = values
      voidsetRow(int row, int offset, double... values)
      Assigns consecutive elements inside a row to the provided array.

      A(row,offset:(offset + values.length)) = values
      Tsolve(T b)
      Solves for X in the following equation:

      x = a-1b

      where 'a' is this matrix and 'b' is an n by p matrix.
      SimpleSVDsvd()
      Computes a full Singular Value Decomposition (SVD) of this matrix with the eigenvalues ordered from largest to smallest.
      SimpleSVDsvd(boolean compact)
      Computes the SVD in either compact format or full format.
      StringtoString()
      Converts the array into a string format for display purposes.
      doubletrace()
      Computes the trace of the matrix.
      Ttranspose()
      Returns the transpose of this matrix.
      aT
      voidzero()
      Sets all the elements in the matrix equal to zero.
    • Constructor Detail

      • SimpleBase

        public SimpleBase(int numRows,          int numCols)
    • Method Detail

      • getMatrix

        public DenseMatrix64F getMatrix()

        Returns a reference to the matrix that it uses internally. This is useful when an operation is needed that is not provided by this class.

        Returns:
        Reference to the internal DenseMatrix64F.
      • dot

        public double dot(T v)
        Computes the dot product (a.k.a. inner product) between this vector and vector 'v'.
        Parameters:
        v - The second vector in the dot product. Not modified.
        Returns:
        dot product
      • isVector

        public boolean isVector()
        Returns true if this matrix is a vector. A vector is defined as a matrix that has either one row or column.
        Returns:
        Returns true for vectors and false otherwise.
      • pseudoInverse

        public T pseudoInverse()

        Computes the Moore-Penrose pseudo-inverse

        Returns:
        inverse computed using the pseudo inverse.
      • solve

        public T solve(T b)

        Solves for X in the following equation:

        x = a-1b

        where 'a' is this matrix and 'b' is an n by p matrix.

        If the system could not be solved then SingularMatrixException is thrown. Even if no exception is thrown 'a' could still be singular or nearly singular.

        Parameters:
        b - n by p matrix. Not modified.
        Returns:
        The solution for 'x' that is n by p.
        Throws:
        SingularMatrixException
        See Also:
        CommonOps.solve(DenseMatrix64F, DenseMatrix64F, DenseMatrix64F)
      • set

        public void set(T a)
        Sets the elements in this matrix to be equal to the elements in the passed in matrix. Both matrix must have the same dimension.
        Parameters:
        a - The matrix whose value this matrix is being set to.
      • normF

        public double normF()

        Computes the Frobenius normal of the matrix:

        normF = Sqrt{ ∑i=1:mj=1:n { aij2} }

        Returns:
        The matrix's Frobenius normal.
        See Also:
        NormOps.normF(org.ejml.data.D1Matrix64F)
      • conditionP2

        public double conditionP2()

        The condition p = 2 number of a matrix is used to measure the sensitivity of the linear system Ax=b. A value near one indicates that it is a well conditioned matrix.

        Returns:
        The condition number.
        See Also:
        NormOps.conditionP2(DenseMatrix64F)
      • reshape

        public void reshape(int numRows,           int numCols)

        Reshapes the matrix to the specified number of rows and columns. If the total number of elements is <= number of elements it had before the data is saved. Otherwise a new internal array is declared and the old data lost.

        This is equivalent to calling A.getMatrix().reshape(numRows,numCols,false).

        Parameters:
        numRows - The new number of rows in the matrix.
        numCols - The new number of columns in the matrix.
        See Also:
        Matrix64F.reshape(int,int,boolean)
      • set

        public void set(int row,       int col,       double value)
        Assigns the element in the Matrix to the specified value. Performs a bounds check to make sure the requested element is part of the matrix.
        Parameters:
        row - The row of the element.
        col - The column of the element.
        value - The element's new value.
      • set

        public void set(int index,       double value)
        Assigns an element a value based on its index in the internal array..
        Parameters:
        index - The matrix element that is being assigned a value.
        value - The element's new value.
      • setRow

        public void setRow(int row,          int offset,          double... values)

        Assigns consecutive elements inside a row to the provided array.

        A(row,offset:(offset + values.length)) = values

        Parameters:
        row - The row that the array is to be written to.
        offset - The initial column that the array is written to.
        values - Values which are to be written to the row in a matrix.
      • setColumn

        public void setColumn(int column,             int offset,             double... values)

        Assigns consecutive elements inside a column to the provided array.

        A(offset:(offset + values.length),column) = values

        Parameters:
        column - The column that the array is to be written to.
        offset - The initial column that the array is written to.
        values - Values which are to be written to the row in a matrix.
      • get

        public double get(int row,         int col)
        Returns the value of the specified matrix element. Performs a bounds check to make sure the requested element is part of the matrix.
        Parameters:
        row - The row of the element.
        col - The column of the element.
        Returns:
        The value of the element.
      • get

        public double get(int index)
        Returns the value of the matrix at the specified index of the 1D row major array.
        Parameters:
        index - The element's index whose value is to be returned
        Returns:
        The value of the specified element.
        See Also:
        D1Matrix64F.get(int)
      • getIndex

        public int getIndex(int row,           int col)
        Returns the index in the matrix's array.
        Parameters:
        row - The row number.
        col - The column number.
        Returns:
        The index of the specified element.
        See Also:
        DenseMatrix64F.getIndex(int, int)
      • iterator

        public MatrixIterator iterator(boolean rowMajor,                      int minRow,                      int minCol,                      int maxRow,                      int maxCol)
        Creates a new iterator for traversing through a submatrix inside this matrix. It can be traversed by row or by column. Range of elements is inclusive, e.g. minRow = 0 and maxRow = 1 will include rows 0 and 1. The iteration starts at (minRow,minCol) and ends at (maxRow,maxCol)
        Parameters:
        rowMajor - true means it will traverse through the submatrix by row first, false by columns.
        minRow - first row it will start at.
        minCol - first column it will start at.
        maxRow - last row it will stop at.
        maxCol - last column it will stop at.
        Returns:
        A new MatrixIterator
      • copy

        public T copy()
        Creates and returns a matrix which is idential to this one.
        Returns:
        A new identical matrix.
      • numRows

        public int numRows()
        Returns the number of rows in this matrix.
        Returns:
        number of rows.
      • numCols

        public int numCols()
        Returns the number of columns in this matrix.
        Returns:
        number of columns.
      • getNumElements

        public int getNumElements()
        Returns the number of elements in this matrix, which is equal to the number of rows times the number of columns.
        Returns:
        The number of elements in the matrix.
      • print

        public void print()
        Prints the matrix to standard out.
      • print

        public void print(int numChar,         int precision)
        Prints the matrix to standard out with the specified precision.
      • print

        public void print(String format)

        Prints the matrix to standard out given a {@link java.io.PrintStream#printf) style floating point format, e.g. print("%f").

      • extractMatrix

        public T extractMatrix(int y0,              int y1,              int x0,              int x1)

        Creates a new SimpleMatrix which is a submatrix of this matrix.

        si-y0 , j-x0 = oij for all y0 ≤ i < y1 and x0 ≤ j < x1

        where 'sij' is an element in the submatrix and 'oij' is an element in the original matrix.

        If any of the inputs are set to T.END then it will be set to the last row or column in the matrix.

        Parameters:
        x0 - Start column.
        x1 - Stop column.
        y0 - Start row.
        y1 - Stop row.
        Returns:
        The submatrix.
      • extractVector

        public T extractVector(boolean extractRow,              int element)

        Extracts a row or column from this matrix. The returned vector will either be a row or column vector depending on the input type.

        Parameters:
        extractRow - If true a row will be extracted.
        element - The row or column the vector is contained in.
        Returns:
        Extracted vector.
      • isIdentical

        public boolean isIdentical(T a,                  double tol)
        Checks to see if matrix 'a' is the same as this matrix within the specified tolerance.
        Parameters:
        a - The matrix it is being compared against.
        tol - How similar they must be to be equals.
        Returns:
        If they are equal within tolerance of each other.
      • hasUncountable

        public boolean hasUncountable()
        Checks to see if any of the elements in this matrix are either NaN or infinite.
        Returns:
        True of an element is NaN or infinite. False otherwise.
      • svd

        public SimpleSVD svd()
        Computes a full Singular Value Decomposition (SVD) of this matrix with the eigenvalues ordered from largest to smallest.
        Returns:
        SVD
      • svd

        public SimpleSVD svd(boolean compact)
        Computes the SVD in either compact format or full format.
        Returns:
        SVD of this matrix.
      • eig

        public SimpleEVD eig()
        Returns the Eigen Value Decomposition (EVD) of this matrix.
      • insertIntoThis

        public void insertIntoThis(int insertRow,                  int insertCol,                  T B)
        Copy matrix B into this matrix at location (insertRow, insertCol).
        Parameters:
        insertRow - First row the matrix is to be inserted into.
        insertCol - First column the matrix is to be inserted into.
        B - The matrix that is being inserted.
      • combine

        public T combine(int insertRow,        int insertCol,        T B)

        Creates a new matrix that is a combination of this matrix and matrix B. B is written into A at the specified location if needed the size of A is increased by growing it. A is grown by padding the new area with zeros.

        While useful when adding data to a matrix which will be solved for it is also much less efficient than predeclaring a matrix and inserting data into it.

        If insertRow or insertCol is set to SimpleMatrix.END then it will be combined at the last row or column respectively.

        Parameters:
        insertRow - Row where matrix B is written in to.
        insertCol - Column where matrix B is written in to.
        B - The matrix that is written into A.
        Returns:
        A new combined matrix.
      • elementMaxAbs

        public double elementMaxAbs()
        Returns the maximum absolute value of all the elements in this matrix. This is equivalent the the infinite p-norm of the matrix.
        Returns:
        Largest absolute value of any element.
      • elementSum

        public double elementSum()
        Computes the sum of all the elements in the matrix.
        Returns:
        Sum of all the elements.
      • elementMult

        public T elementMult(T b)

        Returns a matrix which is the result of an element by element multiplication of 'this' and 'b': ci,j = ai,j*bi,j

        Parameters:
        b - A simple matrix.
        Returns:
        The element by element multiplication of 'this' and 'b'.
      • negative

        public T negative()

        Returns a new matrix whose elements are the negative of 'this' matrix's elements.

        bij = -aij

        Returns:
        A matrix that is the negative of the original.
      • isInBounds

        public boolean isInBounds(int row,                 int col)
        Returns true of the specified matrix element is valid element inside this matrix.
        Parameters:
        row - Row index.
        col - Column index.
        Returns:
        true if it is a valid element in the matrix.
      • printDimensions

        public void printDimensions()
        Prints the number of rows and column in this matrix.

SCaVis 2.1 © jWork.ORG