pub struct Mixture { /* private fields */ }Expand description
A severity drawn from component i with probability w_i: attritional
and large losses in one model, or a book of mixed risks.
Every quantity that is linear in the distribution (distribution function, survival, limited expected values, layer moments) is the weighted sum of the components’; the variance follows the law of total variance; quantiles bisect the distribution function.
use prospicio_prob::{Distribution, Lognormal, Mixture, Pareto, Severity};
let m = Mixture::new(vec![
(0.9, Box::new(Lognormal::from_mean_cv(1e4, 1.0).unwrap()) as Box<dyn Severity + Send + Sync>),
(0.1, Box::new(Pareto::new(1e5, 2.0).unwrap())),
])
.unwrap();
assert!((m.mean() - (0.9 * 1e4 + 0.1 * 2e5)).abs() < 1e-6);
// Above 1e5 only the large losses reach: 0.1 × 2e5.
assert!(m.layer(f64::INFINITY, 1e5) > 0.1 * 1e5);Implementations§
Source§impl Mixture
impl Mixture
Sourcepub fn new(parts: Vec<(f64, Box<dyn Severity + Send + Sync>)>) -> Result<Self>
pub fn new(parts: Vec<(f64, Box<dyn Severity + Send + Sync>)>) -> Result<Self>
A mixture of (weight, component) pairs. Weights must be positive
and sum to 1 within 1e-12.
Sourcepub fn from_dists(parts: Vec<(f64, SeverityDist)>) -> Result<Self>
pub fn from_dists(parts: Vec<(f64, SeverityDist)>) -> Result<Self>
A mixture of (weight, component) pairs of native severities. It
behaves as Mixture::new, and also keeps the components as
SeverityDists, so it can be saved (crate::Dist::to_json).
Sourcepub fn dists(&self) -> Option<&[SeverityDist]>
pub fn dists(&self) -> Option<&[SeverityDist]>
The components as SeverityDists, when built by
Mixture::from_dists.
Trait Implementations§
Source§impl Distribution for Mixture
impl Distribution for Mixture
Source§fn quantile(&self, p: f64) -> Result<f64>
fn quantile(&self, p: f64) -> Result<f64>
The smallest x with F(x) >= p, bracketed by the components’
quantiles and bisected (on the survival function above the median).
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 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 Severity for Mixture
impl Severity for Mixture
Source§fn stop_loss(&self, retention: f64) -> f64
fn stop_loss(&self, retention: f64) -> f64
E[max(X - retention, 0)].Source§fn layer(&self, limit: f64, attachment: f64) -> f64
fn layer(&self, limit: f64, attachment: f64) -> f64
limit xs attachment,
E[min(max(X - attachment, 0), limit)].Auto Trait Implementations§
impl !RefUnwindSafe for Mixture
impl !UnwindSafe for Mixture
impl Freeze for Mixture
impl Send for Mixture
impl Sync for Mixture
impl Unpin for Mixture
impl UnsafeUnpin for Mixture
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> 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