// 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 Gumbel distribution.
usecrate::{Distribution, OpenClosed01}; use core::fmt; use num_traits::Float; use rand::Rng;
/// Samples floating-point numbers according to the Gumbel distribution /// /// This distribution has density function: /// `f(x) = exp(-(z + exp(-z))) / σ`, where `z = (x - μ) / σ`, /// `μ` is the location parameter, and `σ` the scale parameter. /// /// # Example /// ``` /// use rand::prelude::*; /// use rand_distr::Gumbel; /// /// let val: f64 = thread_rng().sample(Gumbel::new(0.0, 1.0).unwrap()); /// println!("{}", val); /// ``` #[derive(Clone, Copy, Debug)] #[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))] pubstruct Gumbel<F> where
F: Float,
OpenClosed01: Distribution<F>,
{
location: F,
scale: F,
}
/// Error type returned from `Gumbel::new`. #[derive(Clone, Copy, Debug, PartialEq, Eq)] pubenum Error { /// location is infinite or NaN
LocationNotFinite, /// scale is not finite positive number
ScaleNotPositive,
}
impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(matchself {
Error::ScaleNotPositive => "scale is not positive and finite in Gumbel distribution",
Error::LocationNotFinite => "location is not finite in Gumbel 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.