pub struct Uniform { /* private fields */ }
Expand description
Continuous uniform distribution, U(a, b) on the interval x in [a, b]
§Example
The Uniform CDF is a line
use rv::prelude::*;
let u = Uniform::new(2.0, 4.0).unwrap();
// A line representing the CDF
let y = |x: f64| { 0.5 * x - 1.0 };
assert!((u.cdf(&3.0_f64) - y(3.0)).abs() < 1E-12);
assert!((u.cdf(&3.2_f64) - y(3.2)).abs() < 1E-12);
Implementations§
source§impl Uniform
impl Uniform
sourcepub fn new(a: f64, b: f64) -> Result<Self, UniformError>
pub fn new(a: f64, b: f64) -> Result<Self, UniformError>
Create a new uniform distribution on [a, b]
sourcepub fn new_unchecked(a: f64, b: f64) -> Self
pub fn new_unchecked(a: f64, b: f64) -> Self
Creates a new Uniform without checking whether the parameters are valid.
sourcepub fn set_a_unchecked(&mut self, a: f64)
pub fn set_a_unchecked(&mut self, a: f64)
Set the value of a without checking if a is valid
sourcepub fn set_b_unchecked(&mut self, b: f64)
pub fn set_b_unchecked(&mut self, b: f64)
Set the value of b without checking if b is valid
Trait Implementations§
source§impl ContinuousDistr<f32> for Uniform
impl ContinuousDistr<f32> for Uniform
source§impl ContinuousDistr<f64> for Uniform
impl ContinuousDistr<f64> for Uniform
source§impl<'de> Deserialize<'de> for Uniform
impl<'de> Deserialize<'de> for Uniform
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl HasDensity<f32> for Uniform
impl HasDensity<f32> for Uniform
source§impl HasDensity<f64> for Uniform
impl HasDensity<f64> for Uniform
source§impl InverseCdf<f32> for Uniform
impl InverseCdf<f32> for Uniform
source§impl InverseCdf<f64> for Uniform
impl InverseCdf<f64> for Uniform
source§impl Parameterized for Uniform
impl Parameterized for Uniform
type Parameters = (f64, f64)
fn emit_params(&self) -> Self::Parameters
fn from_params((a, b): Self::Parameters) -> Self
source§impl PartialEq for Uniform
impl PartialEq for Uniform
source§impl Sampleable<f32> for Uniform
impl Sampleable<f32> for Uniform
source§impl Sampleable<f64> for Uniform
impl Sampleable<f64> for Uniform
Auto Trait Implementations§
impl !Freeze for Uniform
impl RefUnwindSafe for Uniform
impl Send for Uniform
impl Sync for Uniform
impl Unpin for Uniform
impl UnwindSafe for Uniform
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self
from the equivalent element of its
superset. Read moresource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self
is actually part of its subset T
(and can be converted to it).source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset
but without any property checks. Always succeeds.source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self
to the equivalent element of its superset.