Implementing the Kalman Filter in Python

Hello. Im trying to experiment with some recent articles that tries to connect transformers and kalman filter. I remember that I saw in my undergrad this concept on the control lecture but to be honest I didnt quite understand the concept at the time. To help my understanding i tried to implement using only some basic python libraries the Kalman Filter in python.

Before the notebook with the implementation here is a quick summary of what is this filter provided by GPT ( =P ):

A Kalman filter is a powerful algorithm used for making estimates or predictions in systems that are subject to various uncertainties. Its widely used in fields like robotics, aerospace, finance, and even weather forecasting. Heres a simplified explanation suitable for a blog post:

The beauty of the Kalman filter lies in its ability to deal with uncertainty. Its designed to weigh both the predicted state and the new measurements, considering the uncertainties in both. If the measurements are very accurate, it gives them more weight. If the predictions are believed to be more reliable, it leans more on them.

Finally here is the notebook : Colab