pub struct Uncertain<T>where
T: ProbabilisticType,{ /* private fields */ }Expand description
A type representing a value with inherent uncertainty, modeled as a probability distribution.
Implementations§
Source§impl Uncertain<bool>
impl Uncertain<bool>
Sourcepub fn point(value: bool) -> Uncertain<bool>
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.
Sourcepub fn bernoulli(p: f64) -> Uncertain<bool>
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.
Sourcepub fn to_bool(
&self,
threshold: f64,
confidence: f64,
epsilon: f64,
max_samples: usize,
) -> Result<bool, UncertainError>
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.
Sourcepub fn probability_exceeds(
&self,
threshold: f64,
confidence: f64,
epsilon: f64,
max_samples: usize,
) -> Result<bool, UncertainError>
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).
Sourcepub fn implicit_conditional(&self) -> Result<bool, UncertainError>
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.
Sourcepub fn estimate_probability(
&self,
num_samples: usize,
) -> Result<f64, UncertainError>
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>
impl Uncertain<f64>
pub fn point(value: f64) -> Uncertain<f64>
pub fn normal(mean: f64, std_dev: f64) -> Uncertain<f64>
pub fn uniform(low: f64, high: f64) -> Uncertain<f64>
pub fn from_samples(samples: &[f64]) -> Uncertain<f64>
pub fn estimate_probability_exceeds( &self, threshold: f64, num_samples: usize, ) -> Result<f64, UncertainError>
pub fn map<F>(&self, func: F) -> Uncertain<f64>
pub fn map_to_bool<F>(&self, func: F) -> Uncertain<bool>
Source§impl Uncertain<f64>
impl Uncertain<f64>
pub fn greater_than(&self, threshold: f64) -> Uncertain<bool>
pub fn less_than(&self, threshold: f64) -> Uncertain<bool>
pub fn equals(&self, threshold: f64) -> Uncertain<bool>
pub fn gt_uncertain(&self, other: &Uncertain<f64>) -> Uncertain<bool>
pub fn lt_uncertain(&self, other: &Uncertain<f64>) -> Uncertain<bool>
pub fn eq_uncertain(&self, other: &Uncertain<f64>) -> Uncertain<bool>
Source§impl Uncertain<f64>
impl Uncertain<f64>
pub fn sample_with_index( &self, sample_index: u64, ) -> Result<f64, UncertainError>
pub fn sample(&self) -> Result<f64, UncertainError>
pub fn take_samples(&self, n: usize) -> Result<Vec<f64>, UncertainError>
Source§impl Uncertain<bool>
impl Uncertain<bool>
pub fn sample_with_index( &self, sample_index: u64, ) -> Result<bool, UncertainError>
pub fn sample(&self) -> Result<bool, UncertainError>
pub fn take_samples(&self, n: usize) -> Result<Vec<bool>, UncertainError>
Source§impl Uncertain<f64>
impl Uncertain<f64>
Sourcepub fn expected_value(&self, num_samples: usize) -> Result<f64, UncertainError>
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.
Sourcepub fn standard_deviation(
&self,
num_samples: usize,
) -> Result<f64, UncertainError>
pub fn standard_deviation( &self, num_samples: usize, ) -> Result<f64, UncertainError>
Estimates the standard deviation of the uncertain f64 value by taking multiple samples.