Skip to main content

EarlyStopping

Struct EarlyStopping 

Source
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: u32

Checks without improvement after which training should stop.

Implementations§

Source§

impl<V> EarlyStopping<V>

Source

pub const fn new(patience: u32) -> Self

Early stopping after patience checks without improvement.

Source

pub fn reset(&mut self)

Forget the best error and the count, as before the first check.

Source

pub fn patience_counter(&self) -> u32

Checks since the error last improved.

Source§

impl<V: Copy> EarlyStopping<V>

Source

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>

Source

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.

Trait Implementations§

Source§

impl<V: Clone> Clone for EarlyStopping<V>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<V: Copy> Copy for EarlyStopping<V>

Source§

impl<V: Debug> Debug for EarlyStopping<V>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<V> Default for EarlyStopping<V>

Source§

fn default() -> Self

Patience 100, tinymind (C++)’s default.

Source§

impl<V: Eq> Eq for EarlyStopping<V>

Source§

impl<V: PartialEq> PartialEq for EarlyStopping<V>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<V: PartialEq> StructuralPartialEq for EarlyStopping<V>

Auto Trait Implementations§

§

impl<V> Freeze for EarlyStopping<V>
where V: Freeze,

§

impl<V> RefUnwindSafe for EarlyStopping<V>
where V: RefUnwindSafe,

§

impl<V> Send for EarlyStopping<V>
where V: Send,

§

impl<V> Sync for EarlyStopping<V>
where V: Sync,

§

impl<V> Unpin for EarlyStopping<V>
where V: Unpin,

§

impl<V> UnsafeUnpin for EarlyStopping<V>
where V: UnsafeUnpin,

§

impl<V> UnwindSafe for EarlyStopping<V>
where V: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.