Metadata-Version: 2.4
Name: kalmanformer
Version: 0.0.3
Summary: KalmanFormer - using transformer to model the Kalman Gain in Kalman Filters
Project-URL: Homepage, https://pypi.org/project/kalmanformer/
Project-URL: Repository, https://codeberg.org/lucidrains/kalmanformer
Author-email: Phil Wang <lucidrains@gmail.com>
License: MIT License
        
        Copyright (c) 2026 Phil Wang
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: artificial intelligence,deep learning,kalman filter,state estimation,transformers
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3.10
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.10
Requires-Dist: einops>=0.8.0
Requires-Dist: torch>=2.0
Requires-Dist: x-mlps-pytorch>=0.2.8
Requires-Dist: x-transformers>=2.19.7
Provides-Extra: examples
Provides-Extra: test
Requires-Dist: pytest; extra == 'test'
Description-Content-Type: text/markdown

<img src="./kalmanformer.png" width="400px"></img>

## KalmanFormer

Implementation of <a href="https://www.frontiersin.org/articles/10.3389/fnbot.2024.1460255/full">KalmanFormer</a>.

The paper proposes learning the Kalman Gain directly from data using Transformers, bypassing the limitations of traditional Kalman Filters on non-linear systems.

## Install

```bash
$ pip install kalmanformer
```

## Usage

```python
import torch
from kalmanformer import KalmanFormer

# kalmanformer

kalmanformer = KalmanFormer(
    state_dim = 3,
    obs_dim = 3,
    dim = 64,
    depth = 2,
    heads = 2,
    dim_head = 32,
    mlp_dim = 64
)

# mock observations

observations = torch.randn(2, 10, 3)

# state transition matrix f and observation matrix h

F = torch.randn(3, 3)
H = torch.randn(3, 3)

# initial state

x_0 = torch.zeros(2, 3)

# tracking over sequence

post_states = kalmanformer(
    observations,
    F,
    H,
    x_0 = x_0
)

assert post_states.shape == (2, 10, 3)
```

## Citations

```bibtex
@article{Shen2025KalmanFormer,
    title   = {KalmanFormer: using transformer to model the Kalman Gain in Kalman Filters},
    author  = {Siyuan Shen and Jichen Chen and Guanfeng Yu and Zhengjun Zhai and Pujie Han},
    journal = {Frontiers in Neurorobotics},
    year    = {2025},
    volume  = {18},
    doi     = {10.3389/fnbot.2024.1460255}
}
```
