Module: Matrix2DFloatingAlgebra

Included in:
FloatingMDMatrix2D
Defined in:
lib/colt/matrix/matrix2D_floating_algebra.rb

Instance Method Summary collapse

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

#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.




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

#condObject


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

#detObject


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

#eigObject





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

#inverseObject


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

#luObject


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

#norm1Object


Returns the one-norm of vector x, which is Sum(abs(x)).




150
151
152
# File 'lib/colt/matrix/matrix2D_floating_algebra.rb', line 150

def norm1
  @algebra.norm1(@colt_matrix)
end

#norm2Object


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_infinityObject


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

#normFObject


Returns the Frobenius norm of matrix A, which is Sqrt(Sum(A^2))




167
168
169
# File 'lib/colt/matrix/matrix2D_floating_algebra.rb', line 167

def normF
  @algebra.normF(@colt_matrix)
end

#numerical_rankObject


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

#svdObject


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

#traceObject


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




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

def trace
  @algebra.trace(@colt_matrix)
end

#trapezoidal_lowerObject


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_norm2Object


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