jsat.linear
Class MatrixOfVecs
- java.lang.Object
-
- jsat.linear.Matrix
-
- jsat.linear.GenericMatrix
-
- jsat.linear.MatrixOfVecs
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable
public class MatrixOfVecs extends GenericMatrix
This class provides a base mechanism to create a Matrix 'view' from a list ofVecobjects. The vector objects will be used to back the rows of the matrix, so changes to one are shown in the other. If the matirx is altered usingchangeSize(int, int), this may no longer be true.
Row oriented operations are implemented to defer to the base vector objects used.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description MatrixOfVecs(int rows, int cols, boolean sparse)Creates a new Matrix of Vecs of the desired size.MatrixOfVecs(java.util.List<Vec> rows)Creates a new Matrix of Vecs from the given list of Vec objects.MatrixOfVecs(Vec... rows)Creates a new Matrix of Vecs from the given array of Vec objects.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description 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.MatrixOfVecsclone()intcols()Returns the number of columns stored in this matrixdoubleget(int i, int j)Returns the value stored at at the matrix position Ai,jVecgetRowView(int r)Obtains a vector that is backed by this, at very little memory cost.voidincrement(int i, int j, double value)Alters the current matrix at index (i,j) to be equal to Ai,j = Ai,j + valuebooleanisSparce()Returnstrueif the matrix is sparse,falseotherwisevoidmultiply(Vec b, double z, Vec c)If this matrix is Am x n, and b has a length of n, and c has a length of m, then this will mutate c to store c = c + A*b*zvoidmutableAdd(double c)Alters the current matrix to store the value A+cvoidmutableMultiply(double c)Alters the current matrix to be equal to A*cintrows()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,jvoidupdateRow(int i, double c, Vec b)Alters row i of this matrix, such that A[i,:] = A[i,:] + c*bvoidzeroOut()Alters the current matrix so that all values are equal to zero.-
Methods inherited from class jsat.linear.GenericMatrix
lup, lup, multiply, multiply, multiplyTranspose, multiplyTranspose, mutableAdd, mutableAdd, mutableAdd, mutableMultiply, mutableTranspose, qr, qr, swapRows, transpose, transposeMultiply, transposeMultiply, transposeMultiply
-
Methods inherited from class jsat.linear.Matrix
add, add, add, add, canBeMutated, canMultiply, copyTo, diag, diagMult, diagMult, equals, equals, eye, getColumn, getColumnView, getRow, 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
-
-
-
-
Constructor Detail
-
MatrixOfVecs
public MatrixOfVecs(Vec... rows)
Creates a new Matrix of Vecs from the given array of Vec objects. All Vec objects contained should be of the same length.- Parameters:
rows- the rows of vecs to make this matrix.
-
MatrixOfVecs
public MatrixOfVecs(java.util.List<Vec> rows)
Creates a new Matrix of Vecs from the given list of Vec objects. All Vec objects contained should be of the same length.- Parameters:
rows- the rows of vecs to make this matrix.
-
MatrixOfVecs
public MatrixOfVecs(int rows, int cols, boolean sparse)Creates a new Matrix of Vecs of the desired size.- Parameters:
rows- the number of rows in the matrixcols- the number of columns in the matrixsparse- iftrueSparseVectorobjects will be used for the rows. ElseDenseVectorwill be used.
-
-
Method Detail
-
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.
-
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
-
increment
public void increment(int i, int j, double value)Description copied from class:MatrixAlters the current matrix at index (i,j) to be equal to Ai,j = Ai,j + value
-
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
-
getRowView
public Vec getRowView(int r)
Description copied from class:MatrixObtains a vector that is backed by this, at very little memory cost. Mutations to this vector will alter the values stored in the matrix, and vice versa.- Overrides:
getRowViewin classMatrix- Parameters:
r- the row to obtain a view of- Returns:
- a vector backed by the specified row of the matrix
-
updateRow
public void updateRow(int i, double c, Vec b)Description copied from class:MatrixAlters row i of this matrix, such that A[i,:] = A[i,:] + c*b
-
multiply
public void multiply(Vec b, double z, Vec c)
Description copied from class:MatrixIf this matrix is Am x n, and b has a length of n, and c has a length of m, then this will mutate c to store c = c + A*b*z- Overrides:
multiplyin classGenericMatrix- Parameters:
b- the vector to be treated as a colum vectorz- the constant to multiply the A*b value by.c- where to place the result by addition
-
mutableMultiply
public void mutableMultiply(double c)
Description copied from class:MatrixAlters the current matrix to be equal to A*c- Overrides:
mutableMultiplyin classGenericMatrix- Parameters:
c- the scalar constant to multiply by
-
mutableAdd
public void mutableAdd(double c)
Description copied from class:MatrixAlters the current matrix to store the value A+c- Overrides:
mutableAddin classGenericMatrix- Parameters:
c- the scalar constant to add to this
-
zeroOut
public void zeroOut()
Description copied from class:MatrixAlters the current matrix so that all values are equal to zero.- Overrides:
zeroOutin classGenericMatrix
-
clone
public MatrixOfVecs clone()
- Overrides:
clonein classGenericMatrix
-
-
DataMelt 3.0 © DataMelt by jWork.ORG