pub struct Geometric { /* private fields */ }
Expand description
Geometric distribution over x in {0, 1, 2, 3, … }.
§Example
use rv::prelude::*;
// Create Geometric(p=0.5)
let geom = Geometric::new(0.5).unwrap();
// Draw Samples
let mut rng = rand::thread_rng();
let xs: Vec<u32> = geom.sample(100, &mut rng);
assert_eq!(xs.len(), 100)
Implementations§
source§impl Geometric
impl Geometric
sourcepub fn new(p: f64) -> Result<Self, GeometricError>
pub fn new(p: f64) -> Result<Self, GeometricError>
Create a new geometric distribution
sourcepub fn new_unchecked(p: f64) -> Self
pub fn new_unchecked(p: f64) -> Self
Creates a new Geometric without checking whether the parameter is valid.
sourcepub fn set_p(&mut self, p: f64) -> Result<(), GeometricError>
pub fn set_p(&mut self, p: f64) -> Result<(), GeometricError>
Set the p parameter
§Example
let mut geom = Geometric::new(0.2).unwrap();
geom.set_p(0.5).unwrap();
assert_eq!(geom.p(), 0.5);
Will error for invalid values
assert!(geom.set_p(0.5).is_ok());
assert!(geom.set_p(1.0).is_ok());
assert!(geom.set_p(0.0).is_err());
assert!(geom.set_p(-1.0).is_err());
assert!(geom.set_p(1.1).is_err());
assert!(geom.set_p(f64::INFINITY).is_err());
assert!(geom.set_p(f64::NEG_INFINITY).is_err());
assert!(geom.set_p(f64::NAN).is_err());
sourcepub fn set_p_unchecked(&mut self, p: f64)
pub fn set_p_unchecked(&mut self, p: f64)
Set p without input validation
Trait Implementations§
source§impl<'de> Deserialize<'de> for Geometric
impl<'de> Deserialize<'de> for Geometric
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<X> DiscreteDistr<X> for Geometric
impl<X> DiscreteDistr<X> for Geometric
source§impl<X> HasDensity<X> for Geometric
impl<X> HasDensity<X> for Geometric
source§impl Parameterized for Geometric
impl Parameterized for Geometric
type Parameters = f64
fn emit_params(&self) -> Self::Parameters
fn from_params(p: Self::Parameters) -> Self
source§impl PartialEq for Geometric
impl PartialEq for Geometric
source§impl<X> Sampleable<X> for Geometric
impl<X> Sampleable<X> for Geometric
Auto Trait Implementations§
impl !Freeze for Geometric
impl RefUnwindSafe for Geometric
impl Send for Geometric
impl Sync for Geometric
impl Unpin for Geometric
impl UnwindSafe for Geometric
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.