HMath.Matrix.QR¶
Module index · Numerical conventions
Detailed QR contracts · Least-squares guide
Description
Column-pivoted Householder QR. A[:, permutation] = Q R, with square Q.
Least squares requires m >= n and full column rank. Ridge uses augmented QR,
avoiding formation of the normal equations. Relative rank tolerance defaults
to max(m,n) times machine epsilon; callers may select an explicit tolerance.
On this page¶
| API | Purpose |
|---|---|
| QR | Opaque column-pivoted Householder factors satisfying A[:,p]=Q*R, with numerical-rank estimate. |
| qrDecompose | Column-pivoted Householder QR of a finite m-by-n matrix using relative rank tolerance max(m,n)*machine epsilon. |
| qrDecomposeWithTolerance | Given finite nonnegative relative rank tolerance then finite matrix, compute column-pivoted Householder QR. |
| qrQ | Extract the square m-by-m orthogonal Q factor from a QR decomposition. |
| qrR | Extract the m-by-n upper trapezoidal R factor. |
| qrPermutation | Return zero-based original column indices in pivoted order, satisfying A[:,p]=Q*R. |
| qrRank | Return estimated numerical rank selected by the factorization's relative diagonal-pivot tolerance. |
| applyQ | Given QR factorization then a matrix with m rows, return Q times that matrix. |
| applyQT | Given QR factorization then a matrix with m rows, return transpose(Q) times it. |
| leastSquares | Given finite m-by-n design matrix then m-element RHS, factor with pivoted QR and return least-squares coefficients. |
| leastSquaresMatrix | Given finite m-by-n design and m-by-k RHS matrices, return n-by-k least-squares solution via QR. |
| solveQR | Given full-column-rank QR factors of an m-by-n matrix then m-element right-hand side, return n least-squares coefficients in original column order. |
| solveMatrixQR | Given QR factors and an m-by-k RHS, return n-by-k least-squares coefficients, undoing column pivoting. |
| ridgeSolve | Given finite nonnegative lambda, design matrix, then RHS list, minimize squared residual plus lambda times squared coefficient norm. |
| ridgeSolveMatrix | Given lambda, m-by-n design, then m-by-k RHS, return n-by-k ridge coefficients via augmented QR. |
Documentation
QR
Opaque column-pivoted Householder factors satisfying A[:,p]=Q*R, with numerical-rank estimate. Construct with qrDecompose.
qrDecompose
qrDecompose :: RealFloat a => Matrix a -> Either MathError (QR a) Source #
Column-pivoted Householder QR of a finite m-by-n matrix using relative rank tolerance max(m,n)*machine epsilon. Return factors satisfying A[:,permutation]=Q*R. Numeric/input failures return Left MathError; rank deficiency is recorded rather than rejected at factorization.
qrDecomposeWithTolerance
qrDecomposeWithTolerance :: RealFloat a => a -> Matrix a -> Either MathError (QR a) Source #
Given finite nonnegative relative rank tolerance then finite matrix, compute column-pivoted Householder QR. Reject invalid tolerance/non-finite arithmetic. Zero tolerance counts every nonzero diagonal pivot as significant.
qrQ
qrQ :: QR a -> Matrix a Source #
Extract the square m-by-m orthogonal Q factor from a QR decomposition.
qrR
qrR :: QR a -> Matrix a Source #
Extract the m-by-n upper trapezoidal R factor. Column ordering corresponds to qrPermutation.
qrPermutation
qrPermutation :: QR a -> [Int] Source #
Return zero-based original column indices in pivoted order, satisfying A[:,p]=Q*R.
qrRank
qrRank :: QR a -> Int Source #
Return estimated numerical rank selected by the factorization's relative diagonal-pivot tolerance.
applyQ
applyQ :: Num a => QR a -> Matrix a -> Either MathError (Matrix a) Source #
Given QR factorization then a matrix with m rows, return Q times that matrix. Dimension/size errors return Left MathError; generic Num arithmetic is unchanged.
applyQT
applyQT :: Num a => QR a -> Matrix a -> Either MathError (Matrix a) Source #
Given QR factorization then a matrix with m rows, return transpose(Q) times it. Checked matrix dimension errors propagate.
leastSquares
leastSquares :: RealFloat a => Matrix a -> [a] -> Either MathError [a] Source #
Given finite m-by-n design matrix then m-element RHS, factor with pivoted QR and return least-squares coefficients. Require m>=n and full column rank; decomposition/solve errors propagate.
leastSquaresMatrix
leastSquaresMatrix :: RealFloat a => Matrix a -> Matrix a -> Either MathError (Matrix a) Source #
Given finite m-by-n design and m-by-k RHS matrices, return n-by-k least-squares solution via QR. Underdetermined/rank-deficient or invalid input returns Left MathError.
solveQR
solveQR :: RealFloat a => QR a -> [a] -> Either MathError [a] Source #
Given full-column-rank QR factors of an m-by-n matrix then m-element right-hand side, return n least-squares coefficients in original column order. Reject underdetermined systems, incompatible RHS, deficient rank, or non-finite input/result.
solveMatrixQR
solveMatrixQR :: RealFloat a => QR a -> Matrix a -> Either MathError (Matrix a) Source #
Given QR factors and an m-by-k RHS, return n-by-k least-squares coefficients, undoing column pivoting. Require m>=n and full column rank; shaperankfiniteness failures return Left MathError.
ridgeSolve
ridgeSolve :: RealFloat a => a -> Matrix a -> [a] -> Either MathError [a] Source #
Given finite nonnegative lambda, design matrix, then RHS list, minimize squared residual plus lambda times squared coefficient norm. Use augmented QR, not normal equations. Zero lambda delegates to leastSquares; dimension/numeric errors propagate.