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

# PrioritizedReplay

## PrioritizedReplay

Code: [slm\_lab/agent/memory/prioritized.py](https://github.com/kengz/SLM-Lab/blob/master/slm_lab/agent/memory/prioritized.py)

[Prioritized Experience Replay (PER)](https://arxiv.org/pdf/1511.05952.pdf) extends from Replay by calculating prioritization for sampling experiences based on errors in Q-values estimation.

Suitable for off-policy algorithms.

### Source Documentation

Refer to the class documentation and example memory spec from the source: [slm\_lab/agent/memory/prioritized.py#L87-L104](https://github.com/kengz/SLM-Lab/blob/master/slm_lab/agent/memory/prioritized.py#L87-L104)

### **Example Memory Spec**

This specification creates a PrioritizedReplay (off-policy) memory with a maximum capacity of 10,000 elements, with a batch size of 32, and CER is disabled. The `alpha` and `epsilon` parameters are specific to PER in computing the errors.

```javascript
{
    ...
    "agent": [{
      "memory": {
        "name": "PrioritizedReplay",
        "alpha": 0.6,
        "epsilon": 0.001,
        "batch_size": 32,
        "max_size": 10000,
        "use_cer": false
      }
    }],
    ...
}
```

For more concrete examples of memory spec specific to algorithms, refer to the existing [spec files](https://github.com/kengz/SLM-Lab/tree/master/slm_lab/spec).


---

# 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, and the optional `goal` query parameter:

```
GET https://slm-lab.gitbook.io/slm-lab/master/development/memory/prioritizedreplay.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
