Class VectorGaussianMoments
Represents a multivariate Gaussian distribution.
Implements
Inherited Members
Namespace: Microsoft.ML.Probabilistic.Distributions
Assembly: Microsoft.ML.Probabilistic.dll
Syntax
[Serializable]
[DataContract]
[Quality(QualityBand.Mature)]
public class VectorGaussianMoments : IDistribution<Vector>, IDistribution, ICloneable, HasPoint<Vector>, CanGetLogProb<Vector>, SettableTo<VectorGaussianMoments>, SettableToProduct<VectorGaussianMoments>, SettableToProduct<VectorGaussianMoments, VectorGaussianMoments>, Diffable, SettableToUniform, SettableToRatio<VectorGaussianMoments>, SettableToRatio<VectorGaussianMoments, VectorGaussianMoments>, SettableToPower<VectorGaussianMoments>, SettableToWeightedSum<VectorGaussianMoments>, Sampleable<Vector>, CanGetMean<DenseVector>, CanGetVariance<PositiveDefiniteMatrix>, CanGetMeanAndVariance<Vector, PositiveDefiniteMatrix>, CanSetMeanAndVariance<Vector, PositiveDefiniteMatrix>, CanGetLogAverageOf<VectorGaussianMoments>, CanGetLogAverageOfPower<VectorGaussianMoments>, CanGetAverageLog<VectorGaussianMoments>, CanGetLogNormalizer, CanGetMode<DenseVector>
Remarks
The distribution is parameterized by Mean and Variance.
Some special cases: If the variance is infinite along the diagonal, then the distribution is uniform. If the variance is zero, then the distribution is a point mass. The Point property gives the location of the point mass. If variance[i,i] is zero, then the distribution is a point mass along dimension i. Point[i] gives the mean. The rest of the row and column of variance must be zero.
The formula for the distribution is:
N(x;m,v) = |2*pi*v|^(-d/2) * exp(-0.5 (x-m)' inv(v) (x-m))
.
When v=0, this reduces to delta(x-m).
When v=infinity, the density is redefined to be 1.
When v is singular, the density is redefined to be exp(-0.5 (x-m)' inv(v) (x-m))
,
i.e. we drop the terms |2*pi*v|^(-d/2)
.
Constructors
VectorGaussianMoments()
Constructs a new VectorGaussian
Declaration
protected VectorGaussianMoments()
VectorGaussianMoments(VectorGaussianMoments)
Sets this VectorGaussian to the value of another
Declaration
public VectorGaussianMoments(VectorGaussianMoments that)
Parameters
Type | Name | Description |
---|---|---|
VectorGaussianMoments | that |
VectorGaussianMoments(Vector, PositiveDefiniteMatrix)
Creates a Gaussian with given mean and variance.
Declaration
public VectorGaussianMoments(Vector mean, PositiveDefiniteMatrix variance)
Parameters
Type | Name | Description |
---|---|---|
Vector | mean | Mean |
PositiveDefiniteMatrix | variance | Variance |
Remarks
The mean and variance objects are copied into the Gaussian and not referenced afterwards.
VectorGaussianMoments(Double, Double)
Creates a 1D VectorGaussian with given mean and variance.
Declaration
public VectorGaussianMoments(double mean, double variance)
Parameters
Type | Name | Description |
---|---|---|
Double | mean | Mean |
Double | variance | Variance |
VectorGaussianMoments(Int32)
Creates a uniform VectorGaussian of a given dimension
Declaration
public VectorGaussianMoments(int dimension)
Parameters
Type | Name | Description |
---|---|---|
Int32 | dimension | The dimension |
Properties
Dimension
The dimension of the VectorGaussian domain
Declaration
[IgnoreDataMember]
public int Dimension { get; }
Property Value
Type | Description |
---|---|
Int32 |
IsPointMass
Asks whether the instance is a point mass
Declaration
[IgnoreDataMember]
public bool IsPointMass { get; }
Property Value
Type | Description |
---|---|
Boolean |
Mean
Gets/Sets the mean vector
Declaration
public Vector Mean { get; set; }
Property Value
Type | Description |
---|---|
Vector |
Point
Sets/gets the instance as a point mass
Declaration
[IgnoreDataMember]
public Vector Point { get; set; }
Property Value
Type | Description |
---|---|
Vector |
Variance
Gets/sets the variance matrix
Declaration
public PositiveDefiniteMatrix Variance { get; set; }
Property Value
Type | Description |
---|---|
PositiveDefiniteMatrix |
Methods
Clone()
Clones this VectorGaussian.
Declaration
public object Clone()
Returns
Type | Description |
---|---|
Object | An object which is a clone of the current instance. This must be cast if you want to assign the result to a VectorGaussian type |
Copy(VectorGaussianMoments)
Creates a copy of a given VectorGaussian
Declaration
public static VectorGaussianMoments Copy(VectorGaussianMoments that)
Parameters
Type | Name | Description |
---|---|---|
VectorGaussianMoments | that |
Returns
Type | Description |
---|---|
VectorGaussianMoments |
Equals(Object)
Override of the Equals method
Declaration
public override bool Equals(object thatd)
Parameters
Type | Name | Description |
---|---|---|
Object | thatd | The instance to compare to |
Returns
Type | Description |
---|---|
Boolean | True if the two distributions are the same in value, false otherwise |
Overrides
FromMeanAndPrecision(Vector, PositiveDefiniteMatrix)
Create a VectorGaussian with given mean and precision matrix.
Declaration
public static VectorGaussianMoments FromMeanAndPrecision(Vector mean, PositiveDefiniteMatrix precision)
Parameters
Type | Name | Description |
---|---|---|
Vector | mean | Mean |
PositiveDefiniteMatrix | precision | Precision |
Returns
Type | Description |
---|---|
VectorGaussianMoments | A new VectorGaussian object. |
FromMeanAndPrecision(Double, Double)
Creates a 1D VectorGaussian with given mean and precision.
Declaration
public static VectorGaussianMoments FromMeanAndPrecision(double mean, double precision)
Parameters
Type | Name | Description |
---|---|---|
Double | mean | Mean |
Double | precision | Precision |
Returns
Type | Description |
---|---|
VectorGaussianMoments | A new VectorGaussian object. |
FromMeanAndVariance(Vector, PositiveDefiniteMatrix)
Create a Gaussian with given mean and variance.
Declaration
public static VectorGaussianMoments FromMeanAndVariance(Vector mean, PositiveDefiniteMatrix variance)
Parameters
Type | Name | Description |
---|---|---|
Vector | mean | Mean |
PositiveDefiniteMatrix | variance | Variance |
Returns
Type | Description |
---|---|
VectorGaussianMoments | A new Gaussian instance. |
Remarks
The mean and variance objects are copied into the Gaussian and not referenced afterwards.
FromMeanAndVariance(Double, Double)
Creates a 1D VectorGaussian with given mean and variance.
Declaration
public static VectorGaussianMoments FromMeanAndVariance(double mean, double variance)
Parameters
Type | Name | Description |
---|---|---|
Double | mean | Mean |
Double | variance | Variance |
Returns
Type | Description |
---|---|
VectorGaussianMoments | A new VectorGaussian object. |
GetAverageLog(VectorGaussianMoments)
The expected logarithm of that distribution under this distribution.
Declaration
public double GetAverageLog(VectorGaussianMoments that)
Parameters
Type | Name | Description |
---|---|---|
VectorGaussianMoments | that | The distribution to take the logarithm of. |
Returns
Type | Description |
---|---|
Double |
|
Remarks
This is also known as the cross entropy.
GetHashCode()
Override of GetHashCode method
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
Int32 | The hash code for this instance |
Overrides
GetLogAverageOf(VectorGaussianMoments)
Log-integral of the product of this VectorGaussian with that VectorGaussian
Declaration
public double GetLogAverageOf(VectorGaussianMoments that)
Parameters
Type | Name | Description |
---|---|---|
VectorGaussianMoments | that | That VectorGaussian |
Returns
Type | Description |
---|---|
Double | The log inner product |
GetLogAverageOfPower(VectorGaussianMoments, Double)
Get the integral of this distribution times another distribution raised to a power.
Declaration
public double GetLogAverageOfPower(VectorGaussianMoments that, double power)
Parameters
Type | Name | Description |
---|---|---|
VectorGaussianMoments | that | |
Double | power |
Returns
Type | Description |
---|---|
Double |
GetLogNormalizer()
Gets the normalizer for the VectorGaussian density function
Declaration
public double GetLogNormalizer()
Returns
Type | Description |
---|---|
Double |
GetLogProb(Vector)
Evaluates the log of the multivariate Gaussian density.
Declaration
public double GetLogProb(Vector x)
Parameters
Type | Name | Description |
---|---|---|
Vector | x | Point to evaluate the density at. |
Returns
Type | Description |
---|---|
Double | log p(x) |
GetMarginal(Int32)
The marginal distribution of one dimension.
Declaration
public Gaussian GetMarginal(int dim)
Parameters
Type | Name | Description |
---|---|---|
Int32 | dim |
Returns
Type | Description |
---|---|
Gaussian |
GetMarginal(Int32, VectorGaussianMoments)
The marginal distribution of a subvector.
Declaration
public VectorGaussianMoments GetMarginal(int firstDim, VectorGaussianMoments result)
Parameters
Type | Name | Description |
---|---|---|
Int32 | firstDim | The first dimension of the subvector |
VectorGaussianMoments | result | A VectorGaussian receiving the result, whose Dimension specifies the length of the subvector. |
Returns
Type | Description |
---|---|
VectorGaussianMoments |
|
GetMean()
Gets the mean of the distribution.
Declaration
public DenseVector GetMean()
Returns
Type | Description |
---|---|
DenseVector | A new Vector. |
GetMean(Vector)
Gets the mean of the distribution
Declaration
public Vector GetMean(Vector result)
Parameters
Type | Name | Description |
---|---|---|
Vector | result | Where to place the mean value |
Returns
Type | Description |
---|---|
Vector | mean |
GetMeanAndPrecision(Vector, PositiveDefiniteMatrix)
Gets the mean vector and precision matrix of the distribution
Declaration
public void GetMeanAndPrecision(Vector mean, PositiveDefiniteMatrix precision)
Parameters
Type | Name | Description |
---|---|---|
Vector | mean | Modified to contain the mean. Must already be the correct size. |
PositiveDefiniteMatrix | precision | Modified to contain the precision matrix. Must already be the correct size. |
GetMeanAndVariance(Vector, PositiveDefiniteMatrix)
Gets the mean and variance of the distribution.
Declaration
public void GetMeanAndVariance(Vector mean, PositiveDefiniteMatrix variance)
Parameters
Type | Name | Description |
---|---|---|
Vector | mean | Modified to contain the mean. Must already be the correct size. |
PositiveDefiniteMatrix | variance | Modified to contain the covariance matrix. Must already be the correct size. |
Remarks
Because the Gaussian stored its parameters in exponential form, it is more efficient to compute the mean and variance at the same time rather than separately.
GetMode()
The most likely value
Declaration
public DenseVector GetMode()
Returns
Type | Description |
---|---|
DenseVector | A new Vector. |
GetVariance()
Gets the variance-covariance matrix of the distribution.
Declaration
public PositiveDefiniteMatrix GetVariance()
Returns
Type | Description |
---|---|
PositiveDefiniteMatrix | A new PositiveDefiniteMatrix. |
GetVariance(PositiveDefiniteMatrix)
Gets the variance-covariance matrix of the distribution.
Declaration
public PositiveDefiniteMatrix GetVariance(PositiveDefiniteMatrix variance)
Parameters
Type | Name | Description |
---|---|---|
PositiveDefiniteMatrix | variance | Where to place the variance-covariance |
Returns
Type | Description |
---|---|
PositiveDefiniteMatrix | variance |
IsProper()
Asks whether this VectorGaussian instance is proper or not. A VectorGaussian distribution is proper only if its precision matrix is positive definite.
Declaration
public bool IsProper()
Returns
Type | Description |
---|---|
Boolean | True if proper, false otherwise |
IsUniform()
Asks whether this instance is uniform
Declaration
public bool IsUniform()
Returns
Type | Description |
---|---|
Boolean | True if uniform, false otherwise |
MaxDiff(Object)
The maximum difference between the parameters of this VectorGaussian and that VectorGaussian
Declaration
public double MaxDiff(object thatd)
Parameters
Type | Name | Description |
---|---|---|
Object | thatd | That VectorGaussian |
Returns
Type | Description |
---|---|
Double | The maximum difference |
PointMass(Vector)
Creates a VectorGaussian point mass at the specified location
Declaration
[Construction(new string[]{"Point"}, UseWhen = "IsPointMass")]
public static VectorGaussianMoments PointMass(Vector mean)
Parameters
Type | Name | Description |
---|---|---|
Vector | mean | Where to position the point mass |
Returns
Type | Description |
---|---|
VectorGaussianMoments | A new point mass VectorGaussian |
PointMass(Double)
Creates a VectorGaussian point mass where the location is a vector of identical values
Declaration
public static VectorGaussianMoments PointMass(double mean)
Parameters
Type | Name | Description |
---|---|---|
Double | mean | The value for the mean vector |
Returns
Type | Description |
---|---|
VectorGaussianMoments | A new point mass VectorGaussian |
Sample()
Sample from this VectorGaussian distribution
Declaration
public Vector Sample()
Returns
Type | Description |
---|---|
Vector | The sample value |
Sample(Vector)
Samples from this VectorGaussian distribution
Declaration
public Vector Sample(Vector result)
Parameters
Type | Name | Description |
---|---|---|
Vector | result | Where to put the result |
Returns
Type | Description |
---|---|
Vector | The sample value |
SetMeanAndPrecision(Vector, PositiveDefiniteMatrix)
Sets the mean and precision of the distribution.
Declaration
public void SetMeanAndPrecision(Vector mean, PositiveDefiniteMatrix precision)
Parameters
Type | Name | Description |
---|---|---|
Vector | mean | The mean vector |
PositiveDefiniteMatrix | precision | The precision matrix |
SetMeanAndVariance(Vector, PositiveDefiniteMatrix)
Sets the mean and variance of the distribution.
Declaration
public void SetMeanAndVariance(Vector mean, PositiveDefiniteMatrix variance)
Parameters
Type | Name | Description |
---|---|---|
Vector | mean | The mean vector. Cannot be the same object as |
PositiveDefiniteMatrix | variance | The covariance matrix. Can be the same object as |
SetNatural(Vector, PositiveDefiniteMatrix)
Sets the natural parameters of the distribution (mean times precision, and precision)
Declaration
public void SetNatural(Vector meanTimesPrecision, PositiveDefiniteMatrix precision)
Parameters
Type | Name | Description |
---|---|---|
Vector | meanTimesPrecision | Mean times precision |
PositiveDefiniteMatrix | precision | The precision matrix |
SetTo(VectorGaussianMoments)
Sets this VectorGaussian instance to have the parameter values of that VectorGaussian instance
Declaration
public void SetTo(VectorGaussianMoments that)
Parameters
Type | Name | Description |
---|---|---|
VectorGaussianMoments | that | That VectorGaussian |
SetToPointMass()
Sets this instance to a point mass. The location of the point mass is the existing mean vector
Declaration
protected void SetToPointMass()
SetToPower(VectorGaussianMoments, Double)
Sets the parameters to represent the power of a source VectorGaussian to some exponent.
Declaration
public void SetToPower(VectorGaussianMoments dist, double exponent)
Parameters
Type | Name | Description |
---|---|---|
VectorGaussianMoments | dist | The source VectorGaussian |
Double | exponent | The exponent |
SetToProduct(VectorGaussianMoments, VectorGaussianMoments)
Sets the parameters to represent the product of two VectorGaussians.
Declaration
public void SetToProduct(VectorGaussianMoments g1, VectorGaussianMoments g2)
Parameters
Type | Name | Description |
---|---|---|
VectorGaussianMoments | g1 | The first VectorGaussian. May refer to |
VectorGaussianMoments | g2 | The second VectorGaussian. May refer to |
Remarks
The result may not be proper. No error is thrown in this case.
SetToProduct(VectorGaussianMoments, IList<Gaussian>)
Declaration
public void SetToProduct(VectorGaussianMoments vector, IList<Gaussian> array)
Parameters
Type | Name | Description |
---|---|---|
VectorGaussianMoments | vector | |
IList<Gaussian> | array |
SetToRatio(VectorGaussianMoments, VectorGaussianMoments, Boolean)
Sets the parameters to represent the product of two VectorGaussians.
Declaration
public void SetToRatio(VectorGaussianMoments numerator, VectorGaussianMoments denominator, bool forceProper = false)
Parameters
Type | Name | Description |
---|---|---|
VectorGaussianMoments | numerator | The numerator VectorGaussian. Can be the same object as |
VectorGaussianMoments | denominator | The denominator VectorGaussian |
Boolean | forceProper | If true, the precision of the result is made non-negative definite, under the constraint that result*denominator has the same mean as numerator |
SetToSum(Double, VectorGaussianMoments, Double, VectorGaussianMoments)
Sets the mean and covariance to match a VectorGaussian mixture.
Declaration
public void SetToSum(double weight1, VectorGaussianMoments dist1, double weight2, VectorGaussianMoments dist2)
Parameters
Type | Name | Description |
---|---|---|
Double | weight1 | First weight |
VectorGaussianMoments | dist1 | First VectorGaussian |
Double | weight2 | Second weight |
VectorGaussianMoments | dist2 | Second VectorGaussian |
SetToUniform()
Sets this VectorGaussian instance to be a uniform distribution
Declaration
public void SetToUniform()
ToString()
ToString override
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String | String representation of the instance |
Overrides
Uniform(Int32)
Creates a uniform VectorGaussian of a given dimension
Declaration
[Construction(new string[]{"Dimension"}, UseWhen = "IsUniform")]
public static VectorGaussianMoments Uniform(int dimension)
Parameters
Type | Name | Description |
---|---|---|
Int32 | dimension | The dimension |
Returns
Type | Description |
---|---|
VectorGaussianMoments |
WeightedSum<T>(T, Int32, Double, T, Double, T)
Creates a distribution of the specified type which matchs the mean and variance/covariance of a VectorGaussian mixture. The distribution type must implement CanGetMeanAndVariance<MeanType, VarType> and CanSetMeanAndVariance<MeanType, VarType>
Declaration
public static T WeightedSum<T>(T result, int dimension, double weight1, T dist1, double weight2, T dist2)
where T : CanGetMeanAndVariance<Vector, PositiveDefiniteMatrix>, CanSetMeanAndVariance<Vector, PositiveDefiniteMatrix>, SettableTo<T>, SettableToUniform
Parameters
Type | Name | Description |
---|---|---|
T | result | Resulting distribution |
Int32 | dimension | The dimension of the domain |
Double | weight1 | The first weight |
T | dist1 | The first distribution |
Double | weight2 | The second weight |
T | dist2 | The second distribution |
Returns
Type | Description |
---|---|
T |
Type Parameters
Name | Description |
---|---|
T | Distribution type for the mixture |
Operators
Division(VectorGaussianMoments, VectorGaussianMoments)
Creates a new VectorGaussian which the ratio of two other VectorGaussians
Declaration
public static VectorGaussianMoments operator /(VectorGaussianMoments numerator, VectorGaussianMoments denominator)
Parameters
Type | Name | Description |
---|---|---|
VectorGaussianMoments | numerator | numerator VectorGaussian |
VectorGaussianMoments | denominator | denominator VectorGaussian |
Returns
Type | Description |
---|---|
VectorGaussianMoments | Result |
ExclusiveOr(VectorGaussianMoments, Double)
Raises a distribution to a power.
Declaration
public static VectorGaussianMoments operator ^(VectorGaussianMoments dist, double exponent)
Parameters
Type | Name | Description |
---|---|---|
VectorGaussianMoments | dist | The distribution. |
Double | exponent | The power to raise to. |
Returns
Type | Description |
---|---|
VectorGaussianMoments |
|
Multiply(VectorGaussianMoments, VectorGaussianMoments)
Creates a new VectorGaussian which the product of two other VectorGaussians
Declaration
public static VectorGaussianMoments operator *(VectorGaussianMoments a, VectorGaussianMoments b)
Parameters
Type | Name | Description |
---|---|---|
VectorGaussianMoments | a | First VectorGaussian |
VectorGaussianMoments | b | Second VectorGaussian |
Returns
Type | Description |
---|---|
VectorGaussianMoments | Result |