Skip to content

Commit

Permalink
First stage of EM estimation implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Gord Stephen committed Oct 29, 2015
1 parent 5c7a692 commit ab55ec8
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 122 deletions.
20 changes: 20 additions & 0 deletions src/kalman_smooth.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,26 @@ function kalman_smooth(y::Array, model::StateSpaceModel; u::Array=zeros(size(y,1

end #smooth

# Bad performance - will be much better with sparse matrices
function lag1_smooth(y::Array, u::Array, m::StateSpaceModel)

A_stack(t) = [m.A(t) zeros(m.nx, m.nx); eye(m.nx) zeros(m.nx, m.nx)]
B_stack(t) = [m.B(t); zeros(m.nx, m.nu)]
V_stack(t) = [m.V(t) zeros(m.nx, m.nx); zeros(m.nx, 2*m.nx)]
C_stack(t) = [m.C(t) zeros(m.ny, m.nx)]
x1_stack = [m.x1; zeros(model.x1)]
P1_stack = [m.P1 zeros(m.nx, m.nx); zeros(m.nx, 2*m.nx)]
stack_model = StateSpaceModel(A_stack, B_stack, V_stack,
C_stack, model.D, model.W, x1_stack, V1_stack)

stack_smoothed = smooth(y, stack_model, u=u)
x = stack_smoothed.x[:, 1:model.nx]
V = stack_smoothed.V[1:model.nx, 1:model.nx, :]
Vlag1 = stack_smoothed.V[1:model.nx, (model.nx+1):end]
return x, V, Vlag1, stack_smoothed.loglik

end #function


# Rauch-Tung-Striebel Smoothing
function kalman_smooth(filt::KalmanFiltered)
Expand Down
Loading

0 comments on commit ab55ec8

Please sign in to comment.