AI research
The Purpose of Memory
What controlled simulations reveal about hidden context, selective memory, exploration and change.
Elementary Intelligence · Controlled simulation study

In this article8 sections
One measurable purpose of memory is to predict consequences that the present moment cannot reveal. In the adaptive decisions studied here, memory does more than record the past: it helps an agent act when useful information is no longer in front of it.
That sounds obvious, but it has sharp implications for this task. It tells you when remembering history adds nothing to a decision, what an agent should keep, how much it needs, and why forgetting is as important as remembering. This article sets out those implications in plain terms, with the mathematics alongside. It draws on controlled experiments in a deliberately simple world, run as part of a project aiming at a general theory of intelligence.
In that world, a creature sees objects one at a time and decides whether to take or skip each one. Taking a good object scores a point; taking a bad one loses a point. Which objects are good depends on the creature’s goal and on a “season” that is sometimes visible and sometimes hidden. We built creatures with no memory, with a one-line notebook, with a memory they shape themselves, and with a full mental model, then measured what each one gained from what it remembered.
When memory is useless
If the present observation already tells an agent everything it needs to choose well, remembering history adds nothing to that decision. Write o for what the creature observes now, h for its whole history, a for an available action, g for its goal, and Y for the outcome it cares about. A sufficient condition is that, for every action and goal,
The past then adds no information about the consequences of any choice. The best possible action can be selected from the current observation.
That is exactly what we found when the season was visible. The creature with no memory at all learned to perform perfectly, with regret per object of 0.000 to 0.008. The creatures with memory did no better. In the main study, giving the notebook creature more space even made it very slightly worse (regret rising from 0.000 to 0.010), because there were more things to learn and nothing extra to gain.
The lesson: memory is not a general-purpose improvement. It is a specific answer to a specific problem.
When memory becomes necessary
Memory earns its place when something hidden and persistent changes which action is best. Hidden, so the present cannot show it. Persistent, so the past still says something about it. In our world, that something is the season: invisible, but stable for a while, so recent outcomes reveal it.
Formally, two histories with the same current observation can require different actions:
In that case a creature cannot always choose optimally from the present observation alone. Its internal state Z must retain enough history to distinguish the action-relevant contexts:
I is mutual information, measured in bits: how much knowing Z reduces uncertainty about C, given the goal G. A yes-or-no context like the season holds at most 1 bit.
The experiments showed the switch from useless to necessary sharply. With the season hidden, the memoryless creature fell to chance: regret 0.45 to 0.49 per object, no better than a coin. Every creature with memory did better. A learned memory reached about 0.10, and a mental model 0.02 to 0.03. The advantage of memory appeared in all 12 hidden-versus-visible comparisons we registered in advance, and grew with the amount of memory available.
Measured directly, the memoryless creature’s internal state held 0 bits about the hidden season, and the creatures with memory held 0.6 to 0.97 bits. Memory, in this precise sense, is what puts the hidden world inside the mind.
What memory should keep
A good memory is not a complete one. It keeps the parts of the past that change what will happen next, and merges the rest. Two histories h and h′ are worth telling apart only if some course of action π would make them turn out differently:
D measures how different two predictions are, and ε is the tolerance below which a difference is not worth keeping. An ideal memory would give similar internal states to histories with similar consequences, while keeping apart histories whose differences change the best action. With a nonzero tolerance ε, “similar” is an approximation rather than a strict equivalence relation.
In everyday terms: remember that the milk smelled sour, forget what colour the carton was.
Three experiments tested this directly.
- What a mind holds. We measured how many bits each creature’s internal state held about the features that never matter. The compressed creature, at its tightest budget, held none at all, while still holding what it needed about outcomes.
- What a mind uses. We performed the equivalent of surgery, forcing trained creatures to treat two objects as one. Merging objects that behave the same cost nothing. Merging objects that behave differently cost the mental-model creatures 0.24 to 0.30 reward per object.
- What a mind is fooled by. We let a meaningless mark happen to predict good objects during training, then removed the coincidence. The creatures that compress, or that shape their own memory, lost almost nothing (extra regret 0.004 and 0.000). Those that stored the coincidence lost 0.07 to 0.10.
One subtlety. Holding information about something is not the same as being misled by it. The self-shaping memory still held some information about the meaningless mark, yet it did not act on it. What matters is what reaches the decision.
How much memory is enough
The amount of memory a mind needs depends less on how much happens than on how many different consequences the past can imply. If histories fall into k groups that matter, as in the equation above, the smallest memory that can tell them apart holds
In our world, everything a creature needs to know about the past is which season it is in. That gives k = 2 and B_min = 1 bit.
The notebook creature shows what happens when memory stores raw events instead of their meaning. It wrote down the last thing that happened: which of 32 objects it took and whether it gained or lost, about 64 possible entries. To keep every entry distinct needs about log₂ 64 = 6 bits. With less room, different entries had to share a slot, and the creature confused situations with opposite consequences. Its regret right after a hidden change was 0.35 with 2 bits and 0.33 with 4 bits, close to chance. With 8 bits it fell to 0.14. In the pilot, its memory only started to help at 5 bits or more.
The self-shaping memory needed none of that headroom. With a small network of 16 units it reached a regret of about 0.10, because it learned to store the season rather than the events. Memory is cheap when it stores conclusions and expensive when it stores evidence.
Forgetting is part of memory
If memory exists to predict consequences, it must let go of the past once the past stops predicting. A world that changes makes old experience misleading. The question is how quickly to forget.
Picture a mind that keeps a running estimate Q of whether an object is worth taking, and gives old experience less weight over a memory span of τ encounters:
Here r is the outcome it just received. A short τ forgets fast; a long τ holds on.
Our first guess at the best τ was wrong, and the way it was wrong is the most useful part. It assumed the mind keeps learning about every object. But a mind learns about an object only when it chooses it. Once a few unlucky outcomes have taught it to skip something, it gets no more evidence about that thing, except from the occasional random try it makes with probability ε. Decision researchers call this the hot stove effect: a cat that once sat on a hot stove avoids even cold stoves, and so never learns they are safe. The mind’s chance of taking an object becomes
In a revised model, the evidence a mind gathers depends on what it chooses, and the model has no adjustable constants. We wrote its predictions down and fingerprinted them before 3,648 new trials. It predicted the simple learner’s regret to within 0.009 per object on average, and ranked the memory and exploration settings correctly in all 12 conditions. Three lessons followed.
- Forgetting fast is dangerous when you stop looking. A short memory turns one bad outcome into a long avoidance, because nothing corrects it.
- How much to explore depends on how the world changes. When each change is new, explore a lot (ε = 0.2 was best in every such condition). When the world switches quickly back and forth between the same two states, explore little (0.02 to 0.05); when those switches are slow, exploring more pays again.
- Memory and curiosity are one system. The right memory span cannot be chosen without the right amount of exploration, and the reverse. Forgetting decides what you might be wrong about; exploring decides whether you ever find out.
Remembering rules that come back
There is a second way to handle change: instead of forgetting the old rule, keep it, and work out which rule is currently in force. A mind that does this holds several possible worlds z in mind and updates its belief b about which one it is in, after each outcome r:
This turns change into context: the switch becomes something to infer, not something to relearn. Our mental-model creature works this way, with room for two possible worlds.
It is a powerful strategy, and a double-edged one.
- It pays when a few rules come back quickly and clearly. When the world flipped fast between the same two rules and outcomes were fairly reliable, the mental-model creature beat the best setting of the forgetting-and-relearning model by 0.07 to 0.11 reward per object.
- It barely helps when outcomes are noisy. With noisier outcomes, the two worlds are hard to tell apart, and the advantage shrank to about zero.
- It hurts when change is open-ended. When every change led to a new rule, the creature kept expecting an old one to return, and did worse than a simple forgetting strategy in all 6 conditions tested.
The same double edge shows up in plain experience. After the hidden season flipped, creatures with past training adapted 5 to 10 times better than newcomers: the old knowledge was still right, just mirrored. But when we secretly swapped what the features meant, every trained creature did worse than a newcomer. What it remembered now pointed the wrong way.
We registered a prediction that the mental-model creature would beat the forgetting strategy whenever rules recur. It held in only 2 of 6 conditions, so that prediction failed as stated. The corrected picture is narrower and more interesting: a memory of past rules is worth keeping when the future is likely to repeat the past, and is a burden when it is not.
What this does not show yet
- It is one small world. Sixteen objects, one hidden bit, two goals. The principles here may change form in worlds with richer histories, longer delays, or many hidden factors at once.
- Some results are pilots. The findings on memory being necessary only under hidden context, and on the costs of merging distinctions, come from a study registered in advance with 30 to 50 repeats per condition. The findings on forgetting, exploration and remembered rules come from pilot runs with 4 to 5 repeats each, and still need a full-scale test.
- Every mind ran on one computer. Whether brains, bodies or other materials follow the same rules is untested. Human and animal experiments are the next step for that question.
- Memory here serves one purpose. In living creatures, memory also builds identity, carries culture, and supports imagination and planning far into the future. This work isolates one function, prediction for action, because it can be measured exactly. It does not claim that this is all memory is for.
The purpose of memory, stated precisely
Putting the pieces together gives a compact statement, offered as a working hypothesis rather than a proven law. A memory is a way f of compressing a history h into an internal state Z = f(h). Its purpose is to keep as much as possible about future consequences Y, given the goal G, while spending as little as possible on everything else:
The first term rewards remembering what predicts outcomes. The second charges for everything remembered, with β setting the price. This is the information bottleneck of Tishby, Pereira and Bialek (1999), applied across time. What the experiments add is a test of when it holds, and the finding that what a mind chooses to do decides what it gets to remember. Each finding above follows from this one trade-off.
- When the present shows everything, the past adds nothing to the first term, so the best memory is empty.
- When something important is hidden but persistent, the past does add to the first term, and memory becomes necessary.
- The best memory merges histories with the same consequences, because keeping them apart costs without predicting anything.
- Storing conclusions is cheaper than storing evidence, which is why a memory of the season beats a notebook of events.
- When the world changes, old history stops predicting, so forgetting is part of the same optimisation. Because a mind sees only what it chooses, forgetting and exploring have to be tuned together.
- Remembering old rules pays only when the future is likely to repeat the past.
In one sentence: memory is the part of a mind that carries the hidden world forward in time, kept only as far as it changes what happens next.