// Copyright 2021 Developers of the Rand project. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // https://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your // option. This file may not be copied, modified, or distributed // except according to those terms.
//! The Fréchet distribution.
usecrate::{Distribution, OpenClosed01}; use core::fmt; use num_traits::Float; use rand::Rng;
/// Samples floating-point numbers according to the Fréchet distribution /// /// This distribution has density function: /// `f(x) = [(x - μ) / σ]^(-1 - α) exp[-(x - μ) / σ]^(-α) α / σ`, /// where `μ` is the location parameter, `σ` the scale parameter, and `α` the shape parameter. /// /// # Example /// ``` /// use rand::prelude::*; /// use rand_distr::Frechet; /// /// let val: f64 = thread_rng().sample(Frechet::new(0.0, 1.0, 1.0).unwrap()); /// println!("{}", val); /// ``` #[derive(Clone, Copy, Debug)] #[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))] pubstruct Frechet<F> where
F: Float,
OpenClosed01: Distribution<F>,
{
location: F,
scale: F,
shape: F,
}
/// Error type returned from `Frechet::new`. #[derive(Clone, Copy, Debug, PartialEq, Eq)] pubenum Error { /// location is infinite or NaN
LocationNotFinite, /// scale is not finite positive number
ScaleNotPositive, /// shape is not finite positive number
ShapeNotPositive,
}
impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(matchself {
Error::LocationNotFinite => "location is not finite in Frechet distribution",
Error::ScaleNotPositive => "scale is not positive and finite in Frechet distribution",
Error::ShapeNotPositive => "shape is not positive and finite in Frechet distribution",
})
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.