Uncertain

Struct Uncertain 

Source
pub struct Uncertain<T>{ /* private fields */ }
Expand description

A type representing a value with inherent uncertainty, modeled as a probability distribution.

Implementations§

Source§

impl Uncertain<bool>

Source

pub fn point(value: bool) -> Uncertain<bool>

Creates a new Uncertain<bool> instance representing a point distribution.

§Arguments
  • value - The boolean value of the point distribution.
Source

pub fn bernoulli(p: f64) -> Uncertain<bool>

Creates a new Uncertain<bool> instance representing a Bernoulli distribution.

§Arguments
  • p - The probability of success (true) for the Bernoulli distribution.
Source

pub fn to_bool( &self, threshold: f64, confidence: f64, epsilon: f64, max_samples: usize, ) -> Result<bool, UncertainError>

Converts the uncertain boolean distribution to a single boolean value based on statistical hypothesis testing.

This method uses Sequential Probability Ratio Test (SPRT) to determine if the underlying probability of true exceeds a given threshold.

§Arguments
  • threshold - The probability threshold to test against.
  • confidence - The desired confidence level (e.g., 0.95 for 95% confidence).
  • epsilon - The indifference region, defining how close the probability can be to the threshold and still be considered uncertain.
  • max_samples - The maximum number of samples to take during the SPRT.
§Returns

Ok(bool) if a decision can be made, or Err(UncertainError) if the test fails or cannot conclude.

Source

pub fn probability_exceeds( &self, threshold: f64, confidence: f64, epsilon: f64, max_samples: usize, ) -> Result<bool, UncertainError>

Determines if the probability of the uncertain boolean being true exceeds a given threshold.

This method is an alias for to_bool and also uses Sequential Probability Ratio Test (SPRT).

§Arguments
  • threshold - The probability threshold to test against.
  • confidence - The desired confidence level.
  • epsilon - The indifference region.
  • max_samples - The maximum number of samples to take.
§Returns

Ok(bool) indicating whether the probability exceeds the threshold, or Err(UncertainError).

Source

pub fn implicit_conditional(&self) -> Result<bool, UncertainError>

Evaluates an implicit conditional, typically checking if the probability of true exceeds 0.5.

This is a convenience method that calls probability_exceeds with default parameters: threshold = 0.5, confidence = 0.95, epsilon = 0.05, max_samples = 1000.

Source

pub fn estimate_probability( &self, num_samples: usize, ) -> Result<f64, UncertainError>

Estimates the probability that this condition is true by taking multiple samples.

Source§

impl Uncertain<f64>

Source

pub fn point(value: f64) -> Uncertain<f64>

Source

pub fn normal(mean: f64, std_dev: f64) -> Uncertain<f64>

Source

pub fn uniform(low: f64, high: f64) -> Uncertain<f64>

Source

pub fn from_samples(samples: &[f64]) -> Uncertain<f64>

Source

pub fn estimate_probability_exceeds( &self, threshold: f64, num_samples: usize, ) -> Result<f64, UncertainError>

Source

pub fn map<F>(&self, func: F) -> Uncertain<f64>
where F: Fn(f64) -> f64 + Send + Sync + 'static,

Source

pub fn map_to_bool<F>(&self, func: F) -> Uncertain<bool>
where F: Fn(f64) -> bool + Send + Sync + 'static,

Source§

impl Uncertain<f64>

Source

pub fn greater_than(&self, threshold: f64) -> Uncertain<bool>

Source

pub fn less_than(&self, threshold: f64) -> Uncertain<bool>

Source

pub fn equals(&self, threshold: f64) -> Uncertain<bool>

Source

pub fn gt_uncertain(&self, other: &Uncertain<f64>) -> Uncertain<bool>

Source

pub fn lt_uncertain(&self, other: &Uncertain<f64>) -> Uncertain<bool>

Source

pub fn eq_uncertain(&self, other: &Uncertain<f64>) -> Uncertain<bool>

Source

pub fn approx_eq(&self, target: f64, tolerance: f64) -> Uncertain<bool>

Check if value is approximately equal within tolerance

Source

pub fn within_range(&self, min: f64, max: f64) -> Uncertain<bool>

Check if value is within a range

Source§

impl Uncertain<f64>

Source

pub fn sample_with_index( &self, sample_index: u64, ) -> Result<f64, UncertainError>

Source

pub fn sample(&self) -> Result<f64, UncertainError>

Source

pub fn take_samples(&self, n: usize) -> Result<Vec<f64>, UncertainError>

Source§

impl Uncertain<bool>

Source

pub fn sample_with_index( &self, sample_index: u64, ) -> Result<bool, UncertainError>

Source

pub fn sample(&self) -> Result<bool, UncertainError>

Source

pub fn take_samples(&self, n: usize) -> Result<Vec<bool>, UncertainError>

Source§

impl Uncertain<f64>

Source

pub fn expected_value(&self, num_samples: usize) -> Result<f64, UncertainError>

Estimates the expected value (mean) of the uncertain f64 value by taking multiple samples.

Source

pub fn standard_deviation( &self, num_samples: usize, ) -> Result<f64, UncertainError>

Estimates the standard deviation of the uncertain f64 value by taking multiple samples.

Source§

impl<T> Uncertain<T>

Source

pub fn conditional( condition: Uncertain<bool>, if_true: Uncertain<T>, if_false: Uncertain<T>, ) -> Uncertain<T>

Source§

impl<T> Uncertain<T>

Source

pub fn id(&self) -> usize

Source

pub fn value(&self) -> T

Trait Implementations§

Source§

impl Add for Uncertain<f64>

Source§

type Output = Uncertain<f64>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Uncertain<f64>) -> <Uncertain<f64> as Add>::Output

Performs the + operation. Read more
Source§

impl BitAnd for Uncertain<bool>

Source§

type Output = Uncertain<bool>

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: Uncertain<bool>) -> <Uncertain<bool> as BitAnd>::Output

Performs the & operation. Read more
Source§

impl BitOr for Uncertain<bool>

Source§

type Output = Uncertain<bool>

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: Uncertain<bool>) -> <Uncertain<bool> as BitOr>::Output

Performs the | operation. Read more
Source§

impl BitXor for Uncertain<bool>

Source§

type Output = Uncertain<bool>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: Uncertain<bool>) -> <Uncertain<bool> as BitXor>::Output

Performs the ^ operation. Read more
Source§

impl<T> Clone for Uncertain<T>

Source§

fn clone(&self) -> Uncertain<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for Uncertain<T>

Source§

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

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

impl Default for Uncertain<bool>

Source§

fn default() -> Uncertain<bool>

Returns the “default value” for a type. Read more
Source§

impl Default for Uncertain<f64>

Source§

fn default() -> Uncertain<f64>

Returns the “default value” for a type. Read more
Source§

impl Div for Uncertain<f64>

Source§

type Output = Uncertain<f64>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Uncertain<f64>) -> <Uncertain<f64> as Div>::Output

Performs the / operation. Read more
Source§

impl Mul for Uncertain<f64>

Source§

type Output = Uncertain<f64>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Uncertain<f64>) -> <Uncertain<f64> as Mul>::Output

Performs the * operation. Read more
Source§

impl Neg for Uncertain<f64>

Source§

type Output = Uncertain<f64>

The resulting type after applying the - operator.
Source§

fn neg(self) -> <Uncertain<f64> as Neg>::Output

Performs the unary - operation. Read more
Source§

impl Not for Uncertain<bool>

Source§

type Output = Uncertain<bool>

The resulting type after applying the ! operator.
Source§

fn not(self) -> <Uncertain<bool> as Not>::Output

Performs the unary ! operation. Read more
Source§

impl<T> PartialEq for Uncertain<T>

Source§

fn eq(&self, other: &Uncertain<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Sub for Uncertain<f64>

Source§

type Output = Uncertain<f64>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Uncertain<f64>) -> <Uncertain<f64> as Sub>::Output

Performs the - operation. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Uncertain<T>

§

impl<T> !RefUnwindSafe for Uncertain<T>

§

impl<T> Send for Uncertain<T>

§

impl<T> Sync for Uncertain<T>

§

impl<T> Unpin for Uncertain<T>
where T: Unpin,

§

impl<T> !UnwindSafe for Uncertain<T>

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<T> MulMagma for T
where T: Mul<Output = T> + Clone,