Documentation

9.6 Dense matrices and Cholesky paths

The shared Mat type is a small row-major dense matrix used for covariance, information and curvature calculations. Core operations include submatrices, multiplication, transpose, scaling, symmetrization, diagonal summaries and finite-value checks.

Symmetrization

Before symmetric eigendecomposition or robust covariance handling, nlmx averages each off-diagonal pair:

\[ a_{ij},a_{ji}\leftarrow(a_{ij}+a_{ji})/2. \]

The maximum removed asymmetry is available to callers. Symmetrization corrects floating-point disagreement between theoretically equal entries; it cannot repair a fundamentally wrong matrix.

Cholesky factorization

For a positive-definite symmetric matrix \(A\), Cholesky computes \(A=LL^T\). A nonpositive or non-finite pivot fails rather than taking a square root. Solves use forward and backward substitution; log determinant is \(2\sum_i\log L_{ii}\).

Plain Cholesky is the fast path for symmetric inversion. The inverse diagonal must remain finite and positive. The engine also calculates eigenvalue summaries so condition and diagnostic information can be reported.

Covariance draws

Sampling a multivariate normal multiplies independent standard normals by a lower-triangular factor. If covariance factorization needs repair, the robust path projects to a positive-semidefinite matrix before retrying Cholesky. The size of the repair is returned and should be surfaced by the calling workflow.

Numerical review

Test (A A^{-1}) against identity, solve residuals (||Ax-b||), log determinants and covariance reconstruction (LL^T). Scale tests over many orders of magnitude; a method that works only near unit scale is not sufficient.

Common mistakes

  • Assuming a nearly symmetric matrix is automatically positive definite.
  • Forming an explicit inverse when a solve is enough.
  • Hiding covariance repair magnitude.

Checklist

  • Record asymmetry and factorization path.
  • Verify solve residuals and finite pivots.
  • Prefer solves to explicit inverses in new algorithms.

Further reading

See stabilized inversion, condition numbers and Chapter 18's future information-matrix theory.