pub struct EarlyStopping<V> {
pub patience: u32,
/* private fields */
}Expand description
Early stopping (C++ EarlyStopping): reports when the error has not
improved for patience checks in a row.
The first error checked becomes the best. After that, an error below the
best replaces it and resets the count; any other error (equal, larger, or
a floating-point NaN) adds one to the count, and
should_stop returns true once the count reaches
patience, and keeps returning true until an error improves on the best.
A NaN as the first error becomes the best, and no error is below it, so
check floating-point errors for NaN before passing them in.
The default patience is 100, tinymind (C++)’s default.
use tinymind::training::EarlyStopping;
let mut stopper = EarlyStopping::new(2);
let errors = [0.9, 0.5, 0.6, 0.4, 0.4, 0.7, 0.3];
let stop = errors.iter().position(|&e| stopper.should_stop(e));
assert_eq!(stop, Some(5)); // 0.4 and then 0.7 did not improve on 0.4
assert_eq!(stopper.best_error(), Some(0.4));Fields§
§patience: u32Checks without improvement after which training should stop.
Implementations§
Source§impl<V> EarlyStopping<V>
impl<V> EarlyStopping<V>
Source§impl<V: Copy> EarlyStopping<V>
impl<V: Copy> EarlyStopping<V>
Sourcepub fn best_error(&self) -> Option<V>
pub fn best_error(&self) -> Option<V>
The lowest error seen so far, or None before the first check.
Source§impl<V: Copy + PartialOrd> EarlyStopping<V>
impl<V: Copy + PartialOrd> EarlyStopping<V>
Sourcepub fn should_stop(&mut self, error: V) -> bool
pub fn should_stop(&mut self, error: V) -> bool
Report error (training or validation) and return whether training
should stop: true when patience checks in a row, this one included,
have not improved on the best error.