Ankur Goel

On hunt of awesomeness!

Kalman and Cholesky Decomposition

Hi everyone!

First, this blog is coming a bit late than usual; sorry for that. I was traveling to my hometown(Delhi) for some occassion and couldn’t do much in last 3 days. I am thankful to Claudio for his support.

So, in this phase, as discussed, we continue to compose estimation methods for ARMA/ARIMA. Good news - Most of method seem to be in place. Even if we manage to make atleast one or two; we seem to be in good position. Bad news - the estimation methods, I am hanging out with has lot of pre-requisitie. These requisites are both theoretical and technical. So, I’m currently initially coding them as I go. This comes with a plus. These methods will be extremely valuable in many other analysis. ;)

Kalman Fiter

So, we started up with developing Kalman filter. Kalman filter is one of the crucial method for ARIMA model fit. It is primarily identified with constitution of 3 matrices -

  • T Matrix : It is the coefficient matrix for the state vector in the state equation.
  • R Matrix : It is the coefficient matrix for the state vector in the observation equation.
  • Z Matrix: It is the selctor matrix.

Currently, these methods are available as class methods of the new class - KalmanFilter in ARIMA. It can be found here

The example snippet of T matrix code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  def self.T(r, k, p)
    arr = Matrix.zero(r)
    params_padded = Statsample::Vector.new(Array.new(r, 0), :scale)

    params_padded[0...p] = params[k...(p+k)]
    intermediate_matrix = (r-1).times.map { Array.new(r, 0) }
    #appending an array filled with padded values in beginning
    intermediate_matrix[0,0] = [params_padded]

    #now generating column matrix for that:
    arr = Matrix.columns(intermediate_matrix)
    arr_00 = arr[0,0]

    #identify matrix substituition in matrix except row[0] and column[0]
    r.times do |i|
      arr[r,r] = 1
    end
    arr[0,0] = arr_00
    arr
  end

The complete coding of R matrix is still pending.

Cholesky Decomposition:

While venturing into another estimation method; I encoutered Cholesky decomposition of matrix; and it took me by surprise. Cholesky decomposition is the decomposition of a symmetric matrix in the product of lower half of Hermitian matrix and it’s conjugate.

I implemented the following as extension of Matrix here. Since the matrix has to be symmetric before it can be decomposed to Hermitian matrix, I also wrote down is_symmetric? method to check if the matrix is symmetric or not. Though symmetric? is present in Ruby Matrix 1.9+, to satisfy back compatibility with Ruby 1.8, it was necessary.

That’s pretty much for now.

Continuing the work.

Cheers,
- Ankur Goel