pub fn local_pareto_to_piecewise(
t: f64,
alpha: impl Fn(f64) -> f64,
options: LocalParetoConversion,
) -> Result<LocalParetoApproximation>Expand description
Converts the local Pareto distribution with local alpha alpha(x) above
the threshold t (and P(X > x) = 1 below it) to a piecewise Pareto.
With L = ln(x/t), ln S = −A(L) where A(L) = ∫_0^L α(t e^v) dv. A
piecewise Pareto is a chord interpolant of A that matches S exactly
at its thresholds, so its relative error in S on a piece is
exp(d) − 1 with d the gap between A and its chord. Pieces are
grown greedily, each as long as possible with that error within
rel_tolerance at 16 checked interior points, A coming from 8-point
Gauss–Legendre integration. The conversion stops at
options.stop_at or where S falls below options.stop_survival, and
the local alpha there continues as the tail. alpha must be finite and
non-negative, and positive at the end.
use prospicio_prob::{Distribution, LogAffinePareto, local_pareto_to_piecewise, LocalParetoConversion};
let exact = LogAffinePareto::new(1000.0, 1.5, 0.4).unwrap();
let approx = local_pareto_to_piecewise(1000.0, |x| exact.local_alpha(x),
LocalParetoConversion::default()).unwrap();
let x = 7_777.0;
assert!((approx.severity.survival(x) / exact.survival(x) - 1.0).abs() < 1e-4);