Skip to content

Instantly share code, notes, and snippets.

@aztennenbaum
Last active May 27, 2022 04:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aztennenbaum/3a8be5c5c8b9d536ee756f10e53e777b to your computer and use it in GitHub Desktop.
Save aztennenbaum/3a8be5c5c8b9d536ee756f10e53e777b to your computer and use it in GitHub Desktop.
Baysian derivation of kalman filter
Theorems:
1. Linear transform of a normal random variable (matrix cookbook, 8.1.4):
Assume:
X ~ N(x,Px),
f(v) = A*v
Then:
f(X) ~ N(A*x,A*Px*A')
2. Conditional Distribution (matrix cookbook, 8.1.3):
[X;Y]~N([x0;y_expected],[Pxx,Pxy;Pxy';Pyy]);
p(x1|y_observed) ~ N(x1,Pxx_new))
K = Pxy*(Pyy)^-1
x1 = x0-K*(y_expected-y_observed)
Pxx_new = Pxx-K*(Pxy')
We have discrete time linear system:
[X1;Y0]=[A,B;C,D]*[X0;R]
Random variables:
Uncertainty: X0~N(x0,P0)
Noise: R~N(0,I)
Uncorrelated, so we can say:
[X0;R]~N([x0;0],[P0,0;0,I])]
Apply theorem 1:
f(v)=[A,B;C,D]*v
[X1;Y0]~f([X0;R])
[X1;Y0]~N([A,B;C,D]*[x0,0],[A,B;C,D]*[P0,0;0,I]*[A,B;C,D]');
[X1;Y0]~N([A*x0;C*x0],[A*P0*A'+B*B',A*P0*C'+B*D';
C*P0*A'+D*B',C*P0*C'+D*D']);
Apply theorem 2:
p(x1|y0) = N(x1,P1)
K = (A*P0*C'+B*D')*(C*P0*C'+D*D')^-1
x1 = A*x0 - K*(C*x0 - y0)
P1 = A*P0*A'+B*B - K*(C*P0*A'+D*B')
For seperate update and propagate:
Update:
A=I
B=0
K = (P0*C')*(C*P0*C'+D*D')^-1
P(x1|y0) ~ N(x0 - K*(C*x0 - y0), P0 - K*(C*P0))
Propagate:
P(x1|x0) ~ N(A*x0, A*P0*A'+B*B')
References:
Matrix cookbook - https://www.math.uwaterloo.ca/~hwolkowi/matrixcookbook.pdf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment