[][src]Struct rstat::Probability

pub struct Probability(_);

Type representing the probability an event.

This struct is just a wrapper around f64 that strictly enforces that the probability lies in \([0, 1]\).

Methods

impl Probability[src]

pub fn new(p: f64) -> Result<Self, InvalidProbabilityError>[src]

Construct a probability, checking that the argument lies in \([0, 1]\).

Examples

use rstat::Probability;

// Invalid probabilities:
assert!(Probability::new(1.5).is_err());
assert!(Probability::new(-1.0).is_err());

// Valid probabilities:
assert!(Probability::new(0.0).is_ok());
assert!(Probability::new(0.5).is_ok());
assert!(Probability::new(1.0).is_ok());

pub fn new_unchecked(p: f64) -> Probability[src]

Construct a probability without checking for validity.

pub fn zero() -> Probability[src]

Returns a new Probability with value 0.

pub fn half() -> Probability[src]

Returns a new Probability with value 0.5.

pub fn one() -> Probability[src]

Returns a new Probability with value 1.

pub fn unwrap(self) -> f64[src]

Unwrap the probability and return the internal f64.

Examples

use rstat::Probability;

assert_eq!(Probability::half().unwrap(), 0.5);

pub fn is_valid(&self) -> bool[src]

Returns true if the probability lies in \([0, 1]\).

Examples

use rstat::Probability;

assert!(Probability::new_unchecked(0.5).is_valid());
assert!(!Probability::new_unchecked(10.0).is_valid());

pub fn ln(self) -> f64[src]

Return the natural logarithm of the probability: \(\ln{p}\).

Examples

use rstat::Probability;

assert_eq!(Probability::one().ln(), 0.0);

pub fn log2(self) -> f64[src]

Return the base-2 logarithm of the probability: \(\log_2{p}\).

Examples

use rstat::Probability;

assert_eq!(Probability::half().log2(), -1.0);

pub fn powf(self, e: f64) -> f64[src]

Return the probability raised to the power e: \(p^e\).

Examples

use rstat::Probability;

assert_eq!(Probability::half().powf(2.5), 0.1767766952966369);

pub fn powi(self, e: i32) -> f64[src]

Return the probability raised to the power e: \(p^e\).

Examples

use rstat::Probability;

assert_eq!(Probability::half().powi(2), 0.25);

Trait Implementations

impl<'a> Add<&'a Probability> for Probability[src]

type Output = Result<Probability, InvalidProbabilityError>

The resulting type after applying the + operator.

impl<'a, 'b> Add<&'a Probability> for &'b Probability[src]

type Output = Result<Probability, InvalidProbabilityError>

The resulting type after applying the + operator.

impl<'a> Add<&'a Probability> for f64[src]

type Output = f64

The resulting type after applying the + operator.

impl<'a, 'b> Add<&'a Probability> for &'b f64[src]

type Output = f64

The resulting type after applying the + operator.

impl<'a> Add<&'a f64> for Probability[src]

type Output = f64

The resulting type after applying the + operator.

impl<'a, 'b> Add<&'a f64> for &'b Probability[src]

type Output = f64

The resulting type after applying the + operator.

impl Add<Probability> for Probability[src]

type Output = Result<Probability, InvalidProbabilityError>

The resulting type after applying the + operator.

impl<'a> Add<Probability> for &'a Probability[src]

type Output = Result<Probability, InvalidProbabilityError>

The resulting type after applying the + operator.

impl Add<Probability> for f64[src]

type Output = f64

The resulting type after applying the + operator.

impl<'a> Add<Probability> for &'a f64[src]

type Output = f64

The resulting type after applying the + operator.

impl Add<f64> for Probability[src]

type Output = f64

The resulting type after applying the + operator.

impl<'a> Add<f64> for &'a Probability[src]

type Output = f64

The resulting type after applying the + operator.

impl Clone for Probability[src]

impl Copy for Probability[src]

impl Debug for Probability[src]

impl Default for Probability[src]

impl Display for Probability[src]

impl<'a> Div<&'a Probability> for Probability[src]

type Output = Result<Probability, InvalidProbabilityError>

The resulting type after applying the / operator.

impl<'a, 'b> Div<&'a Probability> for &'b Probability[src]

type Output = Result<Probability, InvalidProbabilityError>

The resulting type after applying the / operator.

impl<'a> Div<&'a Probability> for f64[src]

type Output = f64

The resulting type after applying the / operator.

impl<'a, 'b> Div<&'a Probability> for &'b f64[src]

type Output = f64

The resulting type after applying the / operator.

impl<'a> Div<&'a f64> for Probability[src]

type Output = f64

The resulting type after applying the / operator.

impl<'a, 'b> Div<&'a f64> for &'b Probability[src]

type Output = f64

The resulting type after applying the / operator.

impl Div<Probability> for Probability[src]

type Output = Result<Probability, InvalidProbabilityError>

The resulting type after applying the / operator.

impl<'a> Div<Probability> for &'a Probability[src]

type Output = Result<Probability, InvalidProbabilityError>

The resulting type after applying the / operator.

impl Div<Probability> for f64[src]

type Output = f64

The resulting type after applying the / operator.

impl<'a> Div<Probability> for &'a f64[src]

type Output = f64

The resulting type after applying the / operator.

impl Div<f64> for Probability[src]

type Output = f64

The resulting type after applying the / operator.

impl<'a> Div<f64> for &'a Probability[src]

type Output = f64

The resulting type after applying the / operator.

impl From<Probability> for f64[src]

impl<'a> Mul<&'a Probability> for Probability[src]

type Output = Probability

The resulting type after applying the * operator.

impl<'a, 'b> Mul<&'a Probability> for &'b Probability[src]

type Output = Probability

The resulting type after applying the * operator.

impl<'a> Mul<&'a Probability> for f64[src]

type Output = f64

The resulting type after applying the * operator.

impl<'a, 'b> Mul<&'a Probability> for &'b f64[src]

type Output = f64

The resulting type after applying the * operator.

impl<'a> Mul<&'a f64> for Probability[src]

type Output = f64

The resulting type after applying the * operator.

impl<'a, 'b> Mul<&'a f64> for &'b Probability[src]

type Output = f64

The resulting type after applying the * operator.

impl Mul<Probability> for Probability[src]

type Output = Probability

The resulting type after applying the * operator.

impl<'a> Mul<Probability> for &'a Probability[src]

type Output = Probability

The resulting type after applying the * operator.

impl Mul<Probability> for f64[src]

type Output = f64

The resulting type after applying the * operator.

impl<'a> Mul<Probability> for &'a f64[src]

type Output = f64

The resulting type after applying the * operator.

impl Mul<f64> for Probability[src]

type Output = f64

The resulting type after applying the * operator.

impl<'a> Mul<f64> for &'a Probability[src]

type Output = f64

The resulting type after applying the * operator.

impl Not for Probability[src]

type Output = Probability

The resulting type after applying the ! operator.

impl<'_> Not for &'_ Probability[src]

type Output = Probability

The resulting type after applying the ! operator.

impl Param for Probability[src]

type Value = f64

impl PartialEq<Probability> for Probability[src]

impl PartialEq<f64> for Probability[src]

impl PartialOrd<Probability> for Probability[src]

impl<'a> Rem<&'a Probability> for Probability[src]

type Output = Result<Probability, InvalidProbabilityError>

The resulting type after applying the % operator.

impl<'a, 'b> Rem<&'a Probability> for &'b Probability[src]

type Output = Result<Probability, InvalidProbabilityError>

The resulting type after applying the % operator.

impl<'a> Rem<&'a Probability> for f64[src]

type Output = f64

The resulting type after applying the % operator.

impl<'a, 'b> Rem<&'a Probability> for &'b f64[src]

type Output = f64

The resulting type after applying the % operator.

impl<'a> Rem<&'a f64> for Probability[src]

type Output = f64

The resulting type after applying the % operator.

impl<'a, 'b> Rem<&'a f64> for &'b Probability[src]

type Output = f64

The resulting type after applying the % operator.

impl Rem<Probability> for Probability[src]

type Output = Result<Probability, InvalidProbabilityError>

The resulting type after applying the % operator.

impl<'a> Rem<Probability> for &'a Probability[src]

type Output = Result<Probability, InvalidProbabilityError>

The resulting type after applying the % operator.

impl Rem<Probability> for f64[src]

type Output = f64

The resulting type after applying the % operator.

impl<'a> Rem<Probability> for &'a f64[src]

type Output = f64

The resulting type after applying the % operator.

impl Rem<f64> for Probability[src]

type Output = f64

The resulting type after applying the % operator.

impl<'a> Rem<f64> for &'a Probability[src]

type Output = f64

The resulting type after applying the % operator.

impl StructuralPartialEq for Probability[src]

impl<'a> Sub<&'a Probability> for Probability[src]

type Output = Result<Probability, InvalidProbabilityError>

The resulting type after applying the - operator.

impl<'a, 'b> Sub<&'a Probability> for &'b Probability[src]

type Output = Result<Probability, InvalidProbabilityError>

The resulting type after applying the - operator.

impl<'a> Sub<&'a Probability> for f64[src]

type Output = f64

The resulting type after applying the - operator.

impl<'a, 'b> Sub<&'a Probability> for &'b f64[src]

type Output = f64

The resulting type after applying the - operator.

impl<'a> Sub<&'a f64> for Probability[src]

type Output = f64

The resulting type after applying the - operator.

impl<'a, 'b> Sub<&'a f64> for &'b Probability[src]

type Output = f64

The resulting type after applying the - operator.

impl Sub<Probability> for Probability[src]

type Output = Result<Probability, InvalidProbabilityError>

The resulting type after applying the - operator.

impl<'a> Sub<Probability> for &'a Probability[src]

type Output = Result<Probability, InvalidProbabilityError>

The resulting type after applying the - operator.

impl Sub<Probability> for f64[src]

type Output = f64

The resulting type after applying the - operator.

impl<'a> Sub<Probability> for &'a f64[src]

type Output = f64

The resulting type after applying the - operator.

impl Sub<f64> for Probability[src]

type Output = f64

The resulting type after applying the - operator.

impl<'a> Sub<f64> for &'a Probability[src]

type Output = f64

The resulting type after applying the - operator.

impl<'a> Sum<&'a Probability> for f64[src]

impl Sum<Probability> for f64[src]

impl TryFrom<f64> for Probability[src]

type Error = InvalidProbabilityError

The type returned in the event of a conversion error.

Auto Trait Implementations

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, Rhs, Output> NumOps<Rhs, Output> for T where
    T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>, 
[src]

impl<T, Base> RefNum<Base> for T where
    T: NumOps<Base, Base> + for<'r> NumOps<&'r Base, Base>, 
[src]

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

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

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>,