Linear Algebra

audio_samples.linalg holds non-negative least squares, the pseudo-inverse, the symmetric eigenproblem and the singular value decomposition.

Dense linear algebra: non-negative least squares, the pseudo-inverse, the symmetric eigenproblem and the SVD.

audio_samples.linalg.eigh(a)

Eigenvalues and eigenvectors of a symmetric matrix; only the lower triangle is read.

Parameters:

a (array_like) – (n, n) symmetric matrix.

Returns:

Increasing eigenvalues, and the matching eigenvectors in the columns, both float64.

Return type:

tuple[numpy.ndarray, numpy.ndarray]

audio_samples.linalg.nnls(A, B, *, max_iter=200, tol=1e-05)

Non-negative least squares: min ||A x - B|| with x >= 0.

A 1-D B gets the exact active-set solution. Each column of a 2-D or higher B starts from the pseudo-inverse solution with negative entries set to zero and is refined by coordinate descent, which keeps it near the minimum-norm solution when A has more columns than rows.

Parameters:
  • A (array_like) – (m, n) matrix.

  • B (array_like) – (m,) or (..., m, t).

  • max_iter (int) – Most sweeps per column of a 2-D B. Default 200.

  • tol (float) – Stop a column when no sweep changes A x by more than this fraction of max|B|. Default 1e-5.

Returns:

(n,) or (..., n, t), of B’s precision.

Return type:

numpy.ndarray

Raises:

ValueError – Dimensions disagree or an input is not finite.

audio_samples.linalg.pinv(a, *, rcond=1e-15)

The Moore-Penrose pseudo-inverse.

Parameters:
  • a (array_like) – (m, n) matrix.

  • rcond (float) – Singular values below this fraction of the largest count as zero. Values below about 1.5e-8 act as that limit. Default 1e-15.

Returns:

(n, m), of a’s precision.

Return type:

numpy.ndarray

audio_samples.linalg.svd(a, *, k=None, n_iter=4, seed=0)

Thin singular value decomposition, or the truncated one with k.

Computed through the Gram matrix: singular values below about 1.5e-8 of the largest are reported as zero. The truncated form finds the leading triplets by randomised range finding, deterministically for a given seed.

Parameters:
  • a (array_like) – (m, n) matrix.

  • k (Optional[int]) – Number of leading triplets. Default: all.

  • n_iter (int) – Power iterations of the truncated form. Default 4.

  • seed (int) – Seed of the truncated form. Default 0.

Returns:

u, s, vt, float64.

Return type:

tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray]