Skip to main content

Uncertain

Struct Uncertain 

Source
pub struct Uncertain<S: Scalar> {
    pub mean: S,
    pub variance: S,
}
Expand description

An uncertain value with mean and variance.

§Example

use numra_core::uncertainty::Uncertain;

// A measurement of 10.0 ± 0.5 (std dev)
let x: Uncertain<f64> = Uncertain::new(10.0, 0.25); // variance = 0.5²

// Scale by 2: mean scales, variance scales by 4
let y = x.scale(2.0);
assert!((y.mean - 20.0).abs() < 1e-10);
assert!((y.variance - 1.0).abs() < 1e-10);

Fields§

§mean: S

Mean value

§variance: S

Variance (σ²)

Implementations§

Source§

impl<S: Scalar> Uncertain<S>

Source

pub fn new(mean: S, variance: S) -> Self

Create a new uncertain value.

Source

pub fn from_std(mean: S, std: S) -> Self

Create from mean and standard deviation.

Source

pub fn certain(value: S) -> Self

Create a certain value (zero variance).

Source

pub fn std(&self) -> S

Standard deviation.

Source

pub fn cv(&self) -> S

Coefficient of variation (std/mean).

Source

pub fn scale(&self, a: S) -> Self

Scale by a constant: y = a*x. Variance scales by a².

Source

pub fn add_const(&self, c: S) -> Self

Add a constant: y = x + c. Variance unchanged.

Source

pub fn add(&self, other: &Self) -> Self

Add another uncertain value (assuming independence). y = x1 + x2, Var(y) = Var(x1) + Var(x2).

Source

pub fn sub(&self, other: &Self) -> Self

Subtract another uncertain value (assuming independence).

Source

pub fn mul(&self, other: &Self) -> Self

Multiply by another uncertain value (first-order approximation). For y = x1 * x2: E[y] ≈ E[x1] * E[x2] Var(y) ≈ E[x2]² * Var(x1) + E[x1]² * Var(x2)

Source

pub fn div(&self, other: &Self) -> Self

Divide by another uncertain value (first-order approximation). For y = x1 / x2: E[y] ≈ E[x1] / E[x2] Var(y) ≈ (1/E[x2]²) * Var(x1) + (E[x1]/E[x2]²)² * Var(x2)

Source

pub fn apply<F, D>(&self, f: F, df: D) -> Self
where F: Fn(S) -> S, D: Fn(S) -> S,

Apply a function with known derivative. For y = f(x): Var(y) ≈ (f’(x))² * Var(x).

Source

pub fn square(&self) -> Self

Square: y = x².

Source

pub fn sqrt_unc(&self) -> Self

Square root: y = √x.

Source

pub fn exp(&self) -> Self

Exponential: y = e^x.

Source

pub fn ln(&self) -> Self

Natural log: y = ln(x).

Source

pub fn sin(&self) -> Self

Sine: y = sin(x).

Source

pub fn cos(&self) -> Self

Cosine: y = cos(x).

Trait Implementations§

Source§

impl<S: Clone + Scalar> Clone for Uncertain<S>

Source§

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

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<S: Debug + Scalar> Debug for Uncertain<S>

Source§

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

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

impl<S: Scalar> Default for Uncertain<S>

Source§

fn default() -> Self

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

impl<S: PartialEq + Scalar> PartialEq for Uncertain<S>

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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<S: Copy + Scalar> Copy for Uncertain<S>

Source§

impl<S: Scalar> StructuralPartialEq for Uncertain<S>

Auto Trait Implementations§

§

impl<S> Freeze for Uncertain<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for Uncertain<S>
where S: RefUnwindSafe,

§

impl<S> Send for Uncertain<S>

§

impl<S> Sync for Uncertain<S>

§

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

§

impl<S> UnsafeUnpin for Uncertain<S>
where S: UnsafeUnpin,

§

impl<S> UnwindSafe for Uncertain<S>
where S: 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 = 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.