cd /news/machine-learning/a-kalman-filter-is-a-memory-system · home topics machine-learning article
[ARTICLE · art-54762] src=dev.to ↗ pub= topic=machine-learning verified=true sentiment=· neutral

A Kalman Filter Is a Memory System

A developer demonstrates that the Kalman filter, a sixty-year-old control theory algorithm, functions as a memory system by continuously blending prior beliefs with new noisy observations. The filter's Kalman gain dynamically adjusts how much past information to retain versus how much to trust new data, making it applicable to signal processing, LLM engineering, and computer vision. The post provides a 1D Python implementation tracking bearing wear from a noisy sensor.

read8 min views1 publishedJul 10, 2026

Three problems that look unrelated:

These are usually filed under three different fields: signal processing, LLM engineering, and computer vision. But they are the same problem. All three come down to one question:

Given everything I've seen so far, and one new noisy observation, what do I now believe, and how much of my history do I keep versus throw away?

That question has a sixty-year-old answer that most people learn as control theory and never think about again: the Kalman filter. I want to show you that it isn't really a control-theory tool. It's the cleanest, oldest instance we have of a memory system. And once you see it that way, the connection to agent memory and video models stops being a metaphor and becomes the same math wearing different clothes.

No prior knowledge of Kalman filters or agent memory assumed. We'll build both from scratch.

Start with the bearing. There's a hidden quantity you actually care about. Call it the wear, a number from 0 (brand new) to 1 (failed). You can't measure wear directly. You can only measure a proxy: vibration, current draw, temperature. Those readings correlate with wear, but they're noisy. Any single reading might be high just because the sensor twitched.

So you have two sources of information, and both are unreliable:

Naively, you could just trust the sensor and plot the raw readings. But that throws away everything you knew a moment ago. Or you could trust your model and ignore the sensor, but then you're not learning from reality at all.

The Kalman filter is the principled way to blend the two, weighting each by how much you trust it. And that weight is the whole story.

A Kalman filter holds two things:

x

: its current best belief about the hidden state (the wear).P

: its Every time step, it does two moves.

Predict. Carry the belief forward using the model of the dynamics. If wear persists, x

stays roughly where it was. But uncertainty grows, because time passed and things could have drifted:

x = F * x          # carry the state forward
P = F * P * F + Q  # uncertainty grows by process noise Q

Update. A new measurement z

arrives. Fold it in, but only partly, weighted by a factor K

called the Kalman gain:

K = P / (P + R)        # how much to trust the measurement vs. your belief
x = x + K * (z - x)    # nudge belief toward the measurement, scaled by K
P = (1 - K) * P        # uncertainty shrinks, you just learned something

Look closely at K

, because K

is a memory knob.

R

is the measurement noise, i.e. how unreliable the sensor is.P

is your current uncertainty.If your belief is very uncertain (P

large) relative to the sensor noise, K

approaches 1: trust the new measurement, discard your prior. If your belief is confident (P

small) and the sensor is noisy (R

large), K

approaches 0: keep your history, ignore the twitchy reading.

That's it. That's the entire mechanism. K

is a continuously-adjusted answer to "how much of the past do I carry forward, and how much of this new observation do I let overwrite it?"

Here's a complete 1D filter tracking bearing wear from a noisy sensor. It runs as-is:

import numpy as np

np.random.seed(1)
T = 60
true_wear = np.clip(np.linspace(0.05, 0.85, T), 0, 1)
measurements = true_wear + np.random.normal(0, 0.08, T)

x, P = 0.0, 1.0     # belief, and uncertainty in it
Q = 2e-3            # process noise: how much wear can drift per step
R = 0.08**2         # measurement noise: how noisy the sensor is
F = 1.0             # dynamics: wear persists

estimates, gains = [], []
for z in measurements:
    x = F * x
    P = F * P * F + Q
    K = P / (P + R)            # the memory knob
    x = x + K * (z - x)
    P = (1 - K) * P
    estimates.append(x)
    gains.append(K)

gains = np.array(gains)
print("gain, first 3 steps:", np.round(gains[:3], 3))   # -> [0.994 0.566 0.468]
print("gain, steady state :", round(gains[-1], 3))       # -> 0.424

The interesting output isn't the wear estimate. It's the gain trajectory: 0.994 → 0.566 → 0.468 → ... → 0.424

.

On the very first step, the filter knows nothing (P

is huge), so K ≈ 0.99

: it essentially adopts the first measurement wholesale. It has no memory yet, so it trusts the sensor completely. Then, step by step, as it accumulates history, P

shrinks and the gain settles toward 0.42

. At steady state it says: blend about 42% of each new reading with 58% of what I already believed.

That settling curve is the memory forming. A system with no history trusts the present entirely. A system with accumulated belief holds its ground and treats new data as a partial correction. The filter cuts the tracking error roughly in half versus the raw sensor, not by having a better sensor, but by remembering.

Now the payoff. Hold that structure in your head (a belief carried forward, a new observation folded in, a gain deciding the mix) and look at the other two problems.

An AI agent in a long conversation is running the same loop, informally. Its "state" is its working understanding of you: your goals, your preferences, the facts you've established. Each new message is a noisy measurement, noisy because a single message can be sarcastic, a typo, a one-off, or a genuine lasting signal.

A naive agent that just embeds every message and retrieves by similarity has no gain. It treats every observation as equally weighted, forever. That's why it surfaces a preference you abandoned months ago, or lets one stray message overwrite a stable fact. It has storage, not memory.

A real memory system needs the equivalent of K

: a judgment about how much each new message should update the persistent picture versus how much accumulated history to preserve. Promote the durable, down-weight the transient, and, crucially, let uncertainty decay so old, unconfirmed beliefs loosen their grip. That's a Kalman gain in disguise.

A video model watching that ball roll behind a wall has a hidden state too: what objects exist in this scene and where. Each frame is a measurement. When the ball is occluded, there's no measurement for it, and this is exactly the predict step with no update. A model with real state carries the ball forward through the occlusion (x = F * x

), holds its position with growing uncertainty (P

grows), and re-acquires it when it reappears.

A model without persistent state does the opposite: with no measurement, the ball ceases to exist, and when it reappears the model hallucinates a fresh object or invents a physics story to explain the "teleport." That failure mode is well documented in current video LLMs. It's not a perception failure. It's a missing predict step, no memory to carry the object through the moment it couldn't be seen.

Object-centric architectures (slot attention) and state-space models (Mamba and kin) are, in effect, learned generalizations of this same predict/update loop, one keeping a slot per object, the other keeping a compressed running state, both deciding per-step what to write and what to ignore. Mamba's "selective" update, where the model learns what to fold into state and what to skip, is the Kalman gain grown up and made learnable.

If I stopped here I'd be overselling it, so here's where the equivalence is real and where it's a useful loose metaphor.

Real: the structure is genuinely shared. Predict-then-update, a persistent belief with quantified uncertainty, and a gain that trades history against observation. That recurrence shows up in all three, and it's not a coincidence. It's what optimal recursive estimation looks like.

Loose: the classic Kalman filter assumes linear dynamics and Gaussian noise. Bearing wear is roughly fine with that. Conversations and video are not. The state is high-dimensional, the dynamics are nonlinear, the noise isn't Gaussian. LLMs and video models do not literally compute a Kalman gain. They learn something functionally analogous through attention and gating, which is far more expressive and far less interpretable. The extended and unscented Kalman filters stretch the math toward nonlinearity, but nobody's running a literal EKF inside a transformer.

So the claim isn't "these systems are Kalman filters." The claim is that the Kalman filter is the simplest, most transparent member of a family, and studying it teaches you the question every member of that family must answer. When you understand why the gain settles, you understand what agent memory and video permanence are reaching for, and why "just store everything and retrieve by similarity" was never going to be memory.

Memory is not storage. Storage is keeping everything. Memory is judgment about what to keep: carrying a belief forward, weighing each new observation against it, and letting uncertainty decide the mix.

The Kalman filter is the oldest clean instance of that judgment we have. It's sixty years old, it's twenty lines of Python, and it's quietly the same thing the newest agent-memory stacks and video world-models are trying to relearn at scale.

If you build agents, the filter is worth an afternoon. Not because you'll implement one (you won't) but because it makes one question concrete and unforgettable: for every new thing your system sees, what is it keeping, and what is it letting go?

If you found this useful, the same lens (hidden state, noisy observation, what to carry forward) is how I think about predictive maintenance on industrial machinery, where the "hidden state" is a machine's health and the "measurement" is its power signature. Different domain, identical question.

── more in #machine-learning 4 stories · sorted by recency
── more on @kalman filter 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/a-kalman-filter-is-a…] indexed:0 read:8min 2026-07-10 ·