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-6.2.16.tar.gz (38.3 kB view details)

Uploaded Source

Built Distributions

ReplayTables_andnp-6.2.16-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

ReplayTables_andnp-6.2.16-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.1 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARM64

ReplayTables_andnp-6.2.16-cp312-cp312-macosx_11_0_arm64.whl (336.0 kB view details)

Uploaded CPython 3.12 macOS 11.0+ ARM64

ReplayTables_andnp-6.2.16-cp312-cp312-macosx_10_12_x86_64.whl (343.8 kB view details)

Uploaded CPython 3.12 macOS 10.12+ x86-64

ReplayTables_andnp-6.2.16-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

ReplayTables_andnp-6.2.16-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.1 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

ReplayTables_andnp-6.2.16-cp311-cp311-macosx_11_0_arm64.whl (338.2 kB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

ReplayTables_andnp-6.2.16-cp311-cp311-macosx_10_12_x86_64.whl (347.4 kB view details)

Uploaded CPython 3.11 macOS 10.12+ x86-64

ReplayTables_andnp-6.2.16-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

ReplayTables_andnp-6.2.16-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.1 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

ReplayTables_andnp-6.2.16-cp310-cp310-macosx_11_0_arm64.whl (338.1 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

ReplayTables_andnp-6.2.16-cp310-cp310-macosx_10_12_x86_64.whl (347.2 kB view details)

Uploaded CPython 3.10 macOS 10.12+ x86-64

File details

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

File metadata

File hashes

Hashes for ReplayTables_andnp-6.2.16.tar.gz
Algorithm Hash digest
SHA256 0f2a6e4787bd0234f2277b29fcbb898f905ba235ad378445a9261ed2c806b0b9
MD5 5424c6b155651cdd2b8de468836517f5
BLAKE2b-256 296512b74ec613a063c890f294ff0d7818ba8cfc481a640e966db954c632c4c5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ReplayTables_andnp-6.2.16-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 972ebdbc56cc50e9fae6df65a1b829e24dd4bc21249398f91d8e6ca89881d6f3
MD5 c8ae7f95ac76ad4110d2dc22fb4303d0
BLAKE2b-256 480a85c8141bd11a44e44a72d6b5e739a18b57b01fb54600bc388235354b2f6f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ReplayTables_andnp-6.2.16-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 734cb693c4e371bc3d812c3b740eba1bfc6c481d2d7628b3e5767c35502f94b5
MD5 812f4f59348c290d953f728a80cc4270
BLAKE2b-256 a149e2b65402431d5094d98a7539481b7bfe5513512275570e4385a0eefbfbf2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ReplayTables_andnp-6.2.16-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cebbf2d3ae68e3b065d485454d0a9dbc4342b385e53598245e8106af8fa6ee3b
MD5 3ecf4ce782400a61ab5f30ef78b94b10
BLAKE2b-256 5208bea0eba8540c741b3e073983b4cb17c941264ce5a8cf77debc90c6b5a8f2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ReplayTables_andnp-6.2.16-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 9fc56c8d223016a4bb71bb3e358a68f4002329001df8322167f8a7b544b0964e
MD5 f93e1b19becf8aa4a9cff8fa40f0ce82
BLAKE2b-256 f5440e6cf462dc799c22f4e640dbdc8ac9383af9fc4e2107261a0634f2ac5c80

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ReplayTables_andnp-6.2.16-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f9feea63ada9fabcd6e9d20ed53786fbd72528087cbb9380d57566e9fbd743b7
MD5 60d8c6f2aad4f397746873fdb69d3eda
BLAKE2b-256 4dea9ec5f554737511309991ca26f1ae01b928ac707834219ccb437c2837dbf6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ReplayTables_andnp-6.2.16-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 617e200b15a7c58b079dd78ee55c76d5a2bbcd56ef0f63e1ea0fc5809fc50caa
MD5 d6ca91df06eba711b8e94afe1178d18b
BLAKE2b-256 27a3a948d76905ae1192e1c5dedafd516b0884d4d3d5e22b68a6dbc69d31ef16

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ReplayTables_andnp-6.2.16-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5108ac84db52efc6cb1e0ecab66a4633f2290d61ff813fee4f1aea0bbe015efc
MD5 57e99d302598510ceb7a3f2d609e29c2
BLAKE2b-256 c21b7a4b59e217c59047b08efe95b1807abb64ccea5b764a12a2a6433dbd54d4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ReplayTables_andnp-6.2.16-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 4e7537b85d53e1612f9e06e4c5558fe0fd0ec23d2595deb96d27ebaf4f2e6596
MD5 66370386a4e8987a6de83df7e8b20629
BLAKE2b-256 2fc864f68ed8dceea1600250190a4e482a6f028c255aba10e6a218ff9b1ae3ed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ReplayTables_andnp-6.2.16-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7ab388e5f83490ed3df2af20b8b757d9e186fe477139a0e9979bd28914063d82
MD5 c4c055e0cffaeb0e611e79e82079cbd6
BLAKE2b-256 c650a948611dbe5393c160f5226c66ca22902d60f4b02e8ec797bf206a62911e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ReplayTables_andnp-6.2.16-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 90d4aaca6c995d2da8be38c697b5219ec57aab95a07719d3cbeefd55738c5b19
MD5 76c6766c66cc0d76964a69f8f4b4afb3
BLAKE2b-256 0cbcb8d97e159785044548d518f847aca879661a135574cd8b6a9c891da0b0a2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ReplayTables_andnp-6.2.16-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5c7b88933ac0f4c4aa18fb5932330f7bada9d8ff14d9eaef5d2a9ffb50b0c9e9
MD5 2f24406bdd6dd23b4354bb3ff21815a3
BLAKE2b-256 be52e5c8bf50e7667d8167dd1b58ff40b2945e138104a6fed15ef92d8311ecf3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ReplayTables_andnp-6.2.16-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 ce597c2b70f39ee51650fcfcb4ecdef64cf46fe359c982ed2a5108b0916443f5
MD5 e39209b54485e1d9ab5ff344aa511199
BLAKE2b-256 3abe5ebd65cb9da100e66d1a3d637ff6297e1ed7cd76517469989739252465a5

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