Skip to content

Instantly share code, notes, and snippets.

@mrocklin
Created September 11, 2012 17:45
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mrocklin/3700186 to your computer and use it in GitHub Desktop.
Save mrocklin/3700186 to your computer and use it in GitHub Desktop.
The Kalman filter represented in Theano syntax
import theano
import theano.sandbox.linalg as linalg
mu = theano.tensor.matrix('mu')
Sigma = theano.tensor.matrix('Sigma')
H = theano.tensor.matrix('H')
R = theano.tensor.matrix('R')
data = theano.tensor.matrix('data')
dot = theano.tensor.dot
A = dot(Sigma, H.T)
B = R + dot(H, dot(Sigma, H.T))
new_mu = mu + dot(A, linalg.solve(B, dot(H, mu) - data))
new_mu.name = "updated_mu"
new_Sigma = Sigma - dot(dot(A, linalg.solve(B, H)), Sigma)
new_Sigma.name = "updated_Sigma"
inputs = [mu, Sigma, H, R, data]
outputs = [new_mu, new_Sigma]
n = 2000
input_shapes = {mu: (n, 1),
Sigma: (n, n),
H: (n, n),
R: (n, n),
data: (n, 1)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment