mod d;
mod p;
mod q;
mod r;
use strafe_type::{LogProbability64, Natural64, Probability64, Real64};
pub(crate) use self::{d::*, p::*, q::*, r::*};
use crate::traits::{Distribution, RNG};
#[cfg_attr(feature = "doc_outputs", cfg_attr(all(), doc = embed_doc_image::embed_image!("density", "src/distribution/cauchy/doctest_out/density.svg")))]
#[cfg_attr(feature = "doc_outputs", cfg_attr(all(), doc = "![Density][density]"))]
#[cfg_attr(feature = "doc_outputs", cfg_attr(all(), doc = include_str!("doctest_out/density.md")))]
pub struct Cauchy {
location: Real64,
scale: Natural64,
}
impl Distribution for Cauchy {
fn density<R: Into<Real64>>(&self, x: R) -> Real64 {
dcauchy(x, self.location, self.scale, false)
}
fn log_density<R: Into<Real64>>(&self, x: R) -> Real64 {
dcauchy(x, self.location, self.scale, true)
}
fn probability<R: Into<Real64>>(&self, q: R, lower_tail: bool) -> Probability64 {
pcauchy(q, self.location, self.scale, lower_tail)
}
fn log_probability<R: Into<Real64>>(&self, q: R, lower_tail: bool) -> LogProbability64 {
log_pcauchy(q, self.location, self.scale, lower_tail)
}
fn quantile<P: Into<Probability64>>(&self, p: P, lower_tail: bool) -> Real64 {
qcauchy(p, self.location, self.scale, lower_tail)
}
fn log_quantile<LP: Into<LogProbability64>>(&self, p: LP, lower_tail: bool) -> Real64 {
log_qcauchy(p, self.location, self.scale, lower_tail)
}
fn random_sample<R: RNG>(&self, rng: &mut R) -> Real64 {
rcauchy(self.location, self.scale, rng)
}
}
pub struct CauchyBuilder {
location: Option<Real64>,
scale: Option<Natural64>,
}
impl CauchyBuilder {
pub fn new() -> Self {
Self {
location: None,
scale: None,
}
}
pub fn with_location<R: Into<Real64>>(&mut self, location: R) -> &mut Self {
self.location = Some(location.into());
self
}
pub fn with_scale<N: Into<Natural64>>(&mut self, scale: N) -> &mut Self {
self.scale = Some(scale.into());
self
}
pub fn build(&self) -> Cauchy {
let location = self.location.unwrap_or(0.0.into());
let scale = self.scale.unwrap_or(1.0.into());
Cauchy { location, scale }
}
}
#[cfg(test)]
mod tests;
#[cfg(all(test, feature = "enable_proptest"))]
mod proptests;
#[cfg(all(test, feature = "enable_covtest"))]
mod covtests;