pub struct Custom { /* private fields */ }Expand description
A non-negative loss severity defined by a user’s cdf (and optionally quantile) function.
use std::sync::Arc;
use prospicio_prob::{Custom, Distribution, Severity};
// An exponential with mean 100, given only by its cdf.
let cdf = Arc::new(|x: f64| Ok((1.0 - (-x / 100.0).exp()).max(0.0)));
let d = Custom::new("exponential", cdf, None, true).unwrap();
assert!((d.mean() - 100.0).abs() < 1e-6);
// E[min(X, 50)] = 100 (1 - e^-0.5).
assert!((d.lev(50.0) - 100.0 * (1.0 - (-0.5f64).exp())).abs() < 1e-9);
assert!((d.quantile(0.5).unwrap() - 100.0 * 2f64.ln()).abs() < 1e-9);Implementations§
Source§impl Custom
impl Custom
Sourcepub fn new(
name: impl Into<String>,
cdf: Callback,
quantile: Option<Callback>,
parallel_safe: bool,
) -> Result<Self>
pub fn new( name: impl Into<String>, cdf: Callback, quantile: Option<Callback>, parallel_safe: bool, ) -> Result<Self>
A severity from its cdf and, optionally, its quantile function.
parallel_safe says whether the callbacks may run on several
threads at once (true for a pure Rust closure; false for an R
function). Construction evaluates the cdf at the panel quantiles and
computes the mean and second moment, so a cdf that fails, leaves
[0, 1], decreases or never reaches 1 - 1e-12 is reported here.
Sourcepub fn has_quantile(&self) -> bool
pub fn has_quantile(&self) -> bool
Whether a quantile function was supplied (otherwise quantiles invert the cdf by bisection, about a hundred cdf calls each).
Trait Implementations§
Source§impl Distribution for Custom
impl Distribution for Custom
Source§fn is_parallel_safe(&self) -> bool
fn is_parallel_safe(&self) -> bool
Whether the distribution may be evaluated on several threads at
once. True for every native family; false for a
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 Severity for Custom
impl Severity for Custom
Source§fn stop_loss(&self, retention: f64) -> f64
fn stop_loss(&self, retention: f64) -> f64
∫_r^∞ S, integrated directly so far retentions keep their
precision.
Source§fn layer_second_moment(&self, limit: f64, attachment: f64) -> f64
fn layer_second_moment(&self, limit: f64, attachment: f64) -> f64
∫_a^{a+l} 2 (x - a) S(x) dx.
Auto Trait Implementations§
impl !RefUnwindSafe for Custom
impl !UnwindSafe for Custom
impl Freeze for Custom
impl Send for Custom
impl Sync for Custom
impl Unpin for Custom
impl UnsafeUnpin for Custom
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
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> ⓘ
Converts
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> ⓘ
Converts
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