Skip to main content

A simple replay buffer implementation in python for sampling n-step trajectories

Project description

ReplayTables

Benchmarks

Getting started

Installation:

pip install ReplayTables-andnp

Basic usage:

from typing import NamedTuple
from ReplayTables.ReplayBuffer import ReplayBuffer

class Data(NamedTuple):
    x: np.ndarray
    a: np.ndarray
    r: np.ndarray

buffer = ReplayBuffer(
    max_size=100_000,
    structure=Data,
    rng=np.random.default_rng(0),
)

buffer.add(Data(x, a, r))

batch = buffer.sample(32)
print(batch.x.shape) # -> (32, d)
print(batch.a.shape) # -> (32, )
print(batch.r.shape) # -> (32, )

Prioritized Replay

An implementation of prioritized experience replay from

Schaul, Tom, et al. "Prioritized experience replay." ICLR (2016).

The defaults for this implementation strictly adhere to the defaults from the original work, though several configuration options are available.

from typing import NamedTuple
from ReplayTables.PER import PERConfig, PrioritizedReplay

class Data(NamedTuple):
    a: float
    b: float

# all configurables are optional.
config = PERConfig(
    # can also use "mean" mode to place new samples in the middle of the distribution
    # or "given" mode, which requires giving the priority when the sample is added
    new_priority_mode='max',
    # the sampling distribution is a mixture between uniform sampling and the priority
    # distribution. This specifies the weight given to the uniform sampler.
    # Setting to 1 reverts this back to an inefficient form of standard uniform replay.
    uniform_probability=1e-3,
    # this implementation assume priorities are positive. Can scale priorities by raising to
    # some power. Default is `priority**(1/2)`
    priority_exponent=0.5,
    # if `new_priority_mode` is 'max', then the buffer tracks the highest seen priority.
    # this can cause accidental saturation if outlier priorities are observed. This provides
    # an exponential decay of the max in order to prevent permanent saturation.
    max_decay=1,
)

# if no config is given, defaults to original PER parameters
buffer = PrioritizedReplay(
    max_size=100_000,
    structure=Data,
    rng=np.random.default_rng(0),
    config=config,
)

buffer.add(Data(a=1, b=2))

# if `new_priority_mode` is 'given':
buffer.add(Data(a=1, b=2), priority=1.3)

batch = buffer.sample(32)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ReplayTables_andnp-7.1.0.tar.gz (35.0 kB view details)

Uploaded Source

Built Distributions

ReplayTables_andnp-7.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (363.1 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

ReplayTables_andnp-7.1.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (368.2 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARM64

ReplayTables_andnp-7.1.0-cp312-cp312-macosx_11_0_arm64.whl (318.3 kB view details)

Uploaded CPython 3.12 macOS 11.0+ ARM64

ReplayTables_andnp-7.1.0-cp312-cp312-macosx_10_12_x86_64.whl (327.1 kB view details)

Uploaded CPython 3.12 macOS 10.12+ x86-64

ReplayTables_andnp-7.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (364.1 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

ReplayTables_andnp-7.1.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (368.8 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

ReplayTables_andnp-7.1.0-cp311-cp311-macosx_11_0_arm64.whl (319.2 kB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

ReplayTables_andnp-7.1.0-cp311-cp311-macosx_10_12_x86_64.whl (329.2 kB view details)

Uploaded CPython 3.11 macOS 10.12+ x86-64

ReplayTables_andnp-7.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (364.2 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

ReplayTables_andnp-7.1.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (369.3 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

ReplayTables_andnp-7.1.0-cp310-cp310-macosx_11_0_arm64.whl (319.3 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

ReplayTables_andnp-7.1.0-cp310-cp310-macosx_10_12_x86_64.whl (329.4 kB view details)

Uploaded CPython 3.10 macOS 10.12+ x86-64

File details

Details for the file ReplayTables_andnp-7.1.0.tar.gz.

File metadata

  • Download URL: ReplayTables_andnp-7.1.0.tar.gz
  • Upload date:
  • Size: 35.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.7.4

File hashes

Hashes for ReplayTables_andnp-7.1.0.tar.gz
Algorithm Hash digest
SHA256 e4ccf690f9dd984c0194b7b47e99bf174063cb1ab5a24547f352bbd672b3c43b
MD5 267df84bdc80d92df0e7868aa94456db
BLAKE2b-256 ec09492709199f769f007cab7f11cb5df80c9c37c6d6f55842404559cc374e13

See more details on using hashes here.

File details

Details for the file ReplayTables_andnp-7.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ReplayTables_andnp-7.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 908e1eaa9082ab6bc50d5318308dbd9169ef5d2d07125f8d3a04a516fe2f25b8
MD5 1fd812e6c0bb46fe5f764cb99e97f146
BLAKE2b-256 8abfe3112870d5af4439b0ec23b858a2f892a410a55e2ea70a4906f9b06d7845

See more details on using hashes here.

File details

Details for the file ReplayTables_andnp-7.1.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for ReplayTables_andnp-7.1.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 187d731c8157da9c2924ed7a7c1103e220efac35e910f677e31eeca11865556a
MD5 d33e79649d0760a44662171992d70059
BLAKE2b-256 8151e0e8df27d48906ba43578b2946b44d85e9a30ad149d90e34d863bae6f346

See more details on using hashes here.

File details

Details for the file ReplayTables_andnp-7.1.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ReplayTables_andnp-7.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5e7bc9b101084b2d1dab1fe14e50f776e1ca78118a14f3b626434140d200772f
MD5 974e5ee0c5a5e21bd667058b3b59b575
BLAKE2b-256 3ae7a4f756fb62c8bf9911b7ccab5bf61d40031679412e16f45abf54e122275d

See more details on using hashes here.

File details

Details for the file ReplayTables_andnp-7.1.0-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for ReplayTables_andnp-7.1.0-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 9e8d0feccfdce89cb4763ec2b7f6b5d43abfd30d6554a3bb2522921a2f27c714
MD5 441bbac0b1e02dd765b39e013a6f4a14
BLAKE2b-256 5b3575af7355a012e0d9dcd9930181456886257e4b0ad2b0380945a765dab9d4

See more details on using hashes here.

File details

Details for the file ReplayTables_andnp-7.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ReplayTables_andnp-7.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6aa39bce7ea55648dedb9f4f39c9d6fae6ea98d85c2ecc7817772cb590ac95b4
MD5 ea8e0c19e490b7e6923a41637efc4de2
BLAKE2b-256 546dfd09a6e708bf805dc5d8995b5641d11e87aad5b1a9260d1b1a291609039e

See more details on using hashes here.

File details

Details for the file ReplayTables_andnp-7.1.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for ReplayTables_andnp-7.1.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 ea3bb1eab317c3e60a06f979e2f3bb97702cbab9f14b72e191774326dde90b3d
MD5 75f011eda103b2aa62f6781c17a13c45
BLAKE2b-256 f5e6d821878dd30551fcb1ba082b0211674e27868c40865bf5e28dc4d98eff24

See more details on using hashes here.

File details

Details for the file ReplayTables_andnp-7.1.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ReplayTables_andnp-7.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 dccde06d6ba541736be67a149eadd0c3f8a5a11ccc317cf4b4af23fa5fdb78d3
MD5 b8c3335d2e9ec5d18df9e06c5cb14b04
BLAKE2b-256 33e90babf6451c4f72b3bd301dd1869dab11f45a3011c1114dc4797a003a982c

See more details on using hashes here.

File details

Details for the file ReplayTables_andnp-7.1.0-cp311-cp311-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for ReplayTables_andnp-7.1.0-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 fe720cfa2cfe99b43666eb0c3d64b408d4a6ac2e4f4ae12458689e29cdaf24c4
MD5 77428c21a186e279394623b8c9511a5f
BLAKE2b-256 8f3354fb56c97d3086436a14a0e055e5a60f3f2277ea6dd7165471e81d98a0f5

See more details on using hashes here.

File details

Details for the file ReplayTables_andnp-7.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ReplayTables_andnp-7.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 78e756739285423616b9a64b9d47f40f0829405aaa193d316f8317cb83b1b801
MD5 47997993e794ee126b9581b74c49c767
BLAKE2b-256 6d39ca06e1d22441dc69b00451bad721cde4ced3be96ba5e6f51bff89d821646

See more details on using hashes here.

File details

Details for the file ReplayTables_andnp-7.1.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for ReplayTables_andnp-7.1.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 296ff3b5e1601718ae6c062bbd705291c28f521a62bd388c1e6446105a4772f1
MD5 a78dcd38cbdc07618692d14254ef1543
BLAKE2b-256 409156b675604596d58bf955de8639af648630ddd5646508117f85bf49dd837f

See more details on using hashes here.

File details

Details for the file ReplayTables_andnp-7.1.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ReplayTables_andnp-7.1.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7e54ce2b89a523edb677488e56bacaa865710fd26270be1bbc5cb8476aa45e73
MD5 ec92daa282bac68fdbed227ef341cf7c
BLAKE2b-256 0ee3181733bcf7c1c30726de245ce0200c6783aaf6c23963aa8d2053613ed080

See more details on using hashes here.

File details

Details for the file ReplayTables_andnp-7.1.0-cp310-cp310-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for ReplayTables_andnp-7.1.0-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 545837d2605b173294657760080be659e15d869de18e71c69bb13e6accd45f46
MD5 d768ef31d6bdd031e4c9ee88c3582bff
BLAKE2b-256 517cb26da1e4cba5252dc2d775ce4ddb4f2ff157dc5fed3bf07ac2a134c9e297

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page