Expand description
Replay buffer for off-policy training (DQN).
This module implements two flavors of experience replay used by
crate::train::dqn:
ReplayBuffer— a fixed-capacity FIFO buffer with uniform sampling. The classic DQN recipe.PrioritizedReplayBuffer— a sum-tree backed buffer with proportional priority sampling and importance-sampling correction weights (Schaul et al. 2015).ContinuousReplayBuffer— the continuous-action sibling ofReplayBuffer, storingVec<f32>actions of widthaction_dimfor off-policy continuous control (SAC / TD3 / DDPG). Same ring/FIFO design and flat-Vecstorage; sample it viasample_continuous.
All store transitions as flat CPU-side Vecs rather than Burn tensors
so the buffer stays WASM-compatible if it ever needs to be exposed
there. Tensor materialization happens via to_burn_tensors on the
batch types when the trainer pushes them to a device.
§Quick example (uniform)
ⓘ
use thrust_rl::buffer::replay::{ReplayBuffer, sample};
use rand::SeedableRng;
let mut buf = ReplayBuffer::new(/* capacity */ 50_000, /* obs_dim */ 4);
buf.push(&[0.0; 4], /* action */ 1, /* reward */ 1.0, &[0.1; 4], /* done */ false);
let mut rng = rand::rngs::StdRng::seed_from_u64(0);
if buf.is_ready(/* min_size */ 1) {
let batch = sample(&buf, 64, &mut rng);
let device = Default::default();
let t = batch.to_burn_tensors::<MyBackend>(&device);
// ... feed t.* into the DQN trainer ...
}§Quick example (prioritized)
ⓘ
use thrust_rl::buffer::replay::PrioritizedReplayBuffer;
use rand::SeedableRng;
let mut buf = PrioritizedReplayBuffer::new(50_000, 4, /* α */ 0.6, /* ε */ 1e-6);
buf.push(&[0.0; 4], 1, 1.0, &[0.1; 4], false);
let mut rng = rand::rngs::StdRng::seed_from_u64(0);
if buf.is_ready(1) {
let batch = buf.sample(64, /* β */ 0.4, &mut rng);
let device = Default::default();
let t = batch.to_burn_tensors::<MyBackend>(&device);
// ... compute weighted Smooth-L1 loss, backprop ...
// ... then write the new TD-error magnitudes back:
// buf.update_priorities(&batch.indices, &new_td_errors);
}Structs§
- Continuous
Replay Batch - One minibatch sampled from the continuous replay buffer.
- Continuous
Replay Buffer - Fixed-capacity FIFO replay buffer for off-policy continuous-action training.
- Continuous
Replay Burn Tensors - Bundle of Burn tensors produced by
ContinuousReplayBatch::to_burn_tensors. - Prioritized
Batch - One minibatch sampled from a
PrioritizedReplayBuffer. - Prioritized
Burn Tensors - Bundle of Burn tensors produced by
PrioritizedBatch::to_burn_tensors. - Prioritized
Replay Buffer - Fixed-capacity prioritized replay buffer.
- Replay
Batch - One minibatch sampled from the replay buffer.
- Replay
Buffer - Fixed-capacity FIFO replay buffer for off-policy training.
- Replay
Burn Tensors - Bundle of Burn tensors produced by
ReplayBatch::to_burn_tensors. - SumTree
- Sum-tree over
capacityleaves backed by a flatVec<f32>.
Functions§
- sample
- Sample
batch_sizetransitions uniformly with replacement from the filled portion ofbuffer. - sample_
continuous - Sample
batch_sizetransitions uniformly with replacement from the filled portion ofbuffer.