> For the complete documentation index, see [llms.txt](https://hypergan.gitbook.io/hypergan/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hypergan.gitbook.io/hypergan/components/trainhook/rolling-memory.md).

# Rolling Memory

Rolling memory is a type of experience replay. Each training step, a memory is replaced with the top scoring batch item.

Each `types` pairing becomes a discriminator that is added to the loss.

## examples

```javascript
{
    "class": "function:hypergan.train_hooks.experimental.rolling_memory_2_train_hook.RollingMemoryTrainHook",
    "types": ["mx-/g(mz-)"]
}
```

mx- is a memory of x that gets updated each training step. g(mz-) is a memory of z that gets run through a generator and updated each trainng step.

A discriminator `d(mx-, g(mz-))` is created and added to the gan loss.

## options

| attribute |                             description                            |       type       |
| :-------: | :----------------------------------------------------------------: | :--------------: |
|   types   | What memories and how they are paired.  See **memory types** below | array of strings |
|   top\_k  |    How many memory items to replace per frame.  Defaults to `1`    |      integer     |
|    only   |  Overrides all other losses when this is set. Defaults to `false`  |      boolean     |

### memory types

| memory | description                                        |
| ------ | -------------------------------------------------- |
| mx-    | x reverse sorted by d\_real                        |
| mx+    | x sorted by d\_real                                |
| mg-    | memory of g reverse sorted by d\_fake              |
| mg+    | memory of g sorted by d\_fake                      |
| g(mz-) | generator of memory of z reverse sorted by d\_fake |
| g(mz+) | generator of memory of z sorted by d\_fake         |
| x      | gan.inputs.x                                       |
| g      | gan.generator.sample                               |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hypergan.gitbook.io/hypergan/components/trainhook/rolling-memory.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
