Class PositiveDefiniteMatrix
A subclass of Matrix with extra methods appropriate to positive-definite matrices.
Implements
Inherited Members
Namespace: Microsoft.ML.Probabilistic.Math
Assembly: Microsoft.ML.Probabilistic.dll
Syntax
[Serializable]
[DataContract]
public class PositiveDefiniteMatrix : Matrix, IList<double>, ICollection<double>, IReadOnlyList<double>, IReadOnlyCollection<double>, IEnumerable<double>, IEnumerable, ICloneable, SettableTo<Matrix>, CanSetAllElementsTo<double>
Constructors
PositiveDefiniteMatrix()
Default constructor just used for serialization.
Declaration
protected PositiveDefiniteMatrix()
PositiveDefiniteMatrix(Matrix)
Constructs a positive-definite matrix type which references an existing matrix.
Declaration
public PositiveDefiniteMatrix(Matrix A)
Parameters
Type | Name | Description |
---|---|---|
Matrix | A | A positive-definite matrix. |
Remarks
This method is similar to a typecast, except it creates a new wrapper around the matrix.
PositiveDefiniteMatrix(Double[,])
Constructs a matrix from data in a 2D array.
Declaration
[Construction(new string[]{"ToArray"})]
public PositiveDefiniteMatrix(double[, ] data)
Parameters
Type | Name | Description |
---|---|---|
Double[,] | data | 2D array of elements. |
Remarks
The 2D array is copied into new storage. The size of the matrix is taken from the array.
PositiveDefiniteMatrix(Int32, Int32)
Constructs a zero matrix of the given dimensions.
Declaration
public PositiveDefiniteMatrix(int rows, int cols)
Parameters
Type | Name | Description |
---|---|---|
Int32 | rows | Number of rows >= 0. |
Int32 | cols | Number of columns >= 0. |
PositiveDefiniteMatrix(Int32, Int32, Double[])
Constructs a matrix by referencing an array.
Declaration
public PositiveDefiniteMatrix(int rows, int cols, double[] data)
Parameters
Type | Name | Description |
---|---|---|
Int32 | rows | Number of rows. |
Int32 | cols | Number of columns. |
Double[] | data | Storage for the matrix elements. |
Methods
CholeskyInPlace(out Boolean)
Gets the Cholesky decomposition of the matrix (L*L' = A), replacing its contents.
Declaration
public LowerTriangularMatrix CholeskyInPlace(out bool isPosDef)
Parameters
Type | Name | Description |
---|---|---|
Boolean | isPosDef | True if |
Returns
Type | Description |
---|---|
LowerTriangularMatrix | The Cholesky decomposition L. If |
Remarks
this
must be symmetric, but need not be positive definite.
Clone()
Creates a full clone of this positive-definite matrix
Declaration
public override object Clone()
Returns
Type | Description |
---|---|
Object |
Overrides
Determinant()
Returns the determinant of this positive-definite matrix.
Declaration
public double Determinant()
Returns
Type | Description |
---|---|
Double | The determinant of |
Remarks
Throws a MatrixSingularException if the matrix is singular.
Identity(Int32)
Creates a positive-definite identity matrix of a given dimension
Declaration
public static PositiveDefiniteMatrix Identity(int dimension)
Parameters
Type | Name | Description |
---|---|---|
Int32 | dimension |
Returns
Type | Description |
---|---|
PositiveDefiniteMatrix |
IdentityScaledBy(Int32, Double)
Creates a positive-definite identity matrix of a given dimension, scaled by a given value
Declaration
public static PositiveDefiniteMatrix IdentityScaledBy(int dimension, double scale)
Parameters
Type | Name | Description |
---|---|---|
Int32 | dimension | |
Double | scale |
Returns
Type | Description |
---|---|
PositiveDefiniteMatrix |
Inverse()
Returns the inverse of a positive-definite matrix.
Declaration
public PositiveDefiniteMatrix Inverse()
Returns
Type | Description |
---|---|
PositiveDefiniteMatrix | A new matrix which is the inverse of |
Remarks
Because this
is positive definite, it must be
invertible, so this routine never throws MatrixSingularException.
Exceptions
Type | Condition |
---|---|
PositiveDefiniteMatrixException | If |
LogDeterminant(LowerTriangularMatrix, Boolean)
Returns the natural logarithm of the determinant of this positive-definite matrix where a lower triangular workspace is passed in.
Declaration
public double LogDeterminant(LowerTriangularMatrix L, bool ignoreInfinity = false)
Parameters
Type | Name | Description |
---|---|---|
LowerTriangularMatrix | L | A temporary workspace, same size as |
Boolean | ignoreInfinity | If true, +infinity on the diagonal is treated as 1. |
Returns
Type | Description |
---|---|
Double | The log-determinant. |
Remarks
Throws a MatrixSingularException if the matrix is singular.
LogDeterminant(Boolean)
Returns the natural logarithm of the determinant of this positive-definite matrix.
Declaration
public double LogDeterminant(bool ignoreInfinity = false)
Parameters
Type | Name | Description |
---|---|---|
Boolean | ignoreInfinity | If true, +infinity on the diagonal is treated as 1. |
Returns
Type | Description |
---|---|
Double | The log-determinant of |
SetToInverse(PositiveDefiniteMatrix)
Sets this positive-definite matrix to inverse of a given positive-definite matrix.
Declaration
public PositiveDefiniteMatrix SetToInverse(PositiveDefiniteMatrix A)
Parameters
Type | Name | Description |
---|---|---|
PositiveDefiniteMatrix | A | A symmetric positive-definite matrix, same size as |
Returns
Type | Description |
---|---|
PositiveDefiniteMatrix |
|
Exceptions
Type | Condition |
---|---|
PositiveDefiniteMatrixException | If |
SetToInverse(PositiveDefiniteMatrix, LowerTriangularMatrix)
Sets this positive-definite matrix to inverse of a given positive-definite matrix where a lower triangular workspace is passed.
Declaration
public PositiveDefiniteMatrix SetToInverse(PositiveDefiniteMatrix A, LowerTriangularMatrix L)
Parameters
Type | Name | Description |
---|---|---|
PositiveDefiniteMatrix | A | A symmetric positive-definite matrix, same size as |
LowerTriangularMatrix | L | A workspace, same size as |
Returns
Type | Description |
---|---|
PositiveDefiniteMatrix |
|
Exceptions
Type | Condition |
---|---|
PositiveDefiniteMatrixException | If |
SetToSum(PositiveDefiniteMatrix, PositiveDefiniteMatrix)
Sets this positive-definite matrix to the sum of two positive-definite matrices. Assumes compatible matrices
Declaration
public PositiveDefiniteMatrix SetToSum(PositiveDefiniteMatrix a, PositiveDefiniteMatrix b)
Parameters
Type | Name | Description |
---|---|---|
PositiveDefiniteMatrix | a | First matrix, which must have the same size as |
PositiveDefiniteMatrix | b | Second matrix, which must have the same size as |
Returns
Type | Description |
---|---|
PositiveDefiniteMatrix |
|
Remarks
this
receives the sum, and must already be the correct size.
a
and/or b
may be the same object as this
.
If this
and a
/b
occupy distinct yet overlapping portions of the same source array, the results are undefined.
Operators
Addition(PositiveDefiniteMatrix, PositiveDefiniteMatrix)
Add two positive-definite matrices.
Declaration
public static PositiveDefiniteMatrix operator +(PositiveDefiniteMatrix a, PositiveDefiniteMatrix b)
Parameters
Type | Name | Description |
---|---|---|
PositiveDefiniteMatrix | a | First matrix. |
PositiveDefiniteMatrix | b | Second matrix. |
Returns
Type | Description |
---|---|
PositiveDefiniteMatrix | Their sum. |
Division(PositiveDefiniteMatrix, Double)
Divide matrix by scalar
Declaration
public static PositiveDefiniteMatrix operator /(PositiveDefiniteMatrix a, double b)
Parameters
Type | Name | Description |
---|---|---|
PositiveDefiniteMatrix | a | |
Double | b |
Returns
Type | Description |
---|---|
PositiveDefiniteMatrix | A new matrix with entry [i,j] equal to a[i,j]/b |
Multiply(PositiveDefiniteMatrix, Double)
Multiply matrix times scalar
Declaration
public static PositiveDefiniteMatrix operator *(PositiveDefiniteMatrix a, double b)
Parameters
Type | Name | Description |
---|---|---|
PositiveDefiniteMatrix | a | |
Double | b |
Returns
Type | Description |
---|---|
PositiveDefiniteMatrix | A new matrix with entry [i,j] equal to a[i,j]*b |
Multiply(Double, PositiveDefiniteMatrix)
Multiply matrix times scalar
Declaration
public static PositiveDefiniteMatrix operator *(double a, PositiveDefiniteMatrix b)
Parameters
Type | Name | Description |
---|---|---|
Double | a | |
PositiveDefiniteMatrix | b |
Returns
Type | Description |
---|---|
PositiveDefiniteMatrix | A new matrix with entry [i,j] equal to a*b[i,j] |