MatrixCorrectionTools
MatrixCorrectionTools is a lightweight package that offers a straightforward function called correction!. This function is designed to correct specific properties of a matrix using predefined strategies.
For instance, if a matrix contains zero diagonal entries, this package provides the means to replace (correct) them using either fixed predefined values or a more advanced algorithm based on SVD decomposition.
General functionality
MatrixCorrectionTools.correction! — Functioncorrection!(strategy, input)Modifies the input in-place using a specified correction strategy. The input can be either a matrix or a number. Certain strategies may require the input to satisfy specific properties beforehand, e.g., the input must be a square matrix. The nothing is a special correction strategy that does nothing and simply returns its input.
MatrixCorrectionTools.correction — Functioncorrection(strategy, input)Similar to correction!, but it first performs a deepcopy of the input.
MatrixCorrectionTools.AbstractCorrectionStrategy — TypeAbstract type to dispatch on a correction strategy defined in the package.
Available strategies
A strategy must implement a single function: MatrixCorrectionTools.correction!. Note that all defined strategies in the package are subtypes of the [MatrixCorrectionTools.AbstractCorrectionStrategy], but it is not necessary to subtype from it for the correction! function to work.
MatrixCorrectionTools.NoCorrection — TypeNoCorrectionA correction strategy option for the correction! function. It does not modify the input and simply returns the original.
MatrixCorrectionTools.ReplaceZeroDiagonalEntries — TypeReplaceZeroDiagonalEntries(value)A correction strategy option for the correction! function. It replaces zero diagonal entries with the predefined value. The LinearAlgebra.diagint function is employed to iterate over the diagonal entries. The iszero function is utilized to determine whether a diagonal entry is zero or not. This strategy converts the type of value to the exact element type of the container.
MatrixCorrectionTools.AddToDiagonalEntries — TypeAddToDiagonalEntries(value)A correction strategy option for the correction! function. It adds the predefined value to the diagonal entries. The LinearAlgebra.diagint function is employed to iterate over the diagonal entries. This strategy converts the type of value to the exact element type of the container.
MatrixCorrectionTools.ClampDiagonalEntries — TypeClampDiagonalEntries(lo, hi)A correction strategy option for the correction! function. It clamps the diagonal entries between lo and ho. The LinearAlgebra.diagint function is employed to iterate over the diagonal entries.
MatrixCorrectionTools.ClampSingularValues — TypeClampSingularValues(lo, hi)A correction strategy option for the correction! function. It clamps the singular values of the matrix between lo and hi. The LinearAlgebra.diagint function is employed to iterate over the diagonal entries. The LinearAlgebra.svd function is employed to make the SVD decomposition.