jsat.linear
Class RandomMatrix
- java.lang.Object
-
- jsat.linear.Matrix
-
- jsat.linear.GenericMatrix
-
- jsat.linear.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 ofgetMatrixOfSameType(int, int). For this reason, it will return aDenseMatrixso that use cases of the given method do not break, and can return new - altered - matrices.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description RandomMatrix(int rows, int cols)Creates a new random matrix objectRandomMatrix(int rows, int cols, long seedMult)Creates a new random matrix objectRandomMatrix(RandomMatrix toCopy)Copy constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description booleancanBeMutated()Indicates whether or not this matrix can be mutated.voidchangeSize(int newRows, int newCols)This method alters the size of a matrix, either adding or subtracting rows from the internal structure of the matrix.intcols()Returns the number of columns stored in this matrixdoubleget(int i, int j)Returns the value stored at at the matrix position Ai,jbooleanisSparce()Returnstrueif the matrix is sparse,falseotherwiseintrows()Returns the number of rows stored in this matrixvoidset(int i, int j, double value)Sets the value stored at at the matrix position Ai,j-
Methods inherited from class jsat.linear.GenericMatrix
clone, lup, lup, multiply, multiply, multiply, multiplyTranspose, multiplyTranspose, mutableAdd, mutableAdd, mutableAdd, mutableAdd, mutableMultiply, mutableMultiply, mutableTranspose, qr, qr, swapRows, transpose, transposeMultiply, transposeMultiply, transposeMultiply, zeroOut
-
Methods inherited from class jsat.linear.Matrix
add, add, add, add, canMultiply, copyTo, diag, diagMult, diagMult, equals, equals, eye, getColumn, getColumnView, getRow, getRowView, increment, isSquare, isSymmetric, isSymmetric, multiply, multiply, multiply, multiply, multiply, multiplyTranspose, multiplyTranspose, mutableAdd, mutableAdd, mutableSubtract, mutableSubtract, mutableSubtract, mutableSubtract, mutableSubtract, mutableSubtract, nnz, OuterProductUpdate, OuterProductUpdate, pascal, random, sameDimensions, subtract, subtract, subtract, subtract, toString, transpose, transposeMultiply, transposeMultiply, transposeMultiply, updateRow
-
-
-
-
Constructor Detail
-
RandomMatrix
public RandomMatrix(int rows, int cols)Creates a new random matrix object- Parameters:
rows- the number of rows for the random matrixcols- 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 matrixcols- the number of columns for the random matrixseedMult- 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:MatrixReturns the value stored at at the matrix position Ai,j
-
set
public void set(int i, int j, double value)Description copied from class:MatrixSets the value stored at at the matrix position Ai,j
-
rows
public int rows()
Description copied from class:MatrixReturns the number of rows stored in this matrix
-
cols
public int cols()
Description copied from class:MatrixReturns the number of columns stored in this matrix
-
isSparce
public boolean isSparce()
Description copied from class:MatrixReturnstrueif the matrix is sparse,falseotherwise
-
canBeMutated
public boolean canBeMutated()
Description copied from class:MatrixIndicates whether or not this matrix can be mutated. Iffalse, any method that contains "mutate" will not work.
By default, this returnstrue- Overrides:
canBeMutatedin classMatrix- Returns:
trueif the matrix supports being altered,falseother wise.
-
changeSize
public void changeSize(int newRows, int newCols)Description copied from class:MatrixThis 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:
changeSizein classMatrix- Parameters:
newRows- the new number of rows, must be positivenewCols- the new number of columns, must be positive.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG