pub struct MatrixLUCI<T: Scalar + Scalar> { /* private fields */ }Expand description
Matrix LU-based Cross Interpolation.
This is a higher-level row-major wrapper around the lower-level matrixluci
substrate.
§Examples
use tensor4all_tcicore::{AbstractMatrixCI, MatrixLUCI, from_vec2d};
let m = from_vec2d(vec![
vec![1.0_f64, 2.0, 3.0],
vec![4.0, 5.0, 6.0],
vec![7.0, 8.0, 9.0],
]);
let ci = MatrixLUCI::from_matrix(&m, None).unwrap();
// The approximation must have at most rank min(nrows, ncols)
assert!(ci.rank() <= 3);
// Reconstructed matrix should match original at pivot positions
let row_indices = ci.row_indices().to_vec();
let col_indices = ci.col_indices().to_vec();
for (&i, &j) in row_indices.iter().zip(col_indices.iter()) {
let approx = ci.evaluate(i, j);
let exact = m[[i, j]];
assert!((approx - exact).abs() < 1e-10);
}Implementations§
Source§impl<T> MatrixLUCI<T>
impl<T> MatrixLUCI<T>
Sourcepub fn from_matrix(a: &Matrix<T>, options: Option<RrLUOptions>) -> Result<Self>
pub fn from_matrix(a: &Matrix<T>, options: Option<RrLUOptions>) -> Result<Self>
Create a MatrixLUCI from a dense row-major matrix.
§Examples
use tensor4all_tcicore::{AbstractMatrixCI, MatrixLUCI, from_vec2d};
let m = from_vec2d(vec![
vec![2.0_f64, 0.0],
vec![0.0, 3.0],
]);
let ci = MatrixLUCI::from_matrix(&m, None).unwrap();
assert!(ci.rank() >= 1);Sourcepub fn left(&self) -> Matrix<T>
pub fn left(&self) -> Matrix<T>
Left CI factor (shape: nrows x rank).
The approximation is left * right.
§Examples
use tensor4all_tcicore::{AbstractMatrixCI, MatrixLUCI, from_vec2d, matrix::mat_mul};
let m = from_vec2d(vec![
vec![1.0_f64, 2.0],
vec![3.0, 4.0],
]);
let ci = MatrixLUCI::from_matrix(&m, None).unwrap();
let reconstructed = mat_mul(&ci.left(), &ci.right());
for i in 0..2 {
for j in 0..2 {
assert!((reconstructed[[i, j]] - m[[i, j]]).abs() < 1e-10);
}
}Sourcepub fn right(&self) -> Matrix<T>
pub fn right(&self) -> Matrix<T>
Right CI factor (shape: rank x ncols).
The approximation is left * right.
§Examples
use tensor4all_tcicore::{AbstractMatrixCI, MatrixLUCI, from_vec2d, matrix::mat_mul};
let m = from_vec2d(vec![vec![1.0_f64, 2.0], vec![3.0, 4.0]]);
let ci = MatrixLUCI::from_matrix(&m, None).unwrap();
let r = ci.right();
assert_eq!(r.nrows(), ci.rank());
assert_eq!(r.ncols(), ci.ncols());
// left * right reconstructs the matrix
let recon = mat_mul(&ci.left(), &r);
for i in 0..2 {
for j in 0..2 {
assert!((recon[[i, j]] - m[[i, j]]).abs() < 1e-10);
}
}Sourcepub fn pivot_errors(&self) -> Vec<f64>
pub fn pivot_errors(&self) -> Vec<f64>
Pivot error history (one entry per pivot, plus a final residual estimate).
§Examples
use tensor4all_tcicore::{MatrixLUCI, from_vec2d};
let m = from_vec2d(vec![vec![1.0_f64, 2.0], vec![3.0, 4.0]]);
let ci = MatrixLUCI::from_matrix(&m, None).unwrap();
let errs = ci.pivot_errors();
assert!(!errs.is_empty());
// All errors are non-negative
for &e in &errs {
assert!(e >= 0.0);
}Sourcepub fn last_pivot_error(&self) -> f64
pub fn last_pivot_error(&self) -> f64
Last pivot error (the residual estimate after all pivots).
§Examples
use tensor4all_tcicore::{MatrixLUCI, from_vec2d};
let m = from_vec2d(vec![vec![1.0_f64, 2.0], vec![3.0, 4.0]]);
let ci = MatrixLUCI::from_matrix(&m, None).unwrap();
let err = ci.last_pivot_error();
assert!(err >= 0.0);Trait Implementations§
Source§impl<T> AbstractMatrixCI<T> for MatrixLUCI<T>
impl<T> AbstractMatrixCI<T> for MatrixLUCI<T>
Source§fn row_indices(&self) -> &[usize]
fn row_indices(&self) -> &[usize]
Row indices selected as pivots (I set) Read more
Source§fn col_indices(&self) -> &[usize]
fn col_indices(&self) -> &[usize]
Column indices selected as pivots (J set) Read more
Source§fn evaluate(&self, i: usize, j: usize) -> T
fn evaluate(&self, i: usize, j: usize) -> T
Evaluate the approximation at position (i, j) Read more
Source§fn submatrix(&self, rows: &[usize], cols: &[usize]) -> Matrix<T>
fn submatrix(&self, rows: &[usize], cols: &[usize]) -> Matrix<T>
Get a submatrix of the approximation Read more
Source§fn available_rows(&self) -> Vec<usize>
fn available_rows(&self) -> Vec<usize>
Get available row indices (rows without pivots) Read more
Source§fn available_cols(&self) -> Vec<usize>
fn available_cols(&self) -> Vec<usize>
Get available column indices (columns without pivots) Read more
Source§fn local_error(
&self,
a: &Matrix<T>,
rows: &[usize],
cols: &[usize],
) -> Matrix<T>where
T: Sub<Output = T>,
fn local_error(
&self,
a: &Matrix<T>,
rows: &[usize],
cols: &[usize],
) -> Matrix<T>where
T: Sub<Output = T>,
Compute local error |A - CI| for given indices Read more
Auto Trait Implementations§
impl<T> Freeze for MatrixLUCI<T>
impl<T> RefUnwindSafe for MatrixLUCI<T>where
T: RefUnwindSafe,
impl<T> Send for MatrixLUCI<T>
impl<T> Sync for MatrixLUCI<T>
impl<T> Unpin for MatrixLUCI<T>where
T: Unpin,
impl<T> UnsafeUnpin for MatrixLUCI<T>
impl<T> UnwindSafe for MatrixLUCI<T>where
T: UnwindSafe,
Blanket Implementations§
§impl<U> As for U
impl<U> As for U
§fn as_<T>(self) -> Twhere
T: CastFrom<U>,
fn as_<T>(self) -> Twhere
T: CastFrom<U>,
Casts
self to type T. The semantics of numeric casting with the as operator are followed, so <T as As>::as_::<U> can be used in the same way as T as U for numeric conversions. Read moreSource§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> Twhere
Self: Distribution<T>,
§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> Twhere
Self: Distribution<T>,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more