Skip to main content

Empirical

Trait Empirical 

Source
pub trait Empirical: Distribution {
    // Required methods
    fn draws(&self) -> &[f64];
    fn sorted(&self) -> &[f64];

    // Provided methods
    fn mean_of(&self, f: impl Fn(f64) -> f64) -> f64 { ... }
    fn var(&self, p: f64) -> Result<f64> { ... }
    fn tvar(&self, p: f64) -> Result<f64> { ... }
    fn distortion(&self, d: &Distortion) -> f64 { ... }
}
Expand description

Operations that are exact on draws: any statistic of the empirical distribution.

Every result is exact for the draws and an estimate of the distribution they came from. Operations that are exact only on a parametric or discretized distribution (limited expected value, layers) are not offered here; a caller who wants an estimate from draws asks for it with Empirical::mean_of.

Required Methods§

Source

fn draws(&self) -> &[f64]

The draws, in the order they were simulated. Draw i came from simulation i, so two distributions from the same simulations can be paired draw by draw.

Source

fn sorted(&self) -> &[f64]

The draws sorted ascending.

Provided Methods§

Source

fn mean_of(&self, f: impl Fn(f64) -> f64) -> f64

Mean of f(x) over the draws.

use prospicio_prob::{Empirical, Sampled};

let s = Sampled::new(vec![50.0, 150.0, 400.0]).unwrap();
// Estimated limited expected value at 100.
assert_eq!(s.mean_of(|x| x.min(100.0)), 250.0 / 3.0);
Source

fn var(&self, p: f64) -> Result<f64>

Value at risk at level p; see var_sorted.

Source

fn tvar(&self, p: f64) -> Result<f64>

Tail value at risk at level p; see tvar_sorted.

Source

fn distortion(&self, d: &Distortion) -> f64

Distortion risk measure of the draws; see Distortion::apply_sorted.

use prospicio_prob::{Distortion, Empirical, Sampled};

let s = Sampled::new(vec![3.0, 1.0, 4.0, 2.0]).unwrap();
let tvar = Distortion::tvar(0.5).unwrap();
assert_eq!(s.distortion(&tvar), s.tvar(0.5).unwrap());

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§