interpolative_decomposition

Function interpolative_decomposition 

Source
pub fn interpolative_decomposition<F>(
    a: &ArrayView2<'_, F>,
    k: usize,
    method: &str,
) -> LinalgResult<(Array2<F>, Array2<F>)>
where F: Float + NumAssign + Zero + One + Sum + Debug + 'static + ScalarOperand + Send + Sync,
Expand description

Computes the Interpolative Decomposition (ID) of a matrix.

The ID decomposes A ≈ C * Z where C consists of a subset of the columns of A and Z is a coefficient matrix, with some columns of Z being the corresponding columns of the identity matrix.

§Arguments

  • a - Input matrix
  • k - Number of columns to select
  • method - Method to use (‘qr’ or ‘svd’)

§Returns

  • Tuple (C, Z) where C contains k columns of A and Z is a coefficient matrix

§Examples

use scirs2_core::ndarray::array;
use scirs2_linalg::matrix_factorization::interpolative_decomposition;

let a = array![
    [1.0, 2.0, 3.0, 4.0],
    [4.0, 5.0, 6.0, 7.0],
    [7.0, 8.0, 9.0, 10.0]
];

// Select 2 representative columns
let (c, z) = interpolative_decomposition(&a.view(), 2, "qr").unwrap();

// C should have 3 rows and k=2 columns
assert_eq!(c.shape(), &[3, 2]);

// Z should have k=2 rows and 4 columns
assert_eq!(z.shape(), &[2, 4]);

// The product C*Z should approximate A
let approx = c.dot(&z);
assert_eq!(approx.shape(), a.shape());