Search Results for

    Show / Hide Table of Contents

    Class PositiveDefiniteMatrix

    A subclass of Matrix with extra methods appropriate to positive-definite matrices.

    Inheritance
    Object
    Matrix
    PositiveDefiniteMatrix
    Implements
    IList<Double>
    ICollection<Double>
    IReadOnlyList<Double>
    IReadOnlyCollection<Double>
    IEnumerable<Double>
    IEnumerable
    ICloneable
    SettableTo<Matrix>
    CanSetAllElementsTo<Double>
    Inherited Members
    Matrix.data
    Matrix.rows
    Matrix.cols
    Matrix.Item[Int32, Int32]
    Matrix.Item[Int32]
    Matrix.RowVector(Int32)
    Matrix.Rows
    Matrix.Cols
    Matrix.SourceArray
    Matrix.Count
    Matrix.GetEnumerator()
    Matrix.IEnumerable.GetEnumerator()
    Matrix.Contains(Double)
    Matrix.CopyTo(Double[], Int32)
    Matrix.ICollection<Double>.IsReadOnly
    Matrix.ICollection<Double>.Add(Double)
    Matrix.ICollection<Double>.Clear()
    Matrix.ICollection<Double>.Remove(Double)
    Matrix.IndexOf(Double)
    Matrix.IList<Double>.Insert(Int32, Double)
    Matrix.IList<Double>.RemoveAt(Int32)
    Matrix.FromArray(Double[,])
    Matrix.ToArray()
    Matrix.CopyTo(Double[,])
    Matrix.SetTo(Matrix)
    Matrix.SetAllElementsTo(Double)
    Matrix.EqualsAll(Double)
    Matrix.SetTo(Double[])
    Matrix.SetTo(Double[], Int32)
    Matrix.SetTo(Double[,])
    Matrix.SymmetryError()
    Matrix.Symmetrize()
    Matrix.SetToIdentity()
    Matrix.SetToIdentityScaledBy(Double)
    Matrix.Transpose()
    Matrix.SetToTranspose(Matrix)
    Matrix.SetToSubmatrix(Matrix, Int32, Int32)
    Matrix.SetSubmatrix(Int32, Int32, Matrix)
    Matrix.SetSubmatrix(Int32, Int32, Matrix, Int32, Int32, Int32, Int32)
    Matrix.SetToDiagonal(Vector)
    Matrix.SetDiagonal(Vector)
    Matrix.FromDiagonal(Vector)
    Matrix.Diagonal()
    Matrix.EnumerateDiagonal()
    Matrix.TraceOfProduct(Matrix, Matrix)
    Matrix.DiagonalOfProduct(Matrix, Matrix)
    Matrix.Scale(Double)
    Matrix.ScaleRows(Vector)
    Matrix.ScaleCols(Vector)
    Matrix.Median()
    Matrix.SetToElementwiseProduct(Matrix, Matrix)
    Matrix.SetToElementwiseRatio(Matrix, Matrix)
    Matrix.SetToProduct(Matrix, Double)
    Matrix.SetToProduct(Matrix, Matrix)
    Matrix.SetToOuter(Matrix)
    Matrix.Outer()
    Matrix.SetToOuterTranspose(Matrix)
    Matrix.OuterTranspose()
    Matrix.SetToOuter(Vector, Vector)
    Matrix.SetToSumWithOuter(Matrix, Double, Vector, Vector)
    Matrix.QuadraticForm(Vector)
    Matrix.QuadraticForm(Vector, Vector)
    Matrix.SetToSum(Matrix, Matrix)
    Matrix.SetToSum(Double, Matrix, Double, Matrix)
    Matrix.SetToDifference(Matrix, Matrix)
    Matrix.SetToDifference(Matrix, Double, Matrix)
    Matrix.Equals(Object)
    Matrix.GetHashCode()
    Matrix.CheckCompatible(Matrix, String)
    Matrix.CheckSymmetry(String)
    Matrix.MaxDiff(Matrix)
    Matrix.MaxDiff(Matrix, Double)
    Matrix.ToString()
    Matrix.ToString(String)
    Matrix.Parse(String)
    Matrix.IsPositiveDefinite()
    Matrix.Trace()
    Matrix.Inner(Matrix)
    Matrix.SetToKronecker(Matrix, Matrix)
    Matrix.Kronecker(Matrix)
    Matrix.Commutation(Int32, Int32)
    Matrix.PredivideBy(UpperTriangularMatrix)
    Matrix.PredivideByTranspose(LowerTriangularMatrix)
    Matrix.PredivideBy(LowerTriangularMatrix)
    Matrix.PredivideBy(PositiveDefiniteMatrix)
    Matrix.SetToLeastSquares(Matrix, Matrix)
    Matrix.SetToEigenvectorsOfSymmetric(Matrix)
    Matrix.SetToRightSingularVectors(Matrix)
    Matrix.EigenvaluesInPlace(Double[], Double[])
    Matrix.GetColumn(Int32)
    Matrix.GetRow(Int32)
    Object.Equals(Object, Object)
    Object.GetType()
    Object.MemberwiseClone()
    Object.ReferenceEquals(Object, Object)
    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 this is positive definite, otherwise false.

    Returns
    Type Description
    LowerTriangularMatrix

    The Cholesky decomposition L. If this is positive semidefinite, then L will satisfy LL' = A. Otherwise, L will only approximately satisfy LL' = A.

    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
    Matrix.Clone()

    Determinant()

    Returns the determinant of this positive-definite matrix.

    Declaration
    public double Determinant()
    Returns
    Type Description
    Double

    The determinant of this.

    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 this

    Remarks

    Because this is positive definite, it must be invertible, so this routine never throws MatrixSingularException.

    Exceptions
    Type Condition
    PositiveDefiniteMatrixException

    If this is not positive definite.

    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 this.

    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 this.

    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 this. Can be the same object as this.

    Returns
    Type Description
    PositiveDefiniteMatrix

    this

    Exceptions
    Type Condition
    PositiveDefiniteMatrixException

    If A is not positive definite.

    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 this. Can be the same object as this.

    LowerTriangularMatrix L

    A workspace, same size as A.

    Returns
    Type Description
    PositiveDefiniteMatrix

    this

    Exceptions
    Type Condition
    PositiveDefiniteMatrixException

    If A is not positive definite.

    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 this.

    PositiveDefiniteMatrix b

    Second matrix, which must have the same size as this.

    Returns
    Type Description
    PositiveDefiniteMatrix

    this

    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]

    Implements

    System.Collections.Generic.IList<T>
    System.Collections.Generic.ICollection<T>
    System.Collections.Generic.IReadOnlyList<T>
    System.Collections.Generic.IReadOnlyCollection<T>
    System.Collections.Generic.IEnumerable<T>
    System.Collections.IEnumerable
    System.ICloneable
    SettableTo<T>
    CanSetAllElementsTo<T>

    Extension Methods

    CollectionExtensions.AddRange<T>(ICollection<T>, IEnumerable<T>)
    CollectionExtensions.ContainsAll<T>(ICollection<T>, IEnumerable<T>)
    CollectionExtensions.ContainsAny<T>(ICollection<T>, IEnumerable<T>)
    EnumerableExtensions.ForEach<T>(IEnumerable<T>, Action<T>)
    EnumerableExtensions.ForEach<T>(IEnumerable, Action<T>)
    EnumerableExtensions.ForEach<T>(IEnumerable<T>, Action<Int32, T>)
    EnumerableExtensions.ForEach<T>(IEnumerable, Action<Int32, T>)
    EnumerableExtensions.Sum<TSource>(IEnumerable<TSource>, Func<TSource, UInt32>)
    EnumerableExtensions.Sum<TSource>(IEnumerable<TSource>, Func<TSource, UInt64>)
    EnumerableExtensions.ValueEquals<T>(IEnumerable<T>, IEnumerable<T>)
    EnumerableExtensions.IndexOf<T>(IEnumerable<T>, T)
    EnumerableExtensions.IndexOf<T>(IEnumerable, T)
    EnumerableExtensions.FindIndex<T>(IEnumerable<T>, Predicate<T>)
    EnumerableExtensions.FindIndex<T>(IEnumerable, Predicate<T>)
    EnumerableExtensions.FindAllIndex<T>(IEnumerable<T>, Predicate<T>)
    EnumerableExtensions.IndexOfAll<T>(IEnumerable<T>, T)
    EnumerableExtensions.Skip<T>(IEnumerable<T>, Int32, out List<T>)
    EnumerableExtensions.CopyTo<T>(IEnumerable<T>, T[], Int32)
    EnumerableExtensions.ToReadOnlyList<T>(IEnumerable<T>)
    IEnumerableExensions.EnumerableReduce<T, TRes>(IEnumerable<T>, TRes, Func<TRes, T, TRes>, Func<TRes, T, Int32, TRes>)
    IEnumerableExensions.EnumerableSum<T>(IEnumerable<T>, Func<T, Double>)
    IEnumerableExensions.ListZip<TFirst, TSecond, TResult>(IList<TFirst>, IEnumerable<TSecond>, Func<TFirst, TSecond, TResult>)
    IEnumerableExensions.ListZip<TFirst, TSecond, TThird, TResult>(IList<TFirst>, IEnumerable<TSecond>, IEnumerable<TThird>, Func<TFirst, TSecond, TThird, TResult>)
    IEnumerableExensions.ListZip<TFirst, TSecond, TThird, TFourth, TResult>(IList<TFirst>, IList<TSecond>, IList<TThird>, IList<TFourth>, Func<TFirst, TSecond, TThird, TFourth, TResult>)
    IListExtensions.IsSparse<T>(IList<T>)
    IListExtensions.ListSelect<T, T2>(IList<T>, Func<T, T2>)
    IListExtensions.ListReduce<T, TRes>(IList<T>, TRes, Func<TRes, T, TRes>)
    IListExtensions.ListReduce<T, T2, TRes>(IList<T>, IEnumerable<T2>, TRes, Func<TRes, T, T2, TRes>)
    IListExtensions.ToVector(IList<Double>)
    IListExtensions.SetTo<T>(IList<T>, IEnumerable<T>)
    IListExtensions.SetTo(IList<Double>, IEnumerable<Double>)
    IListExtensions.AsReadOnly<T>(IList<T>)
    ReadOnlyArray.ToReadOnlyArray<T>(IEnumerable<T>)
    In This Article
    Back to top Copyright © .NET Foundation. All rights reserved.