Skip to main content

Stop

Enum Stop 

Source
pub enum Stop {
    MaxTrials(u64),
    MinTrials(u64),
    MinErrors {
        metric: String,
        errors: u64,
    },
    Precision {
        metric: String,
        relative: f64,
        confidence: f64,
    },
    MaxTime(Duration),
    Any(Vec<Stop>),
    All(Vec<Stop>),
}
Expand description

A stopping rule.

Variants§

§

MaxTrials(u64)

At most this many trials: met once they have run (a cap, printed max_trials(n)).

§

MinTrials(u64)

Never before this many trials (use with Stop::and; met once they have run, as Stop::MaxTrials, but printed min_trials(n)).

§

MinErrors

At least errors errors of the error rate metric (never met by a mean).

Fields

§metric: String

The error-rate metric.

§errors: u64

The number of errors.

§

Precision

Relative half-width of the confidence interval of metric at most relative.

Fields

§metric: String

The metric.

§relative: f64

The relative half-width.

§confidence: f64

The confidence level of the interval.

§

MaxTime(Duration)

At least this much wall time on the condition.

§

Any(Vec<Stop>)

Any of the rules.

§

All(Vec<Stop>)

All of the rules.

Implementations§

Source§

impl Stop

Source

pub fn max_trials(n: u64) -> Stop

Stop after n trials.

Source

pub fn min_trials(n: u64) -> Stop

Never stop before n trials.

Source

pub fn min_errors(metric: &str, errors: u64) -> Stop

Stop after errors errors of the error rate metric.

Source

pub fn precision(metric: &str, relative: f64) -> Stop

Stop when the 95 % interval of metric is within ±relative of its value.

Source

pub fn precision_at(metric: &str, relative: f64, confidence: f64) -> Stop

Stop when the interval of level confidence of metric is within ±relative of its value (the runner refuses a level outside $(0, 1)$, see check_confidence).

§Examples
use comnum_sim::stopping::Stop;
assert_eq!(Stop::precision_at("snr_db", 0.01, 0.99).to_string(), "precision(snr_db) ≤ 0.01 at 0.99");
Source

pub fn max_time(d: Duration) -> Stop

Stop after d of wall time on the condition.

Source

pub fn or(self, other: Stop) -> Stop

Either rule.

Source

pub fn and(self, other: Stop) -> Stop

Both rules.

Source

pub fn is_met(&self, p: &Progress<'_>) -> bool

Whether the rule is met.

Source

pub fn is_bounded(&self) -> bool

Whether the rule can stop at all (a rule made only of lower bounds would run forever).

Source

pub fn trial_limit(&self) -> Option<u64>

The number of trials at which the rule is met whatever the metrics and the time, if there is one: n for Stop::max_trials and Stop::min_trials, the smallest bound of an Stop::or, the largest of an Stop::and whose rules all have one. The runner ends its last batch there.

§Examples
use comnum_sim::stopping::Stop;
assert_eq!(Stop::min_errors("ber", 100).or(Stop::max_trials(1000)).trial_limit(), Some(1000));
assert_eq!(Stop::max_trials(1000).and(Stop::min_trials(10)).trial_limit(), Some(1000));
assert_eq!(Stop::min_errors("ber", 100).and(Stop::max_trials(1000)).trial_limit(), None);
Source

pub fn check_confidences(&self) -> Result<()>

Check the confidence levels of the precision targets of the rule (check_confidence).

§Errors

Error::Config for a level outside $(0, 1)$.

Source

pub fn check_metrics(&self, record: &Record) -> Result<()>

Check that every target of the rule can be met by the metrics of record (the record of a first batch of trials).

§Errors

Error::Config for a target on a metric that record does not hold (the message names the recorded ones), or Stop::min_errors on a mean.

§Examples
use comnum_sim::stopping::Stop;
use comnum_sim::scenario::Record;
let mut rec = Record::new();
rec.errors("ber", 3, 1000);
rec.value("snr_db", 9.5);
assert!(Stop::min_errors("ber", 100).or(Stop::max_trials(10)).check_metrics(&rec).is_ok());
let e = Stop::min_errors("bler", 100).or(Stop::max_trials(10)).check_metrics(&rec).unwrap_err();
assert!(e.to_string().contains("bler") && e.to_string().contains("ber, snr_db"));
assert!(Stop::min_errors("snr_db", 100).or(Stop::max_trials(10)).check_metrics(&rec).is_err());

Trait Implementations§

Source§

impl Clone for Stop

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 Debug for Stop

Source§

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

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

impl Display for Stop

Source§

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

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

impl PartialEq for Stop

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 StructuralPartialEq for Stop

Auto Trait Implementations§

§

impl Freeze for Stop

§

impl RefUnwindSafe for Stop

§

impl Send for Stop

§

impl Sync for Stop

§

impl Unpin for Stop

§

impl UnsafeUnpin for Stop

§

impl UnwindSafe for Stop

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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.