jsat.linear
Class Matrix
- java.lang.Object
-
- jsat.linear.Matrix
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable
- Direct Known Subclasses:
- GenericMatrix, SparseMatrix
public abstract class Matrix extends java.lang.Object implements java.lang.Cloneable, java.io.SerializableGeneric class with some pre-implemented methods for a Matrix object. Throughout the documentation, the object that has its method called on will be denoted as A. So if you have code that looks likeMatrix gramHat = gram.subtract(Matrix.eye(gram.rows()));
Thengramwould be the matrix A in the documentation.
Matrices will use a capital letter, vectors a bold lower case letter, and scalars a normal lower case letter.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description Matrix()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method and Description Matrixadd(double c)Creates a new Matrix that stores the result ofA+cMatrixadd(double c, java.util.concurrent.ExecutorService threadPool)Creates a new Matrix that stores the result ofA+cMatrixadd(Matrix B)Creates a new Matrix that stores the result ofA+BMatrixadd(Matrix B, java.util.concurrent.ExecutorService threadPool)Creates a new Matrix that stores the result ofA+BbooleancanBeMutated()Indicates whether or not this matrix can be mutated.static booleancanMultiply(Matrix A, Matrix B)Convenience method that will returntrueonly if the two input matrices have dimensions compatible for multiplying A*Babstract 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.abstract Matrixclone()abstract intcols()Returns the number of columns stored in this matrixvoidcopyTo(Matrix other)Copes the values of this matrix into the other matrix of the same dimensionsstatic Matrixdiag(Vec a)Returns a new dense square matrix such that the main diagonal contains the values given in astatic voiddiagMult(Matrix A, Vec b)Alters the matrix A so that it contains the result of A times a sparse matrix represented by only its diagonal values or A = A*diag(b).static voiddiagMult(Vec b, Matrix A)Alters the matrix A so that it contains the result of sparse matrix represented by only its diagonal values times A or A = diag(b)*A.booleanequals(java.lang.Object obj)booleanequals(java.lang.Object obj, double range)Performs the same asequals(java.lang.Object), but allows a leniency in the differences between matrix values.static DenseMatrixeye(int k)Creates a new dense identity matrix with k rows and columns.abstract doubleget(int i, int j)Returns the value stored at at the matrix position Ai,jVecgetColumn(int j)Creates a vector that has a copy of the values in column j of this matrix.VecgetColumnView(int j)Obtains a vector that is backed by this, at very little memory cost.VecgetRow(int r)Creates a vector that has a copy of the values in row i of this matrix.VecgetRowView(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 + valueabstract booleanisSparce()Returnstrueif the matrix is sparse,falseotherwisebooleanisSquare()static booleanisSymmetric(Matrix A)Checks to see if the given input is a perfectly symmetric matrixstatic booleanisSymmetric(Matrix A, double eps)Checks to see if the given input is approximately symmetric.abstract Matrix[]lup()abstract Matrix[]lup(java.util.concurrent.ExecutorService threadPool)Matrixmultiply(double c)Creates a new Matrix that stores A*cMatrixmultiply(double c, java.util.concurrent.ExecutorService threadPool)Creates a new Matrix that stores A*cMatrixmultiply(Matrix B)Creates a new matrix that stores A*BMatrixmultiply(Matrix B, java.util.concurrent.ExecutorService threadPool)Creates a new matrix that stores A*Babstract voidmultiply(Matrix B, Matrix C)Alters the matrix C to be equal to C = C+A*Babstract voidmultiply(Matrix B, Matrix C, java.util.concurrent.ExecutorService threadPool)Alters the matrix C to be equal to C = C+A*BVecmultiply(Vec b)Creates a new vector that is equal to A*babstract voidmultiply(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*zMatrixmultiplyTranspose(Matrix B)Returns the new matrix C that is C = A*BTMatrixmultiplyTranspose(Matrix B, java.util.concurrent.ExecutorService threadPool)Returns the new matrix C that is C = A*BTabstract voidmultiplyTranspose(Matrix B, Matrix C)Alters the matrix C to be equal to C = C+A*BTabstract voidmultiplyTranspose(Matrix B, Matrix C, java.util.concurrent.ExecutorService threadPool)Alters the matrix C to be equal to C = C+A*BTabstract voidmutableAdd(double c)Alters the current matrix to store the value A+cabstract voidmutableAdd(double c, java.util.concurrent.ExecutorService threadPool)Alters the current matrix to store the value A+cabstract voidmutableAdd(double c, Matrix B)Alters the current matrix to store the value A+c*Babstract voidmutableAdd(double c, Matrix B, java.util.concurrent.ExecutorService threadPool)Alters the current matrix to store the value A+c*BvoidmutableAdd(Matrix B)Alters the current matrix to store the value A+BvoidmutableAdd(Matrix B, java.util.concurrent.ExecutorService threadpool)Alters the current matrix to store the value A+Babstract voidmutableMultiply(double c)Alters the current matrix to be equal to A*cabstract voidmutableMultiply(double c, java.util.concurrent.ExecutorService threadPool)Alters the current matrix to be equal to A*cvoidmutableSubtract(double c)Alters the current matrix to store A-cvoidmutableSubtract(double c, java.util.concurrent.ExecutorService threadPool)Alters the current matrix to store A-cvoidmutableSubtract(double c, Matrix B)Alters the current matrix to store A-c*BvoidmutableSubtract(double c, Matrix B, java.util.concurrent.ExecutorService threadPool)Alters the current matrix to store A-c*BvoidmutableSubtract(Matrix B)Alters the current matrix to store A-BvoidmutableSubtract(Matrix B, java.util.concurrent.ExecutorService threadpool)Alters the current matrix to store A-Babstract voidmutableTranspose()Transposes the current matrix in place, altering its value.longnnz()Returns the number of non zero values stored in this matrix.static voidOuterProductUpdate(Matrix A, Vec x, Vec y, double c)Alters the matrix A such that, A = A + c * x * y'static voidOuterProductUpdate(Matrix A, Vec x, Vec y, double c, java.util.concurrent.ExecutorService threadpool)Alters the matrix A such that, A = A + c * x * y'static Matrixpascal(int size)Creates a new square matrix that is a pascal matrix.abstract Matrix[]qr()abstract Matrix[]qr(java.util.concurrent.ExecutorService threadPool)static DenseMatrixrandom(int rows, int cols, java.util.Random rand)Creates a new dense matrix filled with random values fromRandom.nextDouble()abstract introws()Returns the number of rows stored in this matrixstatic booleansameDimensions(Matrix A, Matrix B)Convenience method that will returntrueonly if the two input matrices have the exact same dimensions.abstract voidset(int i, int j, double value)Sets the value stored at at the matrix position Ai,jMatrixsubtract(double c)Creates a new Matrix that stores the result of A-cMatrixsubtract(double c, java.util.concurrent.ExecutorService threadPool)Creates a new Matrix that stores the result of A-cMatrixsubtract(Matrix B)Creates a new Matrix that stores the result of A-BMatrixsubtract(Matrix B, java.util.concurrent.ExecutorService threadPool)Creates a new Matrix that stores the result of A-Babstract voidswapRows(int r1, int r2)Alters the current matrix by swapping the values stored in two different rows.java.lang.StringtoString()Matrixtranspose()Returns a new matrix that is the transpose of this matrix.abstract voidtranspose(Matrix C)Overwrites the values stored in matrix C to store the value of A'VectransposeMultiply(double c, Vec b)Creates a new vector equal to x = A'*b*cabstract voidtransposeMultiply(double c, Vec b, Vec x)Alters the vector x to be equal to x = x + A'*b*cMatrixtransposeMultiply(Matrix B)Creates a new matrix equal to A'*B, or the same result as
A.transpose().multiply(B)MatrixtransposeMultiply(Matrix B, java.util.concurrent.ExecutorService threadPool)Computes the result matrix of A'*B, or the same result as
A.transpose().multiply(B)abstract voidtransposeMultiply(Matrix B, Matrix C)Alters the matrix C so that C = C + A'*Babstract voidtransposeMultiply(Matrix B, Matrix C, java.util.concurrent.ExecutorService threadPool)Alters the matrix C so that C = C + A'*BvoidupdateRow(int i, double c, Vec b)Alters row i of this matrix, such that A[i,:] = A[i,:] + c*babstract voidzeroOut()Alters the current matrix so that all values are equal to zero.
-
-
-
Method Detail
-
add
public Matrix add(Matrix B)
Creates a new Matrix that stores the result ofA+B- Parameters:
B- the matrix to add this this- Returns:
A+B
-
add
public Matrix add(Matrix B, java.util.concurrent.ExecutorService threadPool)
Creates a new Matrix that stores the result ofA+B- Parameters:
B- the matrix to add this thisthreadPool- the source of threads to do computation in parallel- Returns:
A+B
-
add
public Matrix add(double c)
Creates a new Matrix that stores the result ofA+c- Parameters:
c- the scalar to add to each value in this- Returns:
A+c
-
add
public Matrix add(double c, java.util.concurrent.ExecutorService threadPool)
Creates a new Matrix that stores the result ofA+c- Parameters:
c- the scalar to add to each value in thisthreadPool- the source of threads to do computation in parallel- Returns:
A+B
-
mutableAdd
public void mutableAdd(Matrix B)
Alters the current matrix to store the value A+B- Parameters:
B- the matrix to add this this
-
mutableAdd
public abstract void mutableAdd(double c, Matrix B)Alters the current matrix to store the value A+c*B- Parameters:
c- the scalar constant to multiple B byB- the matrix to add to this
-
mutableAdd
public void mutableAdd(Matrix B, java.util.concurrent.ExecutorService threadpool)
Alters the current matrix to store the value A+B- Parameters:
B- the matrix to add to thisthreadpool- the source of threads to do computation in parallel
-
mutableAdd
public abstract void mutableAdd(double c, Matrix B, java.util.concurrent.ExecutorService threadPool)Alters the current matrix to store the value A+c*B- Parameters:
c- the scalar constant to multiple B byB- the matrix to add to thisthreadPool- the source of threads to do computation in parallel
-
mutableAdd
public abstract void mutableAdd(double c)
Alters the current matrix to store the value A+c- Parameters:
c- the scalar constant to add to this
-
mutableAdd
public abstract void mutableAdd(double c, java.util.concurrent.ExecutorService threadPool)Alters the current matrix to store the value A+c- Parameters:
c- the scalar constant to add to thisthreadPool- the source of threads to do computation in parallel
-
canBeMutated
public boolean canBeMutated()
Indicates whether or not this matrix can be mutated. Iffalse, any method that contains "mutate" will not work.
By default, this returnstrue- Returns:
trueif the matrix supports being altered,falseother wise.
-
subtract
public Matrix subtract(Matrix B)
Creates a new Matrix that stores the result of A-B- Parameters:
B- the matrix to subtract from this.- Returns:
- a new matrix equal to A-B
-
subtract
public Matrix subtract(Matrix B, java.util.concurrent.ExecutorService threadPool)
Creates a new Matrix that stores the result of A-B- Parameters:
B- the matrix to subtract from this.threadPool- the source of threads to do computation in parallel- Returns:
- a new matrix equal to A-B
-
subtract
public Matrix subtract(double c)
Creates a new Matrix that stores the result of A-c- Parameters:
c- the scalar constant to subtract from this- Returns:
- a new matrix equal to A-B
-
subtract
public Matrix subtract(double c, java.util.concurrent.ExecutorService threadPool)
Creates a new Matrix that stores the result of A-c- Parameters:
c- the scalar constant to subtract from thisthreadPool- the source of threads to do computation in parallel- Returns:
- a new matrix equal to A-B
-
mutableSubtract
public void mutableSubtract(Matrix B)
Alters the current matrix to store A-B- Parameters:
B- the matrix to subtract from this.
-
mutableSubtract
public void mutableSubtract(double c, Matrix B)Alters the current matrix to store A-c*B- Parameters:
c- the scalar constant to multiply B byB- the matrix to subtract from this.
-
mutableSubtract
public void mutableSubtract(Matrix B, java.util.concurrent.ExecutorService threadpool)
Alters the current matrix to store A-B- Parameters:
B- the matrix to subtract from this.threadpool- the source of threads to do computation in parallel
-
mutableSubtract
public void mutableSubtract(double c, Matrix B, java.util.concurrent.ExecutorService threadPool)Alters the current matrix to store A-c*B- Parameters:
c- the scalar constant to multiply B byB- the matrix to subtract from this.threadPool- the source of threads to do computation in parallel
-
mutableSubtract
public void mutableSubtract(double c)
Alters the current matrix to store A-c- Parameters:
c- the scalar constant to subtract from this
-
mutableSubtract
public void mutableSubtract(double c, java.util.concurrent.ExecutorService threadPool)Alters the current matrix to store A-c- Parameters:
c- the scalar constant to subtract from thisthreadPool- the source of threads to do computation in parallel
-
multiply
public abstract void multiply(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*z- 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- Throws:
java.lang.ArithmeticException- if the dimensions of A, b, or c do not all agree
-
multiply
public Vec multiply(Vec b)
Creates a new vector that is equal to A*b- Parameters:
b- the vector to multiply by- Returns:
- a new vector A*b
-
multiply
public Matrix multiply(Matrix B)
Creates a new matrix that stores A*B- Parameters:
B- the matrix to multiply by- Returns:
- a new matrix A*B
-
multiply
public Matrix multiply(Matrix B, java.util.concurrent.ExecutorService threadPool)
Creates a new matrix that stores A*B- Parameters:
B- the matrix to multiply bythreadPool- the source of threads to do computation in parallel- Returns:
- a new matrix A*B
-
multiply
public abstract void multiply(Matrix B, Matrix C)
Alters the matrix C to be equal to C = C+A*B- Parameters:
B- the matrix to multiply this withC- the matrix to add the result to
-
multiply
public abstract void multiply(Matrix B, Matrix C, java.util.concurrent.ExecutorService threadPool)
Alters the matrix C to be equal to C = C+A*B- Parameters:
B- the matrix to multiply this withC- the matrix to add the result tothreadPool- the source of threads to do computation in parallel
-
multiplyTranspose
public abstract void multiplyTranspose(Matrix B, Matrix C)
Alters the matrix C to be equal to C = C+A*BT- Parameters:
B- the matrix to multiply this withC- the matrix to add the result to
-
multiplyTranspose
public Matrix multiplyTranspose(Matrix B)
Returns the new matrix C that is C = A*BT- Parameters:
B- the matrix to multiply by the transpose of- Returns:
- the result C
-
multiplyTranspose
public abstract void multiplyTranspose(Matrix B, Matrix C, java.util.concurrent.ExecutorService threadPool)
Alters the matrix C to be equal to C = C+A*BT- Parameters:
B- the matrix to multiply this withC- the matrix to add the result tothreadPool- the source of threads to do computation in parallel
-
multiplyTranspose
public Matrix multiplyTranspose(Matrix B, java.util.concurrent.ExecutorService threadPool)
Returns the new matrix C that is C = A*BT- Parameters:
B- the matrix to multiply by the transpose ofthreadPool- the source of threads to do computation in parallel- Returns:
- the result C
-
multiply
public Matrix multiply(double c)
Creates a new Matrix that stores A*c- Parameters:
c- the scalar constant to multiply by- Returns:
- a new vector A*c
-
multiply
public Matrix multiply(double c, java.util.concurrent.ExecutorService threadPool)
Creates a new Matrix that stores A*c- Parameters:
c- the scalar constant to multiply bythreadPool- the source of threads to do computation in parallel- Returns:
- a new matrix equal to A*c
-
mutableMultiply
public abstract void mutableMultiply(double c)
Alters the current matrix to be equal to A*c- Parameters:
c- the scalar constant to multiply by
-
mutableMultiply
public abstract void mutableMultiply(double c, java.util.concurrent.ExecutorService threadPool)Alters the current matrix to be equal to A*c- Parameters:
c- the scalar constant to multiply bythreadPool- the source of threads to do computation in parallel
-
lup
public abstract Matrix[] lup()
-
lup
public abstract Matrix[] lup(java.util.concurrent.ExecutorService threadPool)
-
qr
public abstract Matrix[] qr()
-
qr
public abstract Matrix[] qr(java.util.concurrent.ExecutorService threadPool)
-
changeSize
public abstract void changeSize(int newRows, int newCols)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.- Parameters:
newRows- the new number of rows, must be positivenewCols- the new number of columns, must be positive.
-
mutableTranspose
public abstract void mutableTranspose()
Transposes the current matrix in place, altering its value. Only valid for square matrices
-
transpose
public Matrix transpose()
Returns a new matrix that is the transpose of this matrix.- Returns:
- a new matrix A'
-
transpose
public abstract void transpose(Matrix C)
Overwrites the values stored in matrix C to store the value of A'- Parameters:
C- the matrix to store the transpose of the current matrix- Throws:
java.lang.ArithmeticException- if the dimensions of C do not match the dimensions of this'
-
transposeMultiply
public Matrix transposeMultiply(Matrix B)
Creates a new matrix equal to A'*B, or the same result as
A.transpose().multiply(B)- Parameters:
B- the other Matrix- Returns:
- a new matrix equal to A'*B
-
transposeMultiply
public abstract void transposeMultiply(Matrix B, Matrix C)
Alters the matrix C so that C = C + A'*B- Parameters:
B- the matrix to multiply byC- the matrix to add the result to
-
transposeMultiply
public Matrix transposeMultiply(Matrix B, java.util.concurrent.ExecutorService threadPool)
Computes the result matrix of A'*B, or the same result as
A.transpose().multiply(B)- Parameters:
B- the matrix to multiply bythreadPool- the source of threads to do computation in parallel- Returns:
- a new matrix equal to A'*B
-
transposeMultiply
public abstract void transposeMultiply(Matrix B, Matrix C, java.util.concurrent.ExecutorService threadPool)
Alters the matrix C so that C = C + A'*B- Parameters:
B- the matrix to multiply byC- the matrix to place the results inthreadPool- the source of threads to do computation in parallel
-
transposeMultiply
public abstract void transposeMultiply(double c, Vec b, Vec x)Alters the vector x to be equal to x = x + A'*b*c- Parameters:
c- the scalar constant to multiply byb- the vector to multiply byx- the vector the add the result to
-
transposeMultiply
public Vec transposeMultiply(double c, Vec b)
Creates a new vector equal to x = A'*b*c- Parameters:
c- the scalar constant to multiply byb- the vector to multiply by- Returns:
- the new vector equal to A'*b*c
-
get
public abstract double get(int i, int j)Returns the value stored at at the matrix position Ai,j- Parameters:
i- the row, starting from 0j- the column, starting from 0- Returns:
- the value at Ai,j
-
set
public abstract void set(int i, int j, double value)Sets the value stored at at the matrix position Ai,j- Parameters:
i- the row, starting from 0j- the column, starting from 0value- the value to place at Ai,j
-
increment
public void increment(int i, int j, double value)Alters the current matrix at index (i,j) to be equal to Ai,j = Ai,j + value- Parameters:
i- the row, starting from 0j- the column, starting from 0value- the value to add to the matrix coordinate
-
rows
public abstract int rows()
Returns the number of rows stored in this matrix- Returns:
- the number of rows stored in this matrix
-
cols
public abstract int cols()
Returns the number of columns stored in this matrix- Returns:
- the number of columns stored in this matrix
-
isSparce
public abstract boolean isSparce()
Returnstrueif the matrix is sparse,falseotherwise- Returns:
trueif the matrix is sparse,falseotherwise
-
nnz
public long nnz()
Returns the number of non zero values stored in this matrix. This is mostly useful for sparse matrices.- Returns:
- the number of non zero values stored in this matrix.
-
isSquare
public boolean isSquare()
- Returns:
trueif this matrix is square,falseif it is rectangular.
-
swapRows
public abstract void swapRows(int r1, int r2)Alters the current matrix by swapping the values stored in two different rows.- Parameters:
r1- the first row to swapr2- the second row to swap
-
getColumn
public Vec getColumn(int j)
Creates a vector that has a copy of the values in column j of this matrix. Altering it will not effect the values in this matrix- Parameters:
j- the column to copy- Returns:
- a clone of the column as a
Vec
-
getColumnView
public Vec getColumnView(int j)
Obtains 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.- Parameters:
j- the column to obtain a view of- Returns:
- a vector backed by the specified row of the matrix
-
getRow
public Vec getRow(int r)
Creates a vector that has a copy of the values in row i of this matrix. Altering it will not effect the values in this matrix.- Parameters:
r- the row to copy- Returns:
- a clone of the row as a
Vec
-
getRowView
public Vec getRowView(int r)
Obtains 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.- Parameters:
r- the row to obtain a view of- Returns:
- a vector backed by the specified row of the matrix
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
sameDimensions
public static boolean sameDimensions(Matrix A, Matrix B)
Convenience method that will returntrueonly if the two input matrices have the exact same dimensions.- Parameters:
A- the first matrixB- the second matrix- Returns:
trueif they have the exact same dimensions,falseotherwise.
-
canMultiply
public static boolean canMultiply(Matrix A, Matrix B)
Convenience method that will returntrueonly if the two input matrices have dimensions compatible for multiplying A*B- Parameters:
A- the first matrixB- the second matrix- Returns:
trueif they have dimensions allowing multiplication,falseotherwise.
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj, double range)Performs the same asequals(java.lang.Object), but allows a leniency in the differences between matrix values. This is useful for when some amount of numerical error is expected- Parameters:
obj- the other matrixrange- the max acceptable difference between two cell values- Returns:
trueif the difference between the values of each pair of matrix elements are less than or equal to range
-
zeroOut
public abstract void zeroOut()
Alters the current matrix so that all values are equal to zero.
-
copyTo
public void copyTo(Matrix other)
Copes the values of this matrix into the other matrix of the same dimensions- Parameters:
other- the matrix to overwrite the values of
-
updateRow
public void updateRow(int i, double c, Vec b)Alters row i of this matrix, such that A[i,:] = A[i,:] + c*b- Parameters:
i- the index of the row to updatec- the scalar constant to multiply the vector byb- the vector to add to the specified row
-
OuterProductUpdate
public static void OuterProductUpdate(Matrix A, Vec x, Vec y, double c)
Alters the matrix A such that, A = A + c * x * y'- Parameters:
A- the matrix to updatex- the first vectory- the second vectorc- the scalar constant to multiply the outer product by- Throws:
java.lang.ArithmeticException- if the vector dimensions are not compatible with the matrix A
-
OuterProductUpdate
public static void OuterProductUpdate(Matrix A, Vec x, Vec y, double c, java.util.concurrent.ExecutorService threadpool)
Alters the matrix A such that, A = A + c * x * y'- Parameters:
A- the matrix to updatex- the first vectory- the second vectorc- the scalar constant to multiply the outer product bythreadpool- the source of threads to do computation in parallel
-
eye
public static DenseMatrix eye(int k)
Creates a new dense identity matrix with k rows and columns.- Parameters:
k- the number of rows / columns- Returns:
- a new dense identity matrix Ik
-
random
public static DenseMatrix random(int rows, int cols, java.util.Random rand)
Creates a new dense matrix filled with random values fromRandom.nextDouble()- Parameters:
rows- the number of rows for the matrixcols- the number of columns for the matrixrand- the source of randomness- Returns:
- a new dense matrix full of random values
-
diag
public static Matrix diag(Vec a)
Returns a new dense square matrix such that the main diagonal contains the values given in a- Parameters:
a- the diagonal values of a matrix- Returns:
- the diagonal matrix represent by a
-
diagMult
public static void diagMult(Matrix A, Vec b)
Alters the matrix A so that it contains the result of A times a sparse matrix represented by only its diagonal values or A = A*diag(b). This is equivalent to the codeA = A.multiply(diag(b))- Parameters:
A- the square matrix to updateb- the diagonal value vector
-
diagMult
public static void diagMult(Vec b, Matrix A)
Alters the matrix A so that it contains the result of sparse matrix represented by only its diagonal values times A or A = diag(b)*A. This is equivalent to the codeb.multiply(diag(A))- Parameters:
b- the diagonal value vectorA- the square matrix to update
-
isSymmetric
public static boolean isSymmetric(Matrix A, double eps)
Checks to see if the given input is approximately symmetric. Rounding errors may cause the computation of a matrix to come out non symmetric, where |a[i,h] - a[j, i]| < eps. Despite these errors, it may be preferred to treat the matrix as perfectly symmetric regardless.- Parameters:
A- the input matrixeps- the maximum tolerable difference between two entries- Returns:
trueif the matrix is approximately symmetric
-
isSymmetric
public static boolean isSymmetric(Matrix A)
Checks to see if the given input is a perfectly symmetric matrix- Parameters:
A- the input matrix- Returns:
trueif it is perfectly symmetric.
-
pascal
public static Matrix pascal(int size)
Creates a new square matrix that is a pascal matrix. The pascal matrix of size n is n by n and symmetric.- Parameters:
size- the number of rows and columns for the matrix- Returns:
- a pascal matrix of the desired size
-
clone
public abstract Matrix clone()
- Overrides:
clonein classjava.lang.Object
-
-
DataMelt 3.0 © DataMelt by jWork.ORG