pub fn estimate_true_error<T, F>(
tt: &TensorTrain<T>,
f: &F,
nsearch: usize,
initial_points: Option<Vec<MultiIndex>>,
rng: &mut impl Rng,
) -> Vec<(MultiIndex, f64)>Expand description
Estimate the true interpolation error by searching for worst-case indices.
Launches floating_zone from nsearch random starting points (or
from explicit initial_points), returning all found (pivot, error)
pairs sorted by descending error.
This is useful as a post-hoc check: if the largest returned error is below your tolerance, you can be more confident in the approximation.
§Examples
use tensor4all_tensorci::estimate_true_error;
use tensor4all_simplett::TensorTrain;
// Build a constant TT (value = 1.0) on a 4×4 grid
let tt = TensorTrain::<f64>::constant(&[4, 4], 1.0);
// Exact function differs from the constant
let f = |idx: &Vec<usize>| (idx[0] * idx[1]) as f64;
let mut rng = rand::rng();
let errors = estimate_true_error(&tt, &f, 10, None, &mut rng);
// Results are sorted by descending error
for w in errors.windows(2) {
assert!(w[0].1 >= w[1].1, "must be sorted descending");
}
// The worst-case error for |i*j - 1| on [0..4]x[0..4] is at (3,3): |9-1|=8
let (best_pivot, max_err) = &errors[0];
assert_eq!(*best_pivot, vec![3, 3]);
assert!((max_err - 8.0).abs() < 1e-10);§Arguments
tt– the tensor train approximationf– the exact functionnsearch– number of random starting points (ignored wheninitial_pointsisSome)initial_points– explicit starting points for the searchrng– random number generator
§Returns
Vec<(MultiIndex, f64)> sorted by descending error, with duplicate
pivots removed.