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

Uploaded Source

Built Distributions

ReplayTables_andnp-6.2.12-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.12-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.12-cp312-cp312-macosx_11_0_arm64.whl (307.6 kB view details)

Uploaded CPython 3.12 macOS 11.0+ ARM64

ReplayTables_andnp-6.2.12-cp312-cp312-macosx_10_12_x86_64.whl (315.7 kB view details)

Uploaded CPython 3.12 macOS 10.12+ x86-64

ReplayTables_andnp-6.2.12-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.12-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.12-cp311-cp311-macosx_11_0_arm64.whl (309.7 kB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

ReplayTables_andnp-6.2.12-cp311-cp311-macosx_10_12_x86_64.whl (319.5 kB view details)

Uploaded CPython 3.11 macOS 10.12+ x86-64

ReplayTables_andnp-6.2.12-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.12-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.12-cp310-cp310-macosx_11_0_arm64.whl (309.6 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

ReplayTables_andnp-6.2.12-cp310-cp310-macosx_10_12_x86_64.whl (319.2 kB view details)

Uploaded CPython 3.10 macOS 10.12+ x86-64

File details

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

File metadata

File hashes

Hashes for ReplayTables_andnp-6.2.12.tar.gz
Algorithm Hash digest
SHA256 5e40003c098700425f69b31777243ea20dd3d728444310f61841847dbc98dd80
MD5 fe0054be90b64c95a8f42106b6b502c0
BLAKE2b-256 51afd21a128cabed6df04393dc7e1a3e88f665b9308df14bd477d072cae7f2cb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ReplayTables_andnp-6.2.12-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 28c1fd83ead744a99dcbd0c6f0bf78b03ecd1f987d5213e8576c4ec3db85da46
MD5 d55d388008a291bc89ee7ec92bebdfb0
BLAKE2b-256 af97cac4c56ab857d284f19dcc8e2b78022dd9c6575871366ca1abdceaa5861c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ReplayTables_andnp-6.2.12-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f88c2f8872a9e56b0f326d2b8fd9b0e8010dc6c4d974d019f4946d18295c5cde
MD5 1f9a229bf3a9fd50dc5ba6d946bc777d
BLAKE2b-256 23d37a690e22d3c9635c09223c14109b6ff694542421752a0aef369dbda9a609

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ReplayTables_andnp-6.2.12-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2fd5ad2c38849b45b5c7731dff76976bba7830b90d13133a9a39db5117a8443e
MD5 4ff8dc5cbcf0eefdeff7993c4ee30632
BLAKE2b-256 8753226bb66e4858f6359943819a50613a2e9dce67ca40eb0a18d9278282267f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ReplayTables_andnp-6.2.12-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 e7b275f29cb57b6a8bc3289ea2a326d3d56caa7fc0534a9a2e0ace1cbe3d78b8
MD5 7d7aa67d0095f658853767cdc70bcf9b
BLAKE2b-256 51a34bd227b115aaffa0ff2842785a259b1e7beb600fa491a203ff5fe8304231

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ReplayTables_andnp-6.2.12-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 744a02671f3c526509a38774031432ae2cb8879e4fe8cdfa3577f63045b35102
MD5 91a27ee05d857a031afe69773b378b2f
BLAKE2b-256 99ac3ec5a4fad4f9b753fadd4b055622f78b798be795fb6541d68209364c6812

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ReplayTables_andnp-6.2.12-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 bc91cd5427e5266a8259bc2f5dc75747ae85f413132e03c66cf58a13607c801a
MD5 10ecde585b5b681afa2984ce786a9b93
BLAKE2b-256 ba95e02f2137340f8b5fa0749d29a1e8780a49758c938fbf47d1c1e096d7c9de

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ReplayTables_andnp-6.2.12-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0d4c0ec8ef5da763e60c426722c61a59c8cdef4f767475b8ef6a1440c56ee7ff
MD5 e87f4dee65d0d162fa265dd93ec23461
BLAKE2b-256 5a885389390a0eb7e9cf414a15d54052c1fb49d84a886b907c02a357eb62cc93

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ReplayTables_andnp-6.2.12-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 62ea542e10c81182bbf6028b3baa9298122f0d82fa6e8242f58ec0cb2b132532
MD5 934cc6052f6ec5a436ad9dc7cc22cc67
BLAKE2b-256 9edc5de4da96b7d553e47b9ebd933ca271ee885985a555711b58e05b548cafbe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ReplayTables_andnp-6.2.12-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1baefb1c1a322e2e22d1c2a7a8e9212bdf757bf595600556638409f7e291151d
MD5 be6e32fe340708a677d4a6b9bc5d6929
BLAKE2b-256 b0ecf3759ed15b6a520a25b12154e0fbecacc240ce3df850dcb1ec0b96b916cb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ReplayTables_andnp-6.2.12-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 0aca05c30cf22da6273119dbeff465f8b4621233dd837d74fe35b4a2e9b95f63
MD5 114f319465481f2f73c755da90a52ddb
BLAKE2b-256 41189ed373764620937227d7beffc6e7f7b3a9710a0d3bf82d63a82f2c788f17

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ReplayTables_andnp-6.2.12-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7af1baec2f49c92ae7cc3b45c67fe01312764c57ef342d2e454782ef3d55688d
MD5 465d5253a570ca872409ce36c18ca12c
BLAKE2b-256 548f648d34a2bde1bfd061e1ea32f5c521ca3f6d894169e6624a29475be0b50c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ReplayTables_andnp-6.2.12-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 24fa5a21f40bf80a68a754c29f84588af81de36331372d1866697685c710b0de
MD5 dab127a0a66c0ad58daf60c37195d599
BLAKE2b-256 00ca550b218b3132091a9801842d2706352e3b4e9aa5a27b79e44517269d1d61

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