pub struct VonMises { /* private fields */ }
Expand description
VonMises distribution on the circular interval (0, 2π]
§Example
use rv::prelude::*;
let vm = VonMises::new(1.0, 2.0).unwrap();
// x is in (0, 2π]
assert!(!vm.supports(&-0.001_f64));
assert!(!vm.supports(&6.3_f64));
// 103 VonMises draws
let mut rng = rand::thread_rng();
let xs: Vec<f64> = vm.sample(103, &mut rng);
assert_eq!(xs.len(), 103);
Implementations§
source§impl VonMises
impl VonMises
sourcepub fn new(mu: f64, k: f64) -> Result<Self, VonMisesError>
pub fn new(mu: f64, k: f64) -> Result<Self, VonMisesError>
Create a new VonMises distribution with mean mu, and precision, k.
sourcepub fn new_unchecked(mu: f64, k: f64) -> Self
pub fn new_unchecked(mu: f64, k: f64) -> Self
Creates a new VonMises without checking whether the parameters are valid.
sourcepub fn mu(&self) -> f64
pub fn mu(&self) -> f64
Get the mean parameter, mu
§Example
let vm = VonMises::new(0.0, 1.0).unwrap();
assert_eq!(vm.mu(), 0.0);
sourcepub fn set_mu(&mut self, mu: f64) -> Result<(), VonMisesError>
pub fn set_mu(&mut self, mu: f64) -> Result<(), VonMisesError>
Set the value of mu
§Example
use rv::dist::VonMises;
let mut vm = VonMises::new(2.0, 1.5).unwrap();
assert_eq!(vm.mu(), 2.0);
vm.set_mu(1.3).unwrap();
assert_eq!(vm.mu(), 1.3);
Will error for invalid values
assert!(vm.set_mu(1.3).is_ok());
assert!(vm.set_mu(0.0).is_ok());
assert!(vm.set_mu(2.0 * std::f64::consts::PI).is_ok());
assert!(vm.set_mu(0.0 - 0.001).is_err());
assert!(vm.set_mu(2.0 * std::f64::consts::PI + 0.001).is_err());
assert!(vm.set_mu(f64::NEG_INFINITY).is_err());
assert!(vm.set_mu(f64::INFINITY).is_err());
assert!(vm.set_mu(f64::NAN).is_err());
sourcepub fn set_mu_unchecked(&mut self, mu: f64)
pub fn set_mu_unchecked(&mut self, mu: f64)
Set the value of mu without input validation
sourcepub fn k(&self) -> f64
pub fn k(&self) -> f64
Get the precision parameter, k
§Example
let vm = VonMises::new(0.0, 1.0).unwrap();
assert_eq!(vm.k(), 1.0);
sourcepub fn set_k(&mut self, k: f64) -> Result<(), VonMisesError>
pub fn set_k(&mut self, k: f64) -> Result<(), VonMisesError>
Set the value of k
§Example
let mut vm = VonMises::new(0.0, 1.0).unwrap();
let v1: f64 = vm.variance().unwrap();
assert::close(v1, 0.5536100341034653, 1E-10);
vm.set_mu(0.2);
vm.set_k(2.0);
let v2: f64 = vm.variance().unwrap();
assert::close(v2, 0.3022253420359917, 1E-10);
Will error for invalid values
assert!(vm.set_k(0.1).is_ok());
// Must be greater than zero
assert!(vm.set_k(0.0).is_err());
assert!(vm.set_k(-1.0).is_err());
assert!(vm.set_k(f64::INFINITY).is_err());
assert!(vm.set_k(f64::NEG_INFINITY).is_err());
assert!(vm.set_k(f64::NAN).is_err());
sourcepub fn set_k_unchecked(&mut self, k: f64)
pub fn set_k_unchecked(&mut self, k: f64)
Set the value of k without input validation
Trait Implementations§
source§impl ContinuousDistr<f32> for VonMises
impl ContinuousDistr<f32> for VonMises
source§impl ContinuousDistr<f64> for VonMises
impl ContinuousDistr<f64> for VonMises
source§impl<'de> Deserialize<'de> for VonMises
impl<'de> Deserialize<'de> for VonMises
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 VonMises
impl HasDensity<f32> for VonMises
source§impl HasDensity<f64> for VonMises
impl HasDensity<f64> for VonMises
source§impl Parameterized for VonMises
impl Parameterized for VonMises
type Parameters = VonMisesParameters
fn emit_params(&self) -> Self::Parameters
fn from_params(params: Self::Parameters) -> Self
source§impl PartialEq for VonMises
impl PartialEq for VonMises
source§impl Sampleable<f32> for VonMises
impl Sampleable<f32> for VonMises
source§impl Sampleable<f64> for VonMises
impl Sampleable<f64> for VonMises
impl StructuralPartialEq for VonMises
Auto Trait Implementations§
impl Freeze for VonMises
impl RefUnwindSafe for VonMises
impl Send for VonMises
impl Sync for VonMises
impl Unpin for VonMises
impl UnwindSafe for VonMises
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.