packages

linalg::factor::svd

On this page

SVD of a real m x n matrix. A wide A goes through its transpose, so n = min(m, n) below. Two kernels, chosen by n alone (so svdvals(a) is bit for bit svd(a).s()):

  • n <= 16: one-sided Jacobi on the R of a pivoted QR (jacobi). Every singular value to high relative accuracy when A is well conditioned up to a column scaling (graded matrices): on A = Q diag(2^-4j) it gets all twelve values, down to 2^-44, to a few n * eps relative, where QR iteration only promises n * eps * s_max absolute. About 3x slower, which is microseconds at this size.
  • n > 16: Golub-Kahan bidiagonalization and implicit-shift QR (bidiag), after a Householder QR when m >= 1.6n. Every singular value to about n * eps * s_max absolute; on random, Hilbert and Vandermonde matrices as accurate as Jacobi. O(mn^2) for the QR, 8n^3/3 for the bidiagonal, O(n^2) for the values alone and about 12n^3 more for the vectors, against about 4n^3 per Jacobi sweep.

Both are backward stable: ||A - U S V^T|| is a small multiple of n * eps * ||A||, and U, V are orthonormal to a few n * eps. U comes from applying the reflectors to the small factor (no explicit Q). Large reflector updates and rotation sweeps run on core::par workers.

Structs

SvdSource

pub struct Svd<T>

A = U diag(s) V^T of a real m x n matrix: s falls (k = min(m, n) values), U and V have orthonormal columns. Thin by default (U is m x k, V^T k x n); svd_full gives the square U (m x m) and V^T (n x n).

nabi
use core::array::Matrix;

let a: Matrix<f64> = [[3, 0], [0, -2]];
let f = try linalg::svd(a);
assert(f.s()[0] == 3.0 && f.s()[1] == 2.0);
  • pub fn u(self) -> Matrix<T>§

    Source

    U: m x k (thin) or m x m (full).

  • pub fn s(self) -> Vector<T>§

    Source

    The singular values, largest first.

  • pub fn vt(self) -> Matrix<T>§

    Source

    V^T: k x n (thin) or n x n (full).

  • pub fn v(self) -> Matrix<T>§

    Source

    V, the transpose of vt().

  • pub fn rank(self, tol: T | none) -> usize§

    Source

    How many singular values exceed tol (none: the default max(m, n) * eps * s[0]).

  • pub fn solve<B: Rhs<T>>(self, b: B, tol: T | none) throws (LinalgError) -> B§

    Source

    The minimum-norm least-squares solution V S^+ U^T b, singular values at or below tol (none: the default of rank) taken as zero.