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: SMean value
variance: SVariance (σ²)
Implementations§
Source§impl<S: Scalar> Uncertain<S>
impl<S: Scalar> Uncertain<S>
Sourcepub fn add(&self, other: &Self) -> Self
pub fn add(&self, other: &Self) -> Self
Add another uncertain value (assuming independence). y = x1 + x2, Var(y) = Var(x1) + Var(x2).
Sourcepub fn sub(&self, other: &Self) -> Self
pub fn sub(&self, other: &Self) -> Self
Subtract another uncertain value (assuming independence).
Sourcepub fn mul(&self, other: &Self) -> Self
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)
Sourcepub fn div(&self, other: &Self) -> Self
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)
Trait Implementations§
Source§impl<S: PartialEq + Scalar> PartialEq for Uncertain<S>
impl<S: PartialEq + Scalar> PartialEq for Uncertain<S>
impl<S: Copy + Scalar> Copy for Uncertain<S>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more