Skip to main content

floating_zone

Function floating_zone 

Source
pub fn floating_zone<T, F>(
    tt: &TensorTrain<T>,
    f: &F,
    local_dims: &[usize],
    init_p: Option<&MultiIndex>,
    early_stop_tol: f64,
) -> (MultiIndex, f64)
where T: Scalar + TTScalar, F: Fn(&MultiIndex) -> T,
Expand description

Local search for the multi-index with the largest interpolation error.

Starting from init_p, sweeps through each site position, evaluating all local indices while fixing the others, and picks the index with the maximum error |f(idx) - tt(idx)|. Repeats until the error stops increasing or early_stop_tol is exceeded.

§Examples

use tensor4all_tensorci::floating_zone;
use tensor4all_simplett::TensorTrain;

// Constant TT (value = 0.0) on a 4×4 grid
let tt = TensorTrain::<f64>::constant(&[4, 4], 0.0);

// f(i,j) = i * j, so TT error = |i*j|
let f = |idx: &Vec<usize>| (idx[0] * idx[1]) as f64;
let local_dims = vec![4, 4];

// Search from (2, 2) without early stopping
let (pivot, error) = floating_zone(&tt, &f, &local_dims, Some(&vec![2, 2]), f64::MAX);

// Should find maximum error at (3, 3): |3*3 - 0| = 9
assert_eq!(pivot, vec![3, 3]);
assert!((error - 9.0).abs() < 1e-10);

§Arguments

  • tt – the tensor train approximation
  • f – the exact function
  • local_dims – number of values each index can take
  • init_p – starting point (None defaults to the all-zeros index)
  • early_stop_tol – stop early once the error exceeds this value (use f64::MAX to search exhaustively)

§Returns

(pivot, max_error) – the best multi-index found and its error.