umontreal.iro.lecuyer.util
Class DMatrix
- java.lang.Object
-
- umontreal.iro.lecuyer.util.DMatrix
-
public class DMatrix extends java.lang.ObjectThis class implements a few methods for matrix calculations with double numbers.
-
-
Constructor Summary
Constructors Constructor and Description DMatrix(DMatrix that)Copy constructor.DMatrix(double[][] data, int r, int c)Creates a new DMatrix with r rows and c columns using the data in data.DMatrix(int r, int c)Creates a new DMatrix with r rows and c columns.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description static voidCholeskyDecompose(double[][] M, double[][] L)Given a symmetric positive-definite matrix M, performs the Cholesky decomposition of M and returns the result as a lower triangular matrix L, such that M = LLT.static DoubleMatrix2DCholeskyDecompose(DoubleMatrix2D M)Given a symmetric positive-definite matrix M, performs the Cholesky decomposition of M and returns the result as a lower triangular matrix L, such that M = LLT.doubleget(int row, int column)Returns the matrix element in the specified row and column.intnumColumns()Returns the number of columns of the DMatrix.intnumRows()Returns the number of rows of the DMatrix.static voidPCADecompose(double[][] M, double[][] A, double[] lambda)Computes the principal components decomposition M = UΛUt by using the singular value decomposition of matrix M.static DoubleMatrix2DPCADecompose(DoubleMatrix2D M, double[] lambda)Computes the principal components decomposition M = UΛUt by using the singular value decomposition of matrix M.voidset(int row, int column, double value)Sets the value of the element in the specified row and column.java.lang.StringtoString()Creates aStringcontaining all the data of the DMatrix.static java.lang.StringtoString(double[][] M)Returns matrix M as a string.DMatrixtranspose()Returns the transposed matrix.
-
-
-
Constructor Detail
-
DMatrix
public DMatrix(int r, int c)Creates a new DMatrix with r rows and c columns.- Parameters:
r- the number of rowsc- the number of columns
-
DMatrix
public DMatrix(double[][] data, int r, int c)Creates a new DMatrix with r rows and c columns using the data in data.- Parameters:
data- the data of the new DMatrixr- the number of rowsc- the number of columns
-
DMatrix
public DMatrix(DMatrix that)
Copy constructor.- Parameters:
that- the DMatrix to copy
-
-
Method Detail
-
CholeskyDecompose
public static void CholeskyDecompose(double[][] M, double[][] L)Given a symmetric positive-definite matrix M, performs the Cholesky decomposition of M and returns the result as a lower triangular matrix L, such that M = LLT.- Parameters:
M- the input matrixL- the Cholesky lower triangular matrix
-
CholeskyDecompose
public static DoubleMatrix2D CholeskyDecompose(DoubleMatrix2D M)
Given a symmetric positive-definite matrix M, performs the Cholesky decomposition of M and returns the result as a lower triangular matrix L, such that M = LLT.- Parameters:
M- the input matrix- Returns:
- the Cholesky lower triangular matrix
-
PCADecompose
public static void PCADecompose(double[][] M, double[][] A, double[] lambda)Computes the principal components decomposition M = UΛUt by using the singular value decomposition of matrix M. Puts the eigenvalues, which are the diagonal elements of matrix Λ, sorted by decreasing size, in vector lambda, and puts matrix A = U(Λ)1/2 in A.- Parameters:
M- input matrixA- matrix square root of Mlambda- the eigenvalues
-
PCADecompose
public static DoubleMatrix2D PCADecompose(DoubleMatrix2D M, double[] lambda)
Computes the principal components decomposition M = UΛUt by using the singular value decomposition of matrix M. Puts the eigenvalues, which are the diagonal elements of matrix Λ, sorted by decreasing size, in vector lambda. Returns matrix A = U(Λ)1/2.- Parameters:
M- input matrixlambda- the eigenvalues- Returns:
- matrix square root of M
-
toString
public static java.lang.String toString(double[][] M)
Returns matrix M as a string. It is displayed in matrix form, with each row on a line.- Returns:
- the content of M
-
toString
public java.lang.String toString()
Creates aStringcontaining all the data of the DMatrix. The result is displayed in matrix form, with each row on a line.- Overrides:
toStringin classjava.lang.Object- Returns:
- the content of the DMatrix
-
numRows
public int numRows()
Returns the number of rows of the DMatrix.- Returns:
- the number of rows
-
numColumns
public int numColumns()
Returns the number of columns of the DMatrix.- Returns:
- the number of columns
-
get
public double get(int row, int column)Returns the matrix element in the specified row and column.- Parameters:
row- the row of the selected elementcolumn- the column of the selected element- Returns:
- the value of the element
- Throws:
java.lang.IndexOutOfBoundsException- if the selected element would be outside the DMatrix
-
set
public void set(int row, int column, double value)Sets the value of the element in the specified row and column.- Parameters:
row- the row of the selected elementcolumn- the column of the selected elementvalue- the new value of the element- Throws:
java.lang.IndexOutOfBoundsException- if the selected element would be outside the DMatrix
-
transpose
public DMatrix transpose()
Returns the transposed matrix. The rows and columns are interchanged.- Returns:
- the transposed matrix
-
-
DMelt 3.0 © DataMelt by jWork.ORG