pub struct Cauchy { /* private fields */ }
Expand description
Cauchy distribution over x in (-∞, ∞).
§Example
use rv::prelude::*;
let cauchy = Cauchy::new(1.2, 3.4).expect("Invalid params");
let ln_fx = cauchy.ln_pdf(&0.2_f64); // -2.4514716152673368
assert!((ln_fx + 2.4514716152673368).abs() < 1E-12);
Implementations§
source§impl Cauchy
impl Cauchy
sourcepub fn new(loc: f64, scale: f64) -> Result<Self, CauchyError>
pub fn new(loc: f64, scale: f64) -> Result<Self, CauchyError>
Creates a new Cauchy distribution
§Arguments
- loc: location, x0, in (-∞, ∞)
- scale: scale, γ, in (0, ∞)
sourcepub fn new_unchecked(loc: f64, scale: f64) -> Self
pub fn new_unchecked(loc: f64, scale: f64) -> Self
Create a new Cauchy without checking whether the parameters are valid.
sourcepub fn loc(&self) -> f64
pub fn loc(&self) -> f64
Get the location parameter
§Example
let c = Cauchy::new(0.1, 1.0).unwrap();
assert_eq!(c.loc(), 0.1);
sourcepub fn set_loc(&mut self, loc: f64) -> Result<(), CauchyError>
pub fn set_loc(&mut self, loc: f64) -> Result<(), CauchyError>
Set the location parameter
§Example
let mut c = Cauchy::new(0.1, 1.0).unwrap();
assert_eq!(c.loc(), 0.1);
c.set_loc(2.0).unwrap();
assert_eq!(c.loc(), 2.0);
Will error for invalid parameters
assert!(c.set_loc(2.0).is_ok());
assert!(c.set_loc(std::f64::INFINITY).is_err());
assert!(c.set_loc(std::f64::NEG_INFINITY).is_err());
assert!(c.set_loc(std::f64::NAN).is_err());
sourcepub fn set_loc_unchecked(&mut self, loc: f64)
pub fn set_loc_unchecked(&mut self, loc: f64)
Set the location parameter without input validation
sourcepub fn scale(&self) -> f64
pub fn scale(&self) -> f64
Get the scale parameter
§Example
let c = Cauchy::new(0.1, 1.0).unwrap();
assert_eq!(c.scale(), 1.0);
sourcepub fn set_scale(&mut self, scale: f64) -> Result<(), CauchyError>
pub fn set_scale(&mut self, scale: f64) -> Result<(), CauchyError>
Set the scale parameter
§Example
let mut c = Cauchy::new(0.1, 1.0).unwrap();
assert_eq!(c.scale(), 1.0);
c.set_scale(2.1).unwrap();
assert_eq!(c.scale(), 2.1);
Will error for invalid scale.
assert!(c.set_scale(0.0).is_err());
assert!(c.set_scale(-1.0).is_err());
assert!(c.set_scale(std::f64::NAN).is_err());
assert!(c.set_scale(std::f64::INFINITY).is_err());
sourcepub fn set_scale_unchecked(&mut self, scale: f64)
pub fn set_scale_unchecked(&mut self, scale: f64)
Set scale parameter without input validation
Trait Implementations§
source§impl ContinuousDistr<f32> for Cauchy
impl ContinuousDistr<f32> for Cauchy
source§impl ContinuousDistr<f64> for Cauchy
impl ContinuousDistr<f64> for Cauchy
source§impl<'de> Deserialize<'de> for Cauchy
impl<'de> Deserialize<'de> for Cauchy
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 InverseCdf<f32> for Cauchy
impl InverseCdf<f32> for Cauchy
source§impl InverseCdf<f64> for Cauchy
impl InverseCdf<f64> for Cauchy
source§impl PartialEq for Cauchy
impl PartialEq for Cauchy
source§impl Rv<f32> for Cauchy
impl Rv<f32> for Cauchy
source§impl Rv<f64> for Cauchy
impl Rv<f64> for Cauchy
impl StructuralPartialEq for Cauchy
Auto Trait Implementations§
impl Freeze for Cauchy
impl RefUnwindSafe for Cauchy
impl Send for Cauchy
impl Sync for Cauchy
impl Unpin for Cauchy
impl UnwindSafe for Cauchy
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<Fx> Rv<Datum> for Fxwhere
Fx: RvDatum,
impl<Fx> Rv<Datum> for Fxwhere
Fx: RvDatum,
source§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.