Module: Matrix2DFloatingAlgebra
- Included in:
- FloatingMDMatrix2D
- Defined in:
- lib/colt/matrix/matrix2D_floating_algebra.rb
Instance Method Summary collapse
-
#backward_solve(matrix1D) ⇒ Object
———————————————————————————— Solves the upper triangular system U*x=b; ————————————————————————————.
-
#chol ⇒ Object
———————————————————————————— Constructs and returns the cholesky-decomposition of the given matrix.
-
#cond ⇒ Object
———————————————————————————— Returns the condition of matrix A, which is the ratio of largest to smallest singular value.
-
#det ⇒ Object
———————————————————————————— Returns the determinant of matrix A.
-
#eig ⇒ Object
————————————————————————————.
-
#forward_solve(matrix1D) ⇒ Object
———————————————————————————— Solves the lower triangular system L*x=b; ————————————————————————————.
-
#inverse ⇒ Object
———————————————————————————— Returns the inverse or pseudo-inverse of matrix A.
-
#kron(matrix) ⇒ Object
———————————————————————————— Computes the Kronecker product of two real matrices.
-
#lu ⇒ Object
———————————————————————————— Constructs and returns the LU-decomposition of the given matrix.
-
#mult(matrix) ⇒ Object
(also: #*)
———————————————————————————— Multiplies this matrix by another matrix ————————————————————————————.
-
#norm1 ⇒ Object
———————————————————————————— Returns the one-norm of vector x, which is Sum(abs(x)).
-
#norm2 ⇒ Object
———————————————————————————— Returns the two-norm of matrix A, which is the maximum singular value; obtained from SVD.
-
#norm_infinity ⇒ Object
———————————————————————————— Returns the infinity norm of matrix A, which is the maximum absolute row sum.
-
#normF ⇒ Object
———————————————————————————— Returns the Frobenius norm of matrix A, which is Sqrt(Sum(A^2)) ————————————————————————————.
-
#numerical_rank ⇒ Object
———————————————————————————— Returns the effective numerical rank of matrix A, obtained from Singular Value Decomposition.
-
#power(val) ⇒ Object
(also: #**)
———————————————————————————— Linear algebraic matrix power; B = A^k <==> B = A*A*…
-
#solve(matrix) ⇒ Object
———————————————————————————— Solves A*X = B ————————————————————————————.
-
#solve_transpose(matrix) ⇒ Object
———————————————————————————— Solves X*A = B, which is also A’*X’ = B’.
-
#svd ⇒ Object
———————————————————————————— Constructs and returns the SingularValue-decomposition of the given matrix.
-
#trace ⇒ Object
———————————————————————————— Returns the sum of the diagonal elements of matrix A; Sum(A).
-
#trapezoidal_lower ⇒ Object
———————————————————————————— Modifies the matrix to be a lower trapezoidal matrix.
-
#vector_norm2 ⇒ Object
———————————————————————————— Returns the two-norm (aka euclidean norm) of vector X.vectorize(); ————————————————————————————.
Instance Method Details
#backward_solve(matrix1D) ⇒ Object
Solves the upper triangular system U*x=b;
39 40 41 42 |
# File 'lib/colt/matrix/matrix2D_floating_algebra.rb', line 39 def backward_solve(matrix1D) result = @algebra.backwardSolve(@colt_matrix, matrix1D.colt_matrix) MDMatrix.from_colt_matrix(result) end |
#chol ⇒ Object
Constructs and returns the cholesky-decomposition of the given matrix. For a symmetric, positive definite matrix A, the Cholesky decomposition is a lower triangular matrix L so that A = L*L’; If the matrix is not symmetric positive definite, the IllegalArgumentException is thrown.
51 52 53 54 |
# File 'lib/colt/matrix/matrix2D_floating_algebra.rb', line 51 def chol result = @algebra.chol(@colt_matrix).getL() MDMatrix.from_colt_matrix(result) end |
#cond ⇒ Object
Returns the condition of matrix A, which is the ratio of largest to smallest singular value.
61 62 63 |
# File 'lib/colt/matrix/matrix2D_floating_algebra.rb', line 61 def cond @algebra.cond(@colt_matrix) end |
#det ⇒ Object
Returns the determinant of matrix A.
69 70 71 |
# File 'lib/colt/matrix/matrix2D_floating_algebra.rb', line 69 def det @algebra.det(@colt_matrix) end |
#eig ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/colt/matrix/matrix2D_floating_algebra.rb', line 77 def eig eig = @algebra.eig(@colt_matrix) [MDMatrix.from_colt_matrix(eig.getD), MDMatrix.from_colt_matrix(eig.getImagEigenvalues), MDMatrix.from_colt_matrix(eig.getRealEigenvalues), MDMatrix.from_colt_matrix(eig.getV)] end |
#forward_solve(matrix1D) ⇒ Object
Solves the lower triangular system L*x=b;
89 90 91 92 |
# File 'lib/colt/matrix/matrix2D_floating_algebra.rb', line 89 def forward_solve(matrix1D) result = @algebra.forwardSolve(@colt_matrix, matrix1D.colt_matrix) MDMatrix.from_colt_matrix(result) end |
#inverse ⇒ Object
Returns the inverse or pseudo-inverse of matrix A.
98 99 100 101 |
# File 'lib/colt/matrix/matrix2D_floating_algebra.rb', line 98 def inverse result = @algebra.inverse(@colt_matrix) MDMatrix.from_colt_matrix(result) end |
#kron(matrix) ⇒ Object
Computes the Kronecker product of two real matrices.
107 108 109 110 111 112 113 114 115 |
# File 'lib/colt/matrix/matrix2D_floating_algebra.rb', line 107 def kron(matrix) if (matrix.rank != 2) raise "Rank should be 2" end result = @algebra.kron(@colt_matrix, matrix.colt_matrix) MDMatrix.from_colt_matrix(result) end |
#lu ⇒ Object
Constructs and returns the LU-decomposition of the given matrix.
121 122 123 124 125 126 |
# File 'lib/colt/matrix/matrix2D_floating_algebra.rb', line 121 def lu result = @algebra.lu(@colt_matrix) [result.isNonsingular(), result.det(), result.getPivot.to_a(), MDMatrix.from_colt_matrix(result.getL()), MDMatrix.from_colt_matrix(result.getU())] end |
#mult(matrix) ⇒ Object Also known as: *
Multiplies this matrix by another matrix
132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/colt/matrix/matrix2D_floating_algebra.rb', line 132 def mult(matrix) if (matrix.rank > 2) raise "Rank should be 1 or 2" end result = @colt_matrix.like @colt_matrix.zMult(matrix.colt_matrix, result) MDMatrix.from_colt_matrix(result) end |
#norm1 ⇒ Object
150 151 152 |
# File 'lib/colt/matrix/matrix2D_floating_algebra.rb', line 150 def norm1 @algebra.norm1(@colt_matrix) end |
#norm2 ⇒ Object
Returns the two-norm of matrix A, which is the maximum singular value; obtained from SVD.
159 160 161 |
# File 'lib/colt/matrix/matrix2D_floating_algebra.rb', line 159 def norm2 @algebra.norm2(@colt_matrix) end |
#norm_infinity ⇒ Object
Returns the infinity norm of matrix A, which is the maximum absolute row sum.
175 176 177 |
# File 'lib/colt/matrix/matrix2D_floating_algebra.rb', line 175 def norm_infinity @algebra.normInfinity(@colt_matrix) end |
#normF ⇒ Object
167 168 169 |
# File 'lib/colt/matrix/matrix2D_floating_algebra.rb', line 167 def normF @algebra.normF(@colt_matrix) end |
#numerical_rank ⇒ Object
Returns the effective numerical rank of matrix A, obtained from Singular Value Decomposition.
195 196 197 |
# File 'lib/colt/matrix/matrix2D_floating_algebra.rb', line 195 def numerical_rank @algebra.rank(@colt_matrix) end |
#power(val) ⇒ Object Also known as: **
Linear algebraic matrix power; B = A^k <==> B = A*A*…
183 184 185 186 |
# File 'lib/colt/matrix/matrix2D_floating_algebra.rb', line 183 def power(val) result = @algebra.pow(@colt_matrix, val) MDMatrix.from_colt_matrix(result) end |
#solve(matrix) ⇒ Object
Solves A*X = B
203 204 205 206 |
# File 'lib/colt/matrix/matrix2D_floating_algebra.rb', line 203 def solve(matrix) result = @algebra.solve(@colt_matrix, matrix.colt_matrix) MDMatris.from_colt_matrix(resul) end |
#solve_transpose(matrix) ⇒ Object
Solves X*A = B, which is also A’*X’ = B’.
212 213 214 215 |
# File 'lib/colt/matrix/matrix2D_floating_algebra.rb', line 212 def solve_transpose(matrix) result = @algebra.solveTranspose(@colt_matrix, matrix.colt_matrix) MDMatris.from_colt_matrix(resul) end |
#svd ⇒ Object
Constructs and returns the SingularValue-decomposition of the given matrix.
221 222 223 224 225 226 227 228 |
# File 'lib/colt/matrix/matrix2D_floating_algebra.rb', line 221 def svd result = @algebra.svd(@colt_matrix) [result.getInfo().val, result.cond(), result.norm2(), result.rank(), result.getSingularValues().to_a(), MDMatrix.from_colt_matrix(result.getS()), MDMatrix.from_colt_matrix(result.getU()), MDMatrix.from_colt_matrix(result.getV())] end |
#trace ⇒ Object
234 235 236 |
# File 'lib/colt/matrix/matrix2D_floating_algebra.rb', line 234 def trace @algebra.trace(@colt_matrix) end |
#trapezoidal_lower ⇒ Object
Modifies the matrix to be a lower trapezoidal matrix.
242 243 244 245 |
# File 'lib/colt/matrix/matrix2D_floating_algebra.rb', line 242 def trapezoidal_lower result = @algebra.trapezoidalLower(@colt_matrix) MDMatrix.from_colt_matrix(result) end |
#vector_norm2 ⇒ Object
Returns the two-norm (aka euclidean norm) of vector X.vectorize();
251 252 253 |
# File 'lib/colt/matrix/matrix2D_floating_algebra.rb', line 251 def vector_norm2 @algebra.vectorNorm2(@colt_matrix) end |