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

Class RandomMatrix

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


    public abstract class RandomMatrix
    extends GenericMatrix
    Stores a Matrix full of random values in constant O(1) space by re-computing all matrix values on the fly as need. This allows memory reduction and use when it is necessary to use the matrix with a large sparse data set, where some matrix values may never even be used - or used very infrequently.

    This method is most useful when:
    • A random matrix can not be fit into main memory
    • An in memory matrix with the model being trained would result in swapping , in which case the slower Random Matrix would be faster since it can avoid swapping
    • A very large matrix must be synchronized across many threads or machines. The Random Matrix takes O(1) space and is thread safe
    • Initializing a random dense matrix
    • The accesses of the matrix is sparse enough that not all matrix values will get used, or used very infrequently


    Because the values of the random matrix are computed on the fly, the Random Matrix can not be altered. If attempted, an exception will be thrown.

    Because a Random Matric can not be altered, it can not fulfill the contract of getMatrixOfSameType(int, int). For this reason, it will return a DenseMatrix so that use cases of the given method do not break, and can return new - altered - matrices.
    See Also:
    Serialized Form
    • Constructor Detail

      • RandomMatrix

        public RandomMatrix(int rows,
                            int cols)
        Creates a new random matrix object
        Parameters:
        rows - the number of rows for the random matrix
        cols - the number of columns for the random matrix
      • RandomMatrix

        public RandomMatrix(int rows,
                            int cols,
                            long seedMult)
        Creates a new random matrix object
        Parameters:
        rows - the number of rows for the random matrix
        cols - the number of columns for the random matrix
        seedMult - a value to multiply with the seed used for each individual index. It should be a large value
      • RandomMatrix

        public RandomMatrix(RandomMatrix toCopy)
        Copy constructor
        Parameters:
        toCopy - the object to copy
    • Method Detail

      • get

        public double get(int i,
                          int j)
        Description copied from class: Matrix
        Returns the value stored at at the matrix position Ai,j
        Specified by:
        get in class Matrix
        Parameters:
        i - the row, starting from 0
        j - the column, starting from 0
        Returns:
        the value at Ai,j
      • set

        public void set(int i,
                        int j,
                        double value)
        Description copied from class: Matrix
        Sets the value stored at at the matrix position Ai,j
        Specified by:
        set in class Matrix
        Parameters:
        i - the row, starting from 0
        j - the column, starting from 0
        value - the value to place at Ai,j
      • rows

        public int rows()
        Description copied from class: Matrix
        Returns the number of rows stored in this matrix
        Specified by:
        rows in class Matrix
        Returns:
        the number of rows stored in this matrix
      • cols

        public int cols()
        Description copied from class: Matrix
        Returns the number of columns stored in this matrix
        Specified by:
        cols in class Matrix
        Returns:
        the number of columns stored in this matrix
      • isSparce

        public boolean isSparce()
        Description copied from class: Matrix
        Returns true if the matrix is sparse, false otherwise
        Specified by:
        isSparce in class Matrix
        Returns:
        true if the matrix is sparse, false otherwise
      • canBeMutated

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

        By default, this returns true
        Overrides:
        canBeMutated in class Matrix
        Returns:
        true if the matrix supports being altered, false other wise.
      • changeSize

        public void changeSize(int newRows,
                               int newCols)
        Description copied from class: Matrix
        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.
        Specified by:
        changeSize in class Matrix
        Parameters:
        newRows - the new number of rows, must be positive
        newCols - the new number of columns, must be positive.

DataMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.