pub enum Dist {
Show 13 variants
Lognormal(Lognormal),
Pareto(Pareto),
PiecewisePareto(PiecewisePareto),
LogAffinePareto(LogAffinePareto),
GeneralizedPareto(Gpd),
Gamma(Gamma),
Tweedie(Tweedie),
Weibull(Weibull),
Loglogistic(Loglogistic),
Mixture(Arc<Mixture>),
Grid(Grid),
Sampled(Sampled),
Custom(Custom),
}Expand description
Any native univariate distribution.
Every variant is a Distribution; all but Dist::Sampled are also
a Severity, which Dist::as_severity exposes. A Mixture is held
in an Arc (its components are trait objects), so cloning a Dist
never copies one.
use prospicio_prob::{Dist, Distribution, Lognormal, Sampled};
let dists = vec![
Dist::from(Lognormal::from_mean_cv(1000.0, 0.5).unwrap()),
Dist::from(Sampled::new(vec![800.0, 1000.0, 1200.0]).unwrap()),
];
for d in &dists {
assert!((d.mean() - 1000.0).abs() < 1e-9);
}
// Limited expected values exist for the parametric family only.
assert!(dists[0].as_severity().is_some());
assert!(dists[1].as_severity().is_none());Variants§
Lognormal(Lognormal)
Pareto(Pareto)
PiecewisePareto(PiecewisePareto)
LogAffinePareto(LogAffinePareto)
GeneralizedPareto(Gpd)
Gamma(Gamma)
Tweedie(Tweedie)
Weibull(Weibull)
Loglogistic(Loglogistic)
Mixture(Arc<Mixture>)
Grid(Grid)
Sampled(Sampled)
Custom(Custom)
A user-defined severity (a Python or R callback): the slow path.
Implementations§
Source§impl Dist
impl Dist
Sourcepub fn family(&self) -> &'static str
pub fn family(&self) -> &'static str
Short name of the family: "lognormal", "pareto",
"piecewise_pareto", "log_affine_pareto", "generalized_pareto",
"gamma", "tweedie", "weibull", "loglogistic", "mixture",
"grid", "sampled" or "custom".
Sourcepub fn as_severity(&self) -> Option<&(dyn Severity + Send + Sync)>
pub fn as_severity(&self) -> Option<&(dyn Severity + Send + Sync)>
The distribution as a Severity (limited expected values, layers),
or None for Dist::Sampled: draws have no exact layer moments
(docs/design/distributions.md).
Source§impl Dist
impl Dist
Sourcepub fn to_json(&self) -> Result<String>
pub fn to_json(&self) -> Result<String>
The distribution as a JSON document; from_json
reads it back to an equal distribution.
Fails for a Custom (a function in the caller’s
language) and for a mixture built from trait objects rather than
with Mixture::from_dists.
use prospicio_prob::{Dist, Distribution, Lognormal};
let d = Dist::from(Lognormal::new(7.0, 0.5).unwrap());
let back = Dist::from_json(&d.to_json().unwrap()).unwrap();
assert_eq!(back.family(), "lognormal");
assert_eq!(back.mean(), d.mean());Trait Implementations§
Source§impl Distribution for Dist
impl Distribution for Dist
Source§fn survival(&self, x: f64) -> f64
fn survival(&self, x: f64) -> f64
P(X > x). Representations with a direct form override the
default 1 - cdf(x), which loses all precision far in the tail.Source§fn sample(&self, rng: &mut StreamRng, n: usize) -> Vec<f64>
fn sample(&self, rng: &mut StreamRng, n: usize) -> Vec<f64>
n draws from stream rng, by inverse transform unless the family
overrides it (crate::Gamma draws by Marsaglia and Tsang). Read moreSource§fn is_parallel_safe(&self) -> bool
fn is_parallel_safe(&self) -> bool
crate::Custom
whose callbacks must stay on the calling thread (an R function), so
the parallel simulations run single-threaded when they meet one.Source§impl From<LogAffinePareto> for Dist
impl From<LogAffinePareto> for Dist
Source§fn from(d: LogAffinePareto) -> Self
fn from(d: LogAffinePareto) -> Self
Source§impl From<Loglogistic> for Dist
impl From<Loglogistic> for Dist
Source§fn from(d: Loglogistic) -> Self
fn from(d: Loglogistic) -> Self
Source§impl From<PiecewisePareto> for Dist
impl From<PiecewisePareto> for Dist
Source§fn from(d: PiecewisePareto) -> Self
fn from(d: PiecewisePareto) -> Self
Source§impl From<SeverityDist> for Dist
impl From<SeverityDist> for Dist
Source§fn from(s: SeverityDist) -> Self
fn from(s: SeverityDist) -> Self
Auto Trait Implementations§
impl !RefUnwindSafe for Dist
impl !UnwindSafe for Dist
impl Freeze for Dist
impl Send for Dist
impl Sync for Dist
impl Unpin for Dist
impl UnsafeUnpin for Dist
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> ⓘ
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> ⓘ
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 more