Class: Reem::CholeskyFactorization

Inherits:
Object
  • Object
show all
Defined in:
lib/reem/cholesky_factorization.rb

Instance Method Summary collapse

Constructor Details

#initialize(matrix) ⇒ CholeskyFactorization

Returns a new instance of CholeskyFactorization.



3
4
5
6
7
# File 'lib/reem/cholesky_factorization.rb', line 3

def initialize(matrix)
  @matrix = matrix
  @lower = LowerTriangularMatrix.new(matrix)
  decompose!
end

Instance Method Details

#decompose!Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/reem/cholesky_factorization.rb', line 9

def decompose!
  @lower.n.times do |j|
    # Sqrt the diagonal
    @lower[j,j] = Math::sqrt(@lower[j,j])
    # Divide the subdiagonal colum by the diagonal

    (j + 1...@lower.m).each do |i|
      @lower[i,j] = @lower[i,j] / @lower[j,j]
    end

    # symmetric rank 1 update
    # subtract the crossproduct of the
    # subdiagonal column from the remaining
    # lower diagonal
    (j+1...@lower.n).each do |k|
      (k...@lower.m).each do |l|
        @lower[l,k] = @lower[l, k] - @lower[l,k] * @lower[k,j]
      end
    end
  end

  @upper = @lower.transpose
end