Skip to content
amjed-droidPublic

About

Official Python implementation of the Recursive Kurtosis-Aware Kalman Filter (RKAKF) for bypassing Structural Blindness in cyber-physical systems. Reproduces all figures and benchmarks.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Cubic-Decay Recursive Kurtosis-Aware Kalman Filter (RKAKF)

Python 3.9+ License: MIT Tests: Passing

Official Python implementation and reproduction suite for the paper:

A Cubic-Decay Recursive Kurtosis-Aware Kalman Filter for State Estimation under Structurally Masked Impulsive Disturbances
Ahmed Sattar Jabbar* and Haifa Taha Abd Ahmed
Department of Statistics, College of Administration and Economics, Mustansiriyah University, Baghdad, Iraq.


Theoretical Foundations

1. The Kurtosis Ratio Paradox

Recursive higher-order moment estimation in Kalman filtering has historically been hindered by an intrinsic transient instability. When estimating the fourth central moment $\mu_{4,k}$ and variance $\mu_{2,k}$ via symmetric Exponentially Weighted Moving Average (EWMA) updates with forgetting factor $\lambda \in (0, 1)$:

$$\mu_{2,k} = \lambda \mu_{2,k-1} + (1 - \lambda)\bar{\nu}_k^2$$ $$\mu_{4,k} = \lambda \mu_{4,k-1} + (1 - \lambda)\bar{\nu}_k^4$$

the recursive sample kurtosis ratio is:

$$\kappa_k = \frac{\mu_{4,k}}{\mu_{2,k}^2 + \epsilon}$$

Following an impulsive shock, the denominator variance dissipates at rate $\lambda^2$, while the numerator fourth moment dissipates at rate $\lambda$. During post-outlier recovery, the ratio behaves as:

$$\kappa_{k_0+t} \sim \frac{\lambda^t}{(\lambda^t)^2} \kappa_{k_0} = \lambda^{-t} \kappa_{k_0} \xrightarrow{t \to \infty} \infty$$

This creates a spurious exponential divergence (The Kurtosis Ratio Paradox), causing false alarms to explode long after the disturbance has ceased.

2. The Cubic Decay Principle ($\lambda^3$)

We analytically resolve this paradox by introducing a cubic forgetting factor schedule ($\lambda^3$) for the recursive fourth moment:

$$\mu_{4,k} = \lambda_{k-1}^3 \mu_{4,k-1} + (1 - \lambda_{k-1}^3)\bar{\nu}_k^4$$

Under this formulation, the homogeneous post-shock decay rate of the kurtosis ratio becomes:

$$\kappa_{k_0+t} \sim \frac{\lambda^{3t}}{(\lambda^t)^2} \kappa_{k_0} = \lambda^t \kappa_{k_0} \xrightarrow{t \to \infty} 0$$

Stability Bifurcation Analysis (Corollary 1)

For an arbitrary decay exponent $p \ge 1$ where $\mu_{4,k}$ decays as $\lambda^p$:

  • $p < 2$ (e.g., standard linear EWMA $p=1$): Negative damping $\lambda^{-(2-p)t} \to \infty$ (spurious divergence / instability).
  • $p = 2$: Zero damping $\lambda^0 = 1$ (permanent memory lock).
  • $p \ge 3$: Positive exponential damping $\lambda^{(p-2)t}$.
  • $p = 3$ is the minimal integer exponent that guarantees asymptotic post-shock stability while exactly harmonizing higher-order forgetting dynamics with first-order linear filter recovery ($\lambda^t$).

3. Structural Blindness in Cyber-Physical Systems

Standard Kalman filter diagnostic monitors rely on second-order statistics (e.g., Normalized Innovation Squared or moving-window variance). We mathematically prove (Proposition 1) that a Cauchy-Laplace-Gaussian (CLG) mixture with dynamic mixing weight $p_3(M) = C/M$ induces Structural Blindness:

$$\lim_{M \to \infty} \mathbb{E}[v_k^2] = p_1 \sigma^2 + 2 p_2 b^2 + \frac{2 C \gamma}{\pi} < \infty$$ $$\lim_{M \to \infty} \mathbb{E}[v_k^4] = \mathcal{O}(M^2) \to \infty \implies \lim_{M \to \infty} \kappa(v_k) = \infty$$

Because total innovation variance remains strictly bounded below energy thresholds, conventional second-order detectors fail to trigger, allowing stealth impulsive corruption to directly degrade state estimates.


Key Features of RKAKF

  1. Fourth-Order Anomaly Detection: Bypasses structural blindness with zero historical observation buffer overhead.
  2. Cubic Decay Principle: Guarantees post-shock stability and unbiased asymptotic moments $\mathbb{E}[\mu_4^*] = \mathbb{E}[\nu^4]$.
  3. Automated Gain Revocation: Inflates $R_k$ exponentially upon kurtosis breach, forcing $K_k \to 0$ and provably bounding single-step estimation errors (Theorem 1).
  4. Asymptotic Snap-back: Restores nominal Kalman Gain smoothly upon anomaly cessation without step discontinuities.
  5. $\mathcal{O}(d^3)$ Computational Complexity: Preserves the standard Kalman filter complexity with only $\mathcal{O}(1)$ scalar arithmetic overhead and a four-scalar state footprint.

Repository Structure

RKAKF/
├── rkakf/                          # Core Python Package
│   ├── __init__.py                 # Public package interface
│   ├── filters.py                  # RKAKF, Standard KF, Huber KF, VB Student-t, PF
│   ├── distributions.py            # CLG mixture, truncated Cauchy, Laplace samplers
│   └── metrics.py                  # RMSE, MAE, Peak Error, TTR, Wilcoxon test
├── scripts/                        # Extended Benchmarks & Reproduction Scripts
│   ├── multivariate_6d_drone_benchmark.py # 6D drone kinematics & nonlinear EKF tracking
│   └── reproduce_exact_figures.py  # Generates 300 DPI exact paper publication figures
├── tests/                          # Formal Mathematical Verification Tests
│   └── test_rkakf.py               # Unit tests validating Prop 1, Prop 2, Cor 1, Thm 1
├── figures/                        # Output directory for generated publication plots
├── run_experiments.py              # Modular CLI experiment runner
├── reproduce_all_experiments.py    # Complete monolithic reproduction suite (EXP 1-10)
├── requirements.txt                # Python package dependencies
├── pyproject.toml                  # Standard Python packaging (PEP 517/621)
├── LICENSE                         # MIT License
└── README.md                       # Repository documentation

Installation & Quick Start

Installation

Clone the repository and install dependencies:

git clone https://github.com/amjed-droid/RKAKF.git
cd RKAKF
pip install -r requirements.txt

Or install in editable mode:

pip install -e .

Python Quickstart

import numpy as np
from rkakf import RKAKF, generate_CLG

# 1. Instantiate RKAKF
filter = RKAKF(F=1.0, H=1.0, Q=0.01, R_nom=0.10, kappa_th=4.0)

# 2. Simulate streaming measurements with an impulsive outlier
measurements = [0.1, -0.05, 0.08, 250.0, 0.02, -0.04]  # outlier at k=3

for k, y_k in enumerate(measurements):
    x_est, kappa, R_k, K_k = filter.step(y_k)
    print(f"Step {k:d} | Meas: {y_k:6.2f} | Est: {x_est:5.3f} | Kurtosis: {kappa:6.2f} | Gain: {K_k:.4f}")

Reproducing Paper Experiments

Run the complete suite or specific experiments via the CLI runner or specialized benchmark scripts:

1. Run Modular Experiments (Full / Fast Mode)

# Fast mode (100 Monte Carlo runs - ~5 seconds)
python run_experiments.py --all --fast

# Full mode (1000 Monte Carlo runs)
python run_experiments.py --all

2. Run Specific Modular Experiments

# EXP 1: Structural Blindness Verification (Proposition 1)
python run_experiments.py --exp 1

# EXP 2: Localized Stealth Burst Resilience (Standard KF vs RKAKF)
python run_experiments.py --exp 2

# EXP 4: Operational Boundaries (Huber KF vs RKAKF under Continuous CLG Noise)
python run_experiments.py --exp 4

# EXP 5: Large-scale Monte Carlo Analysis (1000 Runs & Wilcoxon Hypothesis Test)
python run_experiments.py --exp 5

3. Monolithic Reproduction & Extended Benchmarks

# Run complete monolithic reproduction suite (EXP 1 to EXP 10 + 2D verification)
python reproduce_all_experiments.py

# Regenerate high-resolution exact paper publication figures (300 DPI)
python scripts/reproduce_exact_figures.py

# Run 6D multivariate drone telemetry and nonlinear EKF tracking benchmark
python scripts/multivariate_6d_drone_benchmark.py

All generated figures are saved at 300 DPI in the figures/ directory.


Summary of Experimental Benchmarks

Scenario Evaluated Metric Standard KF Huber-Robust KF Alternative / Baseline RKAKF (Proposed)
Proposition 1 Empirical Variance ($M \to \infty$) Diverges (if unconstrained) Diverges -- Strictly Bounded ($\le 0.495$)
Proposition 2 Post-Shock Recovery Diverges ($p=1$) Frozen ($p=2$) -- Exponential Decay ($p=3, \mathcal{O}(\lambda^t)$)
Stealth Burst In-Burst RMSE 1.2144 0.8120 0.5738 (Particle Filter, ESS=1) 0.5811 (52.1% reduction)
Continuous CLG Steady-State RMSE 1.6320 0.6102 Degenerates (Particle Filter) 0.7064 (56.7% reduction)
Peak Outlier Maximum Absolute Error 12.0048 1.7654 Degenerates (Particle Filter) 3.0247 (74.8% reduction)
Drone Telemetry Flight Altitude RMSE 0.3218 0.3231 (ripples) 0.4020 ($H_\infty$) 0.2558 (Smooth tracking)
Complexity Per-Step Scaling $\mathcal{O}(d^3)$ $\mathcal{O}(d^3)$ $\mathcal{O}(N d^2)$ $\mathcal{O}(d^3)$

Operational Boundary Note: As transparently documented in the paper, memoryless M-estimators (Huber KF) remain optimal for continuous, stationary i.i.d. noise due to the absence of memory accumulation. The proposed RKAKF is uniquely engineered for localized, stealthy cyber-physical bursts where variance-based detectors fail.


Unit Tests

Run the mathematical invariant unit test suite:

python -m unittest discover tests

Tests verify:

  1. test_proposition1_structural_blindness_bounded_variance: Bounded variance under growing $M$.
  2. test_proposition2_cubic_decay_resolves_kurtosis_ratio_paradox: Asymptotic dissipation vs linear divergence.
  3. test_theorem1_gain_revocation_bounds_outlier_error: Gain suppression and estimation error bounding.
  4. test_rkakf_nominal_performance_comparable_to_kf: Statistical optimality under pure Gaussian noise.

Citation

If you use RKAKF in your research or applications, please cite our paper:

@article{jabbar2026rkakf,
  title     = {A Cubic-Decay Recursive Kurtosis-Aware Kalman Filter for State Estimation under Structurally Masked Impulsive Disturbances},
  author    = {Jabbar, Ahmed Sattar and Abd Ahmed, Haifa Taha},
  year      = {2026},
  note      = {Preprint}
}

License

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

About

Official Python implementation of the Recursive Kurtosis-Aware Kalman Filter (RKAKF) for bypassing Structural Blindness in cyber-physical systems. Reproduces all figures and benchmarks.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages