pub struct ReplayBuffer { /* private fields */ }Expand description
Experience Replay Buffer for storing and sampling past training examples
Implementations§
Source§impl ReplayBuffer
impl ReplayBuffer
Sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
Create a new replay buffer with specified capacity
§Arguments
capacity- Maximum number of entries to store
Sourcepub fn add(&mut self, query: &[f32], positive_ids: &[usize])
pub fn add(&mut self, query: &[f32], positive_ids: &[usize])
Add a new entry to the buffer using reservoir sampling
Reservoir sampling ensures uniform distribution over all samples seen, even as old samples are evicted due to capacity constraints.
§Arguments
query- Query vectorpositive_ids- IDs of positive nodes for this query
Sourcepub fn sample(&self, batch_size: usize) -> Vec<&ReplayEntry>
pub fn sample(&self, batch_size: usize) -> Vec<&ReplayEntry>
Sourcepub fn detect_distribution_shift(&self, recent_window: usize) -> f32
pub fn detect_distribution_shift(&self, recent_window: usize) -> f32
Detect distribution shift between recent samples and overall distribution
Uses Kullback-Leibler divergence approximation based on mean and variance changes.
§Arguments
recent_window- Number of most recent samples to compare
§Returns
Shift score (higher values indicate more significant distribution shift) Returns 0.0 if insufficient data
Sourcepub fn total_seen(&self) -> usize
pub fn total_seen(&self) -> usize
Get the total number of samples seen (including evicted ones)
Sourcepub fn distribution_stats(&self) -> &DistributionStats
pub fn distribution_stats(&self) -> &DistributionStats
Get a reference to the distribution statistics
Auto Trait Implementations§
impl Freeze for ReplayBuffer
impl RefUnwindSafe for ReplayBuffer
impl Send for ReplayBuffer
impl Sync for ReplayBuffer
impl Unpin for ReplayBuffer
impl UnsafeUnpin for ReplayBuffer
impl UnwindSafe for ReplayBuffer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more