IGLib
1.7.2
The IGLib base library EXTENDED - with other lilbraries and applications.
|
Represents a symmetric matrix. More...
Public Member Functions | |
SymmetricMatrix (int dimension) | |
Initializes a new symmetric matrix. More... | |
override void | Fill (Func< int, int, double > f) |
SymmetricMatrix | Copy () |
Copies the matrix. More... | |
override double | Trace () |
Computes the trace of the matrix. More... | |
SymmetricMatrix | Inverse () |
Computes the inverse of the matrix. More... | |
CholeskyDecomposition | CholeskyDecomposition () |
Returns the Cholesky decomposition of the matrix. More... | |
RealEigensystem | Eigensystem () |
Computes the eigenvalues and eigenvectors of the matrix. More... | |
double[] | Eigenvalues () |
Computes the eigenvalues of the matrix. More... | |
![]() | |
virtual double | OneNorm () |
Computes the 1-norm of the matrix. More... | |
virtual double | InfinityNorm () |
Computes the ∞-norm of the matrix. More... | |
virtual double | FrobeniusNorm () |
Computes the Frobenius-norm of the matrix. More... | |
virtual ColumnVector | Column (int c) |
Gets a copy of the specified column. More... | |
virtual RowVector | Row (int r) |
Gets a copy of the specified row. More... | |
virtual SymmetricMatrix | MultiplySelfByTranspose () |
Computes the product of the matrix and its transpose. More... | |
virtual SymmetricMatrix | MultiplyTransposeBySelf () |
Computes the product of the matrix's transpose and itself. More... | |
bool | Equals (AnyRectangularMatrix other) |
Determines whether the given matrix equals the current matrix. More... | |
override bool | Equals (object obj) |
Determines whether the given object is an equal matrix. More... | |
override int | GetHashCode () |
Not a valid operation. More... | |
![]() | |
virtual void | Fill (Func< int, int, T > f) |
Sets all matrix entries according to a supplied fill function. More... | |
virtual T[,] | ToArray () |
Copies the matrix into an array. More... | |
Static Public Member Functions | |
static SymmetricMatrix | operator+ (SymmetricMatrix A, SymmetricMatrix B) |
Adds two symmetric matrices. More... | |
static SymmetricMatrix | operator- (SymmetricMatrix A, SymmetricMatrix B) |
Subtracts two symmetric matrices. More... | |
static SymmetricMatrix | operator* (double alpha, SymmetricMatrix A) |
Multiplies a symmetric matrix by a real factor. More... | |
static SymmetricMatrix | operator- (SymmetricMatrix A) |
Negates a symmetric matrix. More... | |
![]() | |
static SquareMatrix | operator+ (AnySquareMatrix A, AnySquareMatrix B) |
Adds any two real, square matrices. More... | |
static SquareMatrix | operator- (AnySquareMatrix A, AnySquareMatrix B) |
Subtracts any two real, square matrices. More... | |
static SquareMatrix | operator* (AnySquareMatrix A, AnySquareMatrix B) |
Multiplies any two real, square matrices. More... | |
![]() | |
static RectangularMatrix | operator+ (AnyRectangularMatrix A, AnyRectangularMatrix B) |
Adds any two real, rectangular matrices. More... | |
static RectangularMatrix | operator- (AnyRectangularMatrix A, AnyRectangularMatrix B) |
Subtracts any two real, rectangular matrices. More... | |
static RectangularMatrix | operator* (AnyRectangularMatrix A, AnyRectangularMatrix B) |
Multiplies any two real, rectangular matrices. More... | |
static RectangularMatrix | operator* (double alpha, AnyRectangularMatrix A) |
Multiplies any real, rectangular matrix by a real constant. More... | |
static ColumnVector | operator* (AnyRectangularMatrix A, ColumnVector v) |
Multiplies any real, rectangular matrix with a real column vector. More... | |
static bool | operator== (AnyRectangularMatrix A, AnyRectangularMatrix B) |
Determines whether two matrices are equal. More... | |
static bool | operator!= (AnyRectangularMatrix A, AnyRectangularMatrix B) |
Determines whether two matrices are not equal. More... | |
Properties | |
override int | Dimension [get] |
Gets the dimension of the matrix. More... | |
override double | this[int r, int c] [get, set] |
Gets or sets an element of the matrix. More... | |
![]() | |
abstract int | Dimension [get] |
Gets or sets the dimension of the square matrix. More... | |
override int | RowCount [get] |
override int | ColumnCount [get] |
![]() | |
abstract int | RowCount [get] |
Gets the number of matrix rows. More... | |
abstract int | ColumnCount [get] |
Gets the number of matrix columns. More... | |
abstract T | this[int r, int c] [get, set] |
Gets or sets the value of a matrix entry. More... | |
bool | IsReadOnly [get, set] |
Gets a flag indicating whether the matrix is read-only. More... | |
Private Attributes | |
int | dimension |
double[][] | values |
Additional Inherited Members | |
![]() | |
AnyRectangularMatrix () | |
![]() | |
AnyMatrix () | |
Represents a symmetric matrix.
|
inline |
Initializes a new symmetric matrix.
dimension | The dimension of the matrix, which must be positive. |
|
inline |
|
inline |
Copies the matrix.
Referenced by Meta.Numerics.Statistics.FitResult.CovarianceMatrix(), Meta.Numerics.Analysis.SpaceExtremum.Curvature(), and Test.SymmetricMatrixTest.SymmetricMatrixAccess().
|
inlinevirtual |
Computes the trace of the matrix.
Reimplemented from Meta.Numerics.Matrices.AnySquareMatrix.
Referenced by Test.SymmetricMatrixTest.SymmetricHilbertMatrixEigenvalues(), and Test.SymmetricMatrixTest.SymmetricRandomMatrixEigenvectors().
|
inline |
Computes the inverse of the matrix.
References Meta.Numerics.Matrices.SquareMatrix.Inverse().
Referenced by Meta.Numerics.Statistics.BivariateSample.LinearLogisticRegression(), Test.SymmetricMatrixTest.SymmetricHilbertMatrixInverse(), and Test.SymmetricMatrixTest.SymmetricRandomMatrixInverse().
|
inline |
Returns the Cholesky decomposition of the matrix.
A Cholesky decomposition is a special decomposition that is possible only for positive definite matrices. (A positive definite matrix M has xTMx > 0 for any vector x. Equivilently, M is positive definite if all its eigenvalues are positive.)
The Cholesky decomposition represents M = C CT, where C is lower-left triangular (and thus CT is upper-right triangular. It is basically an LU decomposition where the L and U factors are related by transposition. Since the M is produced by multiplying C "by itself", the matrix C is sometimes call the "square root" of M.
Cholesky decomposition is an O(N3) operation. It is about a factor of two faster than LU decomposition, so it is a faster way to obtain inverses, determinates, etc. if you know that M is positive definite.
The fastest way to test whether your matrix is positive definite is attempt a Cholesky decomposition. If this method returns null, M is not positive definite.
Referenced by Test.SymmetricMatrixTest.CatalanHankelMatrixDeterminant(), Test.MultivariateSampleTest.CreateMultivariateNormalSample(), Meta.Numerics.Statistics.UncertainMeasurementSample< T >.FitToFunction(), Meta.Numerics.Statistics.Distributions.WeibullDistribution.FitToSample(), Meta.Numerics.Statistics.Distributions.BetaDistribution.FitToSample(), Meta.Numerics.Statistics.Distributions.GammaDistribution.FitToSample(), Test.MultiIntegrateTest.GaussianIntegrals(), Meta.Numerics.Statistics.MultivariateSample.LinearRegression_Internal(), Meta.Numerics.Statistics.Sample.MaximumLikelihoodFit(), Test.SymmetricMatrixTest.SymmetricMatrixDecomposition(), and Test.SymmetricMatrixTest.SymmetricRandomMatrixCholeskyDecomposition().
|
inline |
Computes the eigenvalues and eigenvectors of the matrix.
For a generic vector v and matrix M, Mv = u will point in some direction with no particular relationship to v. The eigenvectors of a matrix M are vectors z that satisfy Mz = λz, i.e. multiplying an eigenvector by a matrix reproduces the same vector, up to a prortionality constant λ called the eigenvalue.
For v to be an eigenvector of M with eigenvalue λ, (M - λI)z = 0. But for a matrix to anihilate any non-zero vector, that matrix must have determinant, so det(M - λI)=0. For a matrix of order N, this is an equation for the roots of a polynomial of order N. Since an order-N polynomial always has exactly N roots, an order-N matrix always has exactly N eigenvalues.
An alternative way of expressing the same relationship is to say that the eigenvalues of a matrix are its diagonal elements when the matrix is expressed in a basis that diagonalizes it. That is, given Z such that Z-1MZ = D, where D is diagonal, the columns of Z are the eigenvectors of M and the diagonal elements of D are the eigenvalues.
Note that the eigenvectors of a matrix are not entirely unique. Given an eigenvector z, any scaled vector αz is an eigenvector with the same eigenvalue, so eigenvectors are at most unique up to a rescaling. If an eigenvalue is degenerate, i.e. there are two or more linearly independent eigenvectors with the same eigenvalue, then any linear combination of the eigenvectors is also an eigenvector with that eigenvalue, and in fact any set of vectors that span the same subspace could be taken as the eigenvector set corresponding to that eigenvalue.
The eigenvectors of a symmetric matrix are always orthogonal and the eigenvalues are always real. The transformation matrix Z is thus orthogonal (Z-1 = ZT).
Finding the eigenvalues and eigenvectors of a symmetric matrix is an O(N3) operation.
If you require only the eigenvalues, not the eigenvectors, of the matrix, the Eigenvalues method will produce them faster than this method.
Referenced by Test.SymmetricMatrixTest.SymmetricRandomMatrixEigenvectors().
|
inline |
Computes the eigenvalues of the matrix.
If you require only the eigenvalues of the matrix, not its eigenvectors, this method will return them faster than the Eigensystem method. If you do need the eigenvectors as well as the eigenvalues, use the Eigensystem method instead.
Referenced by Test.SymmetricMatrixTest.SymmetricHilbertMatrixEigenvalues().
|
inlinestatic |
Adds two symmetric matrices.
A | The first matrix. |
B | The second matrix. |
References Meta.Numerics.Matrices.SymmetricMatrix.dimension, and Meta.Numerics.Matrices.SymmetricMatrix.values.
|
inlinestatic |
Subtracts two symmetric matrices.
A | The first matrix. |
B | The second matrix. |
References Meta.Numerics.Matrices.SymmetricMatrix.dimension, and Meta.Numerics.Matrices.SymmetricMatrix.values.
|
inlinestatic |
Multiplies a symmetric matrix by a real factor.
alpha | The factor. |
A | The matrix. |
References Meta.Numerics.Matrices.SymmetricMatrix.dimension, Meta.Numerics.Matrices.SymmetricMatrix.Dimension, and Meta.Numerics.Matrices.SymmetricMatrix.values.
|
inlinestatic |
Negates a symmetric matrix.
A | The matrix. |
References Meta.Numerics.Matrices.SymmetricMatrix.dimension, Meta.Numerics.Matrices.SymmetricMatrix.Dimension, and Meta.Numerics.Matrices.SymmetricMatrix.values.
|
private |
|
private |
|
get |
Gets the dimension of the matrix.
Referenced by Test.ExtremaTest.FindMinimumOfGamma(), Meta.Numerics.Matrices.SymmetricMatrix.operator*(), Meta.Numerics.Matrices.SymmetricMatrix.operator-(), Test.SymmetricMatrixTest.SymmetricMatrixAccess(), and Test.SymmetricMatrixTest.SymmetricRandomMatrixEigenvectors().
|
getset |
Gets or sets an element of the matrix.
r | The (zero-based) row number. |
c | The (zero-based) column number. |
The set operation preserves the symmetry of the matrix; when entry Mr c is changed, entry Mc r is updated automatically.