SandHouse
Pages and contents

CL1 — M

The M space is designed to compress episodic memories to enhance sample efficiency as well as provide efficient improvement of the Γ space that is to be introduced next chapter.

Experience

We can introduce a variable that describes a latent episode of experience, ξ. This variable is a sequence of events, which can be encoded or decoded by the M space.

ξt,h=(Z,A,r)t:t+h

Rather than storing arbitrary fixed windows of experience, M stores episodes around meaningful anchor events. An anchor a marks a timestep where something potentially important has occurred and a memory should begin forming. Define an anchor variable

at∈0,1.

For the initial model, an anchor can be triggered by reward, surprise, or a periodic fallback:

at=𝟏[|rt|>δr]∨𝟏[∥Zt−Zt|t−1−∥>δZ]∨𝟏[t−tlast anchor>hfallback]

When at=1 , we open a pending episodic memory around timestep t . The resulting experience is split into a context preceding the anchor and an outcome following it:

ξt=pt‖ft,pt=(Z,A,r)t−hp:t,ft=(Z,A,r)t+1:t+hf

The context pt describes the state of the agent when the event occurred, while the outcome ft records what actions followed and what consequences resulted. The outcome can initially use a fixed maximum horizon hf , but may terminate earlier at another significant event or episode boundary. Once the continuation is complete, the full episode is encoded and written to memory:

mt=EM(ξt)∈M.

This gives M an event-centered structure:

context→anchor event→outcome,

which later allows the agent to retrieve situations similar to its current context and use their historical continuations as candidate plans.

Memory Read

We want to define a learned projection from m to an attention-like retrieval space where K and Q are MLPs.

k_i = \mathrm{norm}(K_M(p_i)) \\ q_t = \mathrm{norm}(Q_M(H_t, Z_t))

Then we use cosine similarity to read relevant historical trajectories.

si=qt⊤ki

Finally our read function

ℛt=DM(TopK(si))

Learning M

The memory encoder and decoder are trained as an autoencoder over recent experience windows.

mi=EM(ξi),ξ^i=DM(mi)

We minimize a reconstruction loss over the components of ξ=(Z,A,r):

λZℒZ+λAℒA+λrℒr

where gradients through the target Z representations can be stopped so that learning M does not distort the perceptual space.

The retrieval networks KM and QM are not trained by reconstruction. Instead, they learn through the downstream usefulness of retrieved memories. During training, we use differentiable retrieval

αi=exp⁡(si/τ)∑jexp⁡(sj/τ)

and pass the weighted retrieved memories into GΓ. The resulting Γ loss propagates through the retrieval weights and therefore into KM and QM:

ℒΓ→αi→si→KM,QM

Thus EM,DM learn how to store experience while KM,QM learn which memories are useful to retrieve for forming reusable concepts.