pub struct StatsTracker { /* private fields */ }Expand description
Accumulates per-episode stats and reports summary aggregates.
By default tracks episode_reward (mean) and episode_length (mean).
Use the builder methods to add custom stats or change aggregators.
§Usage
ⓘ
let mut tracker = StatsTracker::new()
.with("episode_reward_max", StatSource::TotalReward, Max::default())
.with_custom("ep_len_last10", |r| r.length as f64, RollingMean::new(10));
// Feed an episode record:
tracker.update(&record);
// Print summary:
let summary = tracker.summary();
println!("mean reward: {:.1}", summary["episode_reward"]);Implementations§
Source§impl StatsTracker
impl StatsTracker
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a tracker with the default stats: episode_reward (mean) and episode_length (mean).
Sourcepub fn with(
self,
name: impl Into<String>,
source: StatSource,
aggregator: impl Aggregator + 'static,
) -> Self
pub fn with( self, name: impl Into<String>, source: StatSource, aggregator: impl Aggregator + 'static, ) -> Self
Track a predefined stat field with the given aggregator.
Sourcepub fn with_custom(
self,
name: impl Into<String>,
f: impl Fn(&EpisodeRecord) -> f64 + Send + Sync + 'static,
aggregator: impl Aggregator + 'static,
) -> Self
pub fn with_custom( self, name: impl Into<String>, f: impl Fn(&EpisodeRecord) -> f64 + Send + Sync + 'static, aggregator: impl Aggregator + 'static, ) -> Self
Track an arbitrary derived value from each episode record.
Sourcepub fn update(&mut self, record: &EpisodeRecord)
pub fn update(&mut self, record: &EpisodeRecord)
Feed a completed episode into all tracked stats.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for StatsTracker
impl !RefUnwindSafe for StatsTracker
impl Send for StatsTracker
impl Sync for StatsTracker
impl Unpin for StatsTracker
impl UnsafeUnpin for StatsTracker
impl !UnwindSafe for StatsTracker
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more