Skip to main content

GlobalPivotFinder

Trait GlobalPivotFinder 

Source
pub trait GlobalPivotFinder {
    // Required method
    fn find_global_pivots<T, F>(
        &self,
        input: &GlobalPivotSearchInput<T>,
        f: &F,
        abs_tol: f64,
        rng: &mut impl Rng,
    ) -> Vec<MultiIndex> 
       where T: Scalar + TTScalar,
             F: Fn(&MultiIndex) -> T;
}
Expand description

Trait for global pivot finders.

Implementors search for multi-indices where the interpolation error |f(idx) - tt(idx)| is large. Found pivots are added to the TCI state to improve the approximation in the next sweep.

The default implementation is DefaultGlobalPivotFinder. Implement this trait to supply domain-specific search strategies.

§Examples

Using the default implementation via DefaultGlobalPivotFinder:

use tensor4all_tensorci::{DefaultGlobalPivotFinder, GlobalPivotFinder,
    GlobalPivotSearchInput};
use tensor4all_simplett::TensorTrain;

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

let input = GlobalPivotSearchInput {
    local_dims: vec![4, 4],
    current_tt: tt,
    max_sample_value: 9.0,
    i_set: vec![vec![vec![]], vec![vec![0]]],
    j_set: vec![vec![vec![0]], vec![vec![]]],
};

let finder = DefaultGlobalPivotFinder::default();
let mut rng = rand::rng();

// f(i,j) = i*j has nonzero values, so pivots should be found
let pivots = finder.find_global_pivots(
    &input,
    &|idx: &Vec<usize>| (idx[0] * idx[1]) as f64,
    0.1,
    &mut rng,
);

// All returned pivots must have valid indices
for p in &pivots {
    assert_eq!(p.len(), 2);
    assert!(p[0] < 4 && p[1] < 4);
}

Required Methods§

Source

fn find_global_pivots<T, F>( &self, input: &GlobalPivotSearchInput<T>, f: &F, abs_tol: f64, rng: &mut impl Rng, ) -> Vec<MultiIndex>
where T: Scalar + TTScalar, F: Fn(&MultiIndex) -> T,

Find multi-indices with high interpolation error.

§Arguments
  • input – current TCI state (tensor train, index sets, etc.)
  • f – the function being interpolated
  • abs_tol – absolute tolerance; pivots with error above this threshold (times tol_margin) are interesting
  • rng – random number generator for stochastic search
§Returns

Multi-indices where the interpolation error is large, up to the implementation’s maximum count.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§