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

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

ReplayTables_andnp-8.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (341.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

ReplayTables_andnp-8.0.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (338.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

ReplayTables_andnp-8.0.0-cp312-cp312-macosx_11_0_arm64.whl (300.8 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

ReplayTables_andnp-8.0.0-cp312-cp312-macosx_10_12_x86_64.whl (305.3 kB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

ReplayTables_andnp-8.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (341.9 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

ReplayTables_andnp-8.0.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (339.0 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

ReplayTables_andnp-8.0.0-cp311-cp311-macosx_11_0_arm64.whl (301.6 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

ReplayTables_andnp-8.0.0-cp311-cp311-macosx_10_12_x86_64.whl (306.4 kB view details)

Uploaded CPython 3.11macOS 10.12+ x86-64

ReplayTables_andnp-8.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (341.9 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

ReplayTables_andnp-8.0.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (338.8 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

ReplayTables_andnp-8.0.0-cp310-cp310-macosx_11_0_arm64.whl (301.7 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

ReplayTables_andnp-8.0.0-cp310-cp310-macosx_10_12_x86_64.whl (306.4 kB view details)

Uploaded CPython 3.10macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for ReplayTables_andnp-8.0.0.tar.gz
Algorithm Hash digest
SHA256 11d95627d81ce7fea67a688aed1c245e76c20d7ec39f58e14bfadd34135df2c5
MD5 ef43ee123ba9527a8ccbcb0eb623fe7d
BLAKE2b-256 005ee51c5eb86e418c2bfc0bd4e5267ec8a56d156261cb842d369c18247df653

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ReplayTables_andnp-8.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2e3c83ebff4f10cb4aab1284a1e9d5eee4e8356958b5675fa5f255ecab4db55c
MD5 a39f25bf188aa4389fe42c66a0ec2142
BLAKE2b-256 17006f20d422a3515e2edf0186eeb1741b6ac9cc5eda35886688758c264e51c7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ReplayTables_andnp-8.0.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 3489f5a5dcf684555d6cf51dc83f9d96ea6f7dd1363f94f7aa3ba4461c405ca4
MD5 6b395da35fa623543d618e75bc045bfc
BLAKE2b-256 ccb8074189c18be49bec1837a064119011f014008439ec62f8ffba5bd5b610bb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ReplayTables_andnp-8.0.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f7312478551470b6e76dd78a5f62d2fe4f73b97857b85c4a71400d1d7d497da3
MD5 1924ee2aedd5272c53ad58558fe3a112
BLAKE2b-256 65068ab1a74a613db0837d2b436aedc11775db4829b4571ff1314e75def66930

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ReplayTables_andnp-8.0.0-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 166fb71b9db2618ed5c3a1ef7f7fc078cc38d3195ecb91ffec8790d3dd85a0f6
MD5 9e184037468104e681567ba1408a8730
BLAKE2b-256 eab734026da911adc55ab6b1e9d4b62c81ffc3857541be4ca36f8a07f62684a2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ReplayTables_andnp-8.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2210f7f1dd4202089ab9ab56a273ffff272c6cc4e135b70c2733e3f07ac581cd
MD5 c79d18beecd05bcc96fa3633bd17880c
BLAKE2b-256 d279128bf53d596bed609594e1120bedfef61ea1e631284ec5053c0dc21b761e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ReplayTables_andnp-8.0.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 9abac9a9c230f987c6ef2b207d8c3b2600e1577707ee53e7e0d7afb0e8260434
MD5 c4b2dfc626f6156a7dfbf941a41ad45f
BLAKE2b-256 0a24d6f6fc2fb1271a03c6ca96768eb60244cf069aacf70a7355cf53bfa2494f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ReplayTables_andnp-8.0.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 44ac7a43c796abebd49645eca21728483c4c20538b81cdb05d33040a7e2db447
MD5 e972fab86feaf6687fb166b503e534d0
BLAKE2b-256 dc1fee6153d2be6c325e09d104e009b43656aa2e1c80797c3b2063ecdf1f5b8d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ReplayTables_andnp-8.0.0-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 c42886a79372c657a4d1ad6ad47d9b511c227e3c7fc2a358db701930cdf88f71
MD5 1e42a737042190bb8050bc79e8712916
BLAKE2b-256 c13a4bf42f1a592da8e49c87590d3b28f1453f94d701a35374346ce0408ff140

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ReplayTables_andnp-8.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 85d147b789d85dfdb7fd4344da420a30dcd17a45d8a2eb8cfcf3a957030c2bcb
MD5 7ea51f44307f11318c810804ba2e6a61
BLAKE2b-256 9066751d153fa4422c95e914b957e971c0871b0bae5185aa2096b3a19fff311e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ReplayTables_andnp-8.0.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 ad272f0e9e37a6d1c8a02abaea463ca1fe958fa97c887d0aae57046d6d28c871
MD5 2f635fb0df6425b5ac038708fa74a88d
BLAKE2b-256 1965a88aab194f88d48b9d5cf29981482e566cb738faf01b8ff3e2911e4a5e64

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ReplayTables_andnp-8.0.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b32332c9ac949ecf64c40520b8511df6a502019148c98325ac98088720d931a6
MD5 3e8a510118957275cdfe217b52e00d53
BLAKE2b-256 355fca48dd8decfebba23f0fd0f83feef728d925271d807cef98f2f4d18966fc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ReplayTables_andnp-8.0.0-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 b9d78423dcc1b718399d438c329470ed697f9e8fc08bfec0db28d28b9e39abc1
MD5 12d38faf9d54bcb61e424f156104ca68
BLAKE2b-256 25f9cea6f769d983ad1ee41881ed4d7f0fdc04a2767355744a3acacb48f80ea5

See more details on using hashes here.

Supported by

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