Module: Colt::Matrix2DFloatingAlgebra

Included in:
DoubleMDMatrix2D, FloatMDMatrix2D
Defined in:
lib/colt/matrix/algebra.rb

Instance Method Summary collapse

Instance Method Details

#backward_solve(matrix1D) ⇒ Object


Solves the upper triangular system U*x=b;




184
185
186
187
# File 'lib/colt/matrix/algebra.rb', line 184

def backward_solve(matrix1D)
  result = @colt_algebra.backwardSolve(@colt_matrix, matrix1D.colt_matrix)
  MDMatrix.from_colt_matrix(result)
end

#cholObject


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.




196
197
198
199
# File 'lib/colt/matrix/algebra.rb', line 196

def chol
  result = @colt_algebra.chol(@colt_matrix).getL()
  MDMatrix.from_colt_matrix(result)
end

#condObject


Returns the condition of matrix A, which is the ratio of largest to smallest singular value.




206
207
208
# File 'lib/colt/matrix/algebra.rb', line 206

def cond
  @colt_algebra.cond(@colt_matrix)
end

#detObject


Returns the determinant of matrix A.




214
215
216
# File 'lib/colt/matrix/algebra.rb', line 214

def det
  @colt_algebra.det(@colt_matrix)
end

#eigObject





222
223
224
225
226
227
228
# File 'lib/colt/matrix/algebra.rb', line 222

def eig
  eig = @colt_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;




234
235
236
237
# File 'lib/colt/matrix/algebra.rb', line 234

def forward_solve(matrix1D)
  result = @colt_algebra.forwardSolve(@colt_matrix, matrix1D.colt_matrix)
  MDMatrix.from_colt_matrix(result)
end

#inverseObject


Returns the inverse or pseudo-inverse of matrix A.




243
244
245
246
# File 'lib/colt/matrix/algebra.rb', line 243

def inverse
  result = @colt_algebra.inverse(@colt_matrix)
  MDMatrix.from_colt_matrix(result)
end

#luObject


Constructs and returns the LU-decomposition of the given matrix.




252
253
254
255
256
257
# File 'lib/colt/matrix/algebra.rb', line 252

def lu
  result = @colt_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

#numerical_rankObject


Returns the effective numerical rank of matrix A, obtained from Singular Value Decomposition.




264
265
266
# File 'lib/colt/matrix/algebra.rb', line 264

def numerical_rank
  @colt_algebra.rank(@colt_matrix)
end

#power(val) ⇒ Object Also known as: **


Linear algebraic matrix power; B = A^k <==> B = A*A*…




272
273
274
275
# File 'lib/colt/matrix/algebra.rb', line 272

def power(val)
  result = @colt_algebra.pow(@colt_matrix, val)
  MDMatrix.from_colt_matrix(result)
end

#solve(matrix) ⇒ Object


Solves A*X = B




283
284
285
286
# File 'lib/colt/matrix/algebra.rb', line 283

def solve(matrix)
  result = @colt_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’.




292
293
294
295
# File 'lib/colt/matrix/algebra.rb', line 292

def solve_transpose(matrix)
  result = @colt_algebra.solveTranspose(@colt_matrix, matrix.colt_matrix)
  MDMatris.from_colt_matrix(resul)
end

#svdObject


Constructs and returns the SingularValue-decomposition of the given matrix.




301
302
303
304
305
306
307
308
# File 'lib/colt/matrix/algebra.rb', line 301

def svd
  result = @colt_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

#traceObject


Returns the sum of the diagonal elements of matrix A; Sum(A).




314
315
316
# File 'lib/colt/matrix/algebra.rb', line 314

def trace
  @colt_algebra.trace(@colt_matrix)
end

#trapezoidal_lowerObject


Modifies the matrix to be a lower trapezoidal matrix.




322
323
324
325
# File 'lib/colt/matrix/algebra.rb', line 322

def trapezoidal_lower
  result = @colt_algebra.trapezoidalLower(@colt_matrix)
  MDMatrix.from_colt_matrix(result)
end

#vector_norm2Object


Returns the two-norm (aka euclidean norm) of vector X.vectorize();




331
332
333
# File 'lib/colt/matrix/algebra.rb', line 331

def vector_norm2
  @colt_algebra.vectorNorm2(@colt_matrix)
end