Skip to main content

KKKF: a library for Python implementation of Kernel-Koopman-Kalman Filter.

Project description

KKKF - Kernel Koopman Kalman Filter

KKKF is a Python library that implements kernel Extended Dynamic Mode Decomposition (EDMD) of Koopman operators and provides a non-linear variant of the Kalman Filter. This library is particularly useful for state estimation in dynamical systems with non-linear behavior.

Installation

You can install KKKF using pip:

pip install KKKF

Features

  • Kernel-based Extended Dynamic Mode Decomposition (EDMD)
  • Non-linear Kalman Filter implementation
  • Support for additive dynamical systems
  • Integration with various kernel functions (e.g., Matérn kernel)
  • Robust state estimation with noise handling

Dependencies

  • NumPy
  • SciPy
  • scikit-learn (for kernel functions)

Quick Start

Here's a simple example of using KKKF to estimate states in a SIR (Susceptible-Infected-Recovered) model:

import numpy as np
from scipy import stats
from sklearn.gaussian_process.kernels import Matern
from KKKF import AdditiveDynamicalSystem, Koopman, KoopmanKalmanFilter

# Define system parameters
beta, gamma = 0.12, 0.04

# Define system dynamics
def f(x):
    return x + np.array([-beta*x[0]*x[1], beta*x[0]*x[1] - gamma*x[1], gamma*x[1]])

def g(x):
    return np.array([x[1]])

# Setup system dimensions and kernel
N = 300
nx, ny = 3, 1
k = Matern(length_scale=N**(-1/nx), nu=0.5)

# Setup distributions
X_dist = stats.dirichlet(alpha=1*np.ones(nx))
dyn_dist = stats.multivariate_normal(mean=np.zeros(3), cov=1e-5*np.eye(3))
obs_dist = stats.multivariate_normal(mean=np.zeros(1), cov=1e-3*np.eye(1))

# Create dynamical system
dyn = AdditiveDynamicalSystem(nx, ny, f, g, X_dist, dyn_dist, obs_dist)

# Initialize Koopman operator and Kalman filter
x0_prior = np.array([0.8, 0.15, 0.05])
d0 = stats.multivariate_normal(mean=x0_prior, cov=0.1*np.eye(3))

Koop = Koopman(k, dyn)
sol = KoopmanKalmanFilter(Koop, y, d0, N, noise_samples=100)

API Reference

AdditiveDynamicalSystem

AdditiveDynamicalSystem(nx, ny, f, g, X_dist, dyn_dist, obs_dist)

Creates an additive dynamical system with:

  • nx: State dimension
  • ny: Observation dimension
  • f: State transition function
  • g: Observation function
  • X_dist: State distribution
  • dyn_dist: Dynamic noise distribution
  • obs_dist: Observation noise distribution

Koopman

Koopman(kernel, dynamical_system)

Initializes a Koopman operator with:

  • kernel: Kernel function (e.g., Matérn kernel)
  • dynamical_system: Instance of AdditiveDynamicalSystem

KoopmanKalmanFilter

KoopmanKalmanFilter(koopman, observations, initial_distribution, N, noise_samples=100)

Implements the Koopman-based Kalman filter with:

  • koopman: Koopman operator instance
  • observations: Observation data
  • initial_distribution: Initial state distribution
  • N: Number of samples
  • noise_samples: Number of noise samples for uncertainty estimation

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Citation

If you use this library in your research, please cite:

@software{kkkf,
  title = {KKKF: Kernel Koopman Kalman Filter},
  year = {2024},
  author = {[Author Name]},
  url = {https://github.com/[username]/KKKF}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kkkf-0.1.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

KKKF-0.1-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

File details

Details for the file kkkf-0.1.tar.gz.

File metadata

  • Download URL: kkkf-0.1.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.3

File hashes

Hashes for kkkf-0.1.tar.gz
Algorithm Hash digest
SHA256 392e39c8331e17640ee9e81f1d76be8f8937a26957a8c7c15627a4d014c47c6d
MD5 e4e07f55f9082943e9b6a9aba08f48bc
BLAKE2b-256 2a0b8a94779511afdc561e765225c63b522accf9a91fa4c02add91c7e1f28dc8

See more details on using hashes here.

File details

Details for the file KKKF-0.1-py3-none-any.whl.

File metadata

  • Download URL: KKKF-0.1-py3-none-any.whl
  • Upload date:
  • Size: 11.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.3

File hashes

Hashes for KKKF-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9541c85a635a84df4470bc50f9c2ca8759c33a16429b26761fb9d4296299ca07
MD5 9d9fd2b5e8e73410eb2ca55de4f95c1c
BLAKE2b-256 95f86874bde64f226f98e3f4a47a282dfaab81a4793371394b14a7dc42da98f7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page