Skip to main content

lqd_transform

Function lqd_transform 

Source
pub fn lqd_transform(
    density: &[f64],
    argvals: &[f64],
    n_quantile_pts: Option<usize>,
) -> Result<Vec<f64>, FdarError>
Expand description

Log-quantile-density (LQD) forward transform.

Maps a probability density density sampled on argvals (a physical grid in density space) to the LQD representation ψ on a uniform quantile grid t ∈ [0, 1] of length n_quantile_pts.

The LQD is defined as ψ(t) = log q(t) = −log f(Q(t)), where Q is the quantile function and q = dQ/dt is the quantile density.

Numeric chain (matching fdadensity::dens2lqd):

  1. Normalize density.
  2. Compute CDF via cumulative_trapz (starts at 0).
  3. Compute lqd_raw[i] = −log(density_norm[i]) on the physical grid.
  4. Interpolate (x = CDF, y = lqd_raw) onto the uniform t-grid via linear_interp.

§Arguments

  • density — strictly positive density values on argvals.
  • argvals — strictly increasing evaluation grid.
  • n_quantile_pts — length of the output quantile grid (default: argvals.len().max(101)).

§Errors

Returns FdarError::InvalidParameter if any density value is ≤ 0 (since −log(0) = +∞), if argvals is not strictly increasing, or if any output ψ value is non-finite (NaN or ±∞). Returns FdarError::InvalidDimension for length mismatches.

§Example

use fdars_core::density_fda::lqd_transform;
let argvals: Vec<f64> = (0..51).map(|i| i as f64 / 50.0).collect();
let uniform = vec![1.0_f64; 51];
let psi = lqd_transform(&uniform, &argvals, Some(51)).unwrap();
// ψ ≡ 0 for uniform density
assert!(psi.iter().all(|&v| v.abs() < 1e-5));