Struct uncertain::PointMass[][src]

pub struct PointMass<T> where
    T: Clone
{ /* fields omitted */ }

An uncertain value which always yields the same value.

This type can be useful when fixed values should be conditionally returned e.g. from flat_map. If you only need a fixed value as part of an uncertain computation, consider using map.

Examples

Basic usage: conditional distribution.

use uncertain::{Uncertain, PointMass, Distribution};
use rand_distr::Normal;

let a = Distribution::from(Normal::new(2.0, 1.0).unwrap());
let b = a.flat_map(|a| if a < 1.5 {
    Distribution::from(Normal::new(0.0, 1.0).unwrap()).into_boxed()
} else {
    PointMass::new(1.0).into_boxed()
});
assert!(b.map(|b| b > 0.5).pr(0.9));

In most cases you can use map instead:

use uncertain::{Uncertain, PointMass, Distribution};
use rand_distr::StandardNormal;

let x = 1.0;
let y = Distribution::<f64, _>::from(StandardNormal).into_ref();
let a = PointMass::new(x).add(&y);
let b = (&y).map(|v: f64| v + x);
assert!(a.join(b, |a, b| a == b).pr(0.999));

Implementations

impl<T> PointMass<T> where
    T: Clone
[src]

pub fn new(value: T) -> Self[src]

Create a new PointMass centered on the given value.

Trait Implementations

impl<T: Clone> Clone for PointMass<T> where
    T: Clone
[src]

impl<T: Copy> Copy for PointMass<T> where
    T: Clone
[src]

impl<T> Uncertain for PointMass<T> where
    T: Clone
[src]

type Value = T

The type of the contained value.

Auto Trait Implementations

impl<T> RefUnwindSafe for PointMass<T> where
    T: RefUnwindSafe

impl<T> Send for PointMass<T> where
    T: Send

impl<T> Sync for PointMass<T> where
    T: Sync

impl<T> Unpin for PointMass<T> where
    T: Unpin

impl<T> UnwindSafe for PointMass<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,