Skip to main content

optim_bandwidth

Function optim_bandwidth 

Source
pub fn optim_bandwidth(
    x: &[f64],
    y: &[f64],
    h_range: Option<(f64, f64)>,
    criterion: CvCriterion,
    kernel: &str,
    n_grid: usize,
) -> OptimBandwidthResult
Expand description

Bandwidth optimizer for kernel smoothers (R’s optim.np).

Grid search over evenly-spaced bandwidths, selecting the one that minimizes the specified criterion (CV or GCV).

§Arguments

  • x — Predictor values
  • y — Response values
  • h_range — Optional (h_min, h_max). Defaults to (h_default / 5, h_default * 5) where h_default = (x_max - x_min) / n^0.2.
  • criterion — CV or GCV
  • kernel — Kernel type
  • n_grid — Number of grid points (default: 50)

§Examples

use fdars_core::smoothing::{optim_bandwidth, CvCriterion};

let x: Vec<f64> = (0..25).map(|i| i as f64 / 24.0).collect();
let y: Vec<f64> = x.iter().map(|&xi| xi * xi).collect();
let result = optim_bandwidth(&x, &y, None, CvCriterion::Gcv, "gaussian", 20);
assert!(result.h_opt > 0.0);
assert!(result.value.is_finite());