Struct TruncatedGaussian
A distribution over real numbers between an upper and lower bound. If both bounds are infinite, it reduces to an ordinary Gaussian distribution.
Implements
Inherited Members
Namespace: Microsoft.ML.Probabilistic.Distributions
Assembly: Microsoft.ML.Probabilistic.dll
Syntax
[Serializable]
[DataContract]
[Quality(QualityBand.Preview)]
public struct TruncatedGaussian : IDistribution<double>, IDistribution, ICloneable, HasPoint<double>, CanGetLogProb<double>, SettableTo<TruncatedGaussian>, Diffable, SettableToProduct<TruncatedGaussian>, SettableToProduct<TruncatedGaussian, TruncatedGaussian>, SettableToUniform, SettableToRatio<TruncatedGaussian>, SettableToRatio<TruncatedGaussian, TruncatedGaussian>, SettableToPower<TruncatedGaussian>, Sampleable<double>, SettableToWeightedSum<TruncatedGaussian>, CanGetMean<double>, CanGetVariance<double>, CanGetMeanAndVarianceOut<double, double>, CanGetLogNormalizer, CanGetLogAverageOf<TruncatedGaussian>, CanGetLogAverageOfPower<TruncatedGaussian>, CanGetAverageLog<TruncatedGaussian>, ITruncatableDistribution<double>, CanGetProbLessThan<double>, CanGetQuantile<double>
Remarks
The distribution is parameterized by a Gaussian and two real numbers (LowerBound, UpperBound). Between the bounds, the density is proportional to the Gaussian. Outside of the bounds, the density is zero.
Constructors
TruncatedGaussian(Gaussian)
Create a truncated Gaussian equivalent to a Gaussian, i.e. with no truncation.
Declaration
public TruncatedGaussian(Gaussian that)
Parameters
Type | Name | Description |
---|---|---|
Gaussian | that |
TruncatedGaussian(Gaussian, Double, Double)
Create a truncated Gaussian from a Gaussian and bounds
Declaration
[Construction(new string[]{"Gaussian", "LowerBound", "UpperBound"})]
public TruncatedGaussian(Gaussian gaussian, double lowerBound, double upperBound)
Parameters
Type | Name | Description |
---|---|---|
Gaussian | gaussian | |
Double | lowerBound | |
Double | upperBound |
TruncatedGaussian(TruncatedGaussian)
Create a new TruncatedGaussian distribution equal to that
Declaration
public TruncatedGaussian(TruncatedGaussian that)
Parameters
Type | Name | Description |
---|---|---|
TruncatedGaussian | that |
TruncatedGaussian(Double, Double, Double, Double)
Create a truncated Gaussian from untruncated (mean, variance) and bounds
Declaration
public TruncatedGaussian(double mean, double variance, double lowerBound, double upperBound)
Parameters
Type | Name | Description |
---|---|---|
Double | mean | |
Double | variance | |
Double | lowerBound | |
Double | upperBound |
Fields
Gaussian
Untruncated Gaussian
Declaration
[DataMember]
public Gaussian Gaussian
Field Value
Type | Description |
---|---|
Gaussian |
LowerBound
Lower bound
Declaration
[DataMember]
public double LowerBound
Field Value
Type | Description |
---|---|
Double |
UpperBound
Upper bound
Declaration
[DataMember]
public double UpperBound
Field Value
Type | Description |
---|---|
Double |
Properties
IsPointMass
True if the distribution is a point mass.
Declaration
[IgnoreDataMember]
public readonly bool IsPointMass { get; }
Property Value
Type | Description |
---|---|
Boolean |
Point
Set this distribution to a point mass, or get its location
Declaration
[IgnoreDataMember]
public double Point { get; set; }
Property Value
Type | Description |
---|---|
Double |
Methods
Clone()
Make a deep copy of this distribution.
Declaration
public object Clone()
Returns
Type | Description |
---|---|
Object |
Equals(Object)
True if this distribution has the same parameters as that
Declaration
public override bool Equals(object thatd)
Parameters
Type | Name | Description |
---|---|---|
Object | thatd | The instance to compare to |
Returns
Type | Description |
---|---|
Boolean |
Overrides
FromGaussian(Gaussian)
Create a truncated Gaussian equivalent to a Gaussian, i.e. with no truncation.
Declaration
public static TruncatedGaussian FromGaussian(Gaussian gaussian)
Parameters
Type | Name | Description |
---|---|---|
Gaussian | gaussian |
Returns
Type | Description |
---|---|
TruncatedGaussian |
GetAverageLog(TruncatedGaussian)
Get the average logarithm of that distribution under this distribution, i.e. int this(x) log( that(x) ) dx
Declaration
public double GetAverageLog(TruncatedGaussian that)
Parameters
Type | Name | Description |
---|---|---|
TruncatedGaussian | that |
Returns
Type | Description |
---|---|
Double |
GetHashCode()
A hash of the distribution parameter values
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
Int32 |
Overrides
GetLogAverageOf(TruncatedGaussian)
Get the logarithm of the average value of that distribution under this distribution, i.e. log(int this(x) that(x) dx)
Declaration
public double GetLogAverageOf(TruncatedGaussian that)
Parameters
Type | Name | Description |
---|---|---|
TruncatedGaussian | that |
Returns
Type | Description |
---|---|
Double |
GetLogAverageOfPower(TruncatedGaussian, Double)
Get the integral of this distribution times another distribution raised to a power.
Declaration
public double GetLogAverageOfPower(TruncatedGaussian that, double power)
Parameters
Type | Name | Description |
---|---|---|
TruncatedGaussian | that | |
Double | power |
Returns
Type | Description |
---|---|
Double |
GetLogNormalizer()
Gets the log of the normalizer for the Gaussian density function
Declaration
public double GetLogNormalizer()
Returns
Type | Description |
---|---|
Double |
GetLogProb(Double)
Get the log probability density at value.
Declaration
public double GetLogProb(double value)
Parameters
Type | Name | Description |
---|---|---|
Double | value |
Returns
Type | Description |
---|---|
Double |
GetMean()
Returns the mean (first moment) of the distribution
Declaration
public double GetMean()
Returns
Type | Description |
---|---|
Double |
GetMeanAndVariance(out Double, out Double)
Get the mean and variance after truncation.
Declaration
public void GetMeanAndVariance(out double mean, out double variance)
Parameters
Type | Name | Description |
---|---|---|
Double | mean | |
Double | variance |
GetProbBetween(Double, Double)
Returns the probability mass in an interval.
Declaration
public double GetProbBetween(double lowerBound, double upperBound)
Parameters
Type | Name | Description |
---|---|---|
Double | lowerBound | |
Double | upperBound |
Returns
Type | Description |
---|---|
Double | A number between 0 and 1, inclusive. |
GetProbLessThan(Double)
Returns the probability of drawing a sample less than x.
Declaration
public double GetProbLessThan(double x)
Parameters
Type | Name | Description |
---|---|---|
Double | x |
Returns
Type | Description |
---|---|
Double | A real number in [0,1]. |
GetQuantile(Double)
Returns the largest value x such that GetProbLessThan(x) <= probability.
Declaration
public double GetQuantile(double probability)
Parameters
Type | Name | Description |
---|---|---|
Double | probability | A real number in [0,1]. |
Returns
Type | Description |
---|---|
Double | A number |
GetVariance()
Get the variance of this distribution
Declaration
public double GetVariance()
Returns
Type | Description |
---|---|
Double |
IsProper()
Returns true if this distribution is proper
Declaration
public bool IsProper()
Returns
Type | Description |
---|---|
Boolean |
IsUniform()
Asks whether this instance is uniform. If the upper and lower bounds are finite the distribution is not uniform.
Declaration
public bool IsUniform()
Returns
Type | Description |
---|---|
Boolean | True if uniform, false otherwise |
MaxDiff(Object)
The maximum difference between the parameters of this distribution and that
Declaration
public double MaxDiff(object thatd)
Parameters
Type | Name | Description |
---|---|---|
Object | thatd |
Returns
Type | Description |
---|---|
Double |
PointMass(Double)
Create a point mass distribution.
Declaration
[Construction(new string[]{"Point"}, UseWhen = "IsPointMass")]
public static TruncatedGaussian PointMass(double point)
Parameters
Type | Name | Description |
---|---|---|
Double | point | The location of the point mass |
Returns
Type | Description |
---|---|
TruncatedGaussian | A new TruncatedGaussian with all probability concentrated on the given point. |
Sample()
Sample from the distribution
Declaration
public double Sample()
Returns
Type | Description |
---|---|
Double | The sample value |
Sample(Double)
Sample from the distribution
Declaration
public double Sample(double result)
Parameters
Type | Name | Description |
---|---|---|
Double | result | Ignored |
Returns
Type | Description |
---|---|
Double | The sample value |
Sample(Double, Double, Double, Double)
Sample from a TruncatedGaussian distribution with the specified parameters
Declaration
public static double Sample(double mean, double precision, double lowerBound, double upperBound)
Parameters
Type | Name | Description |
---|---|---|
Double | mean | |
Double | precision | |
Double | lowerBound | |
Double | upperBound |
Returns
Type | Description |
---|---|
Double | The sample value |
SetTo(TruncatedGaussian)
Set this distribution equal to value.
Declaration
public void SetTo(TruncatedGaussian value)
Parameters
Type | Name | Description |
---|---|---|
TruncatedGaussian | value |
SetToPower(TruncatedGaussian, Double)
Set this equal to (dist)^exponent
Declaration
public void SetToPower(TruncatedGaussian dist, double exponent)
Parameters
Type | Name | Description |
---|---|---|
TruncatedGaussian | dist | |
Double | exponent |
SetToProduct(TruncatedGaussian, TruncatedGaussian)
Set this distribution equal to the product of a and b
Declaration
public void SetToProduct(TruncatedGaussian a, TruncatedGaussian b)
Parameters
Type | Name | Description |
---|---|---|
TruncatedGaussian | a | |
TruncatedGaussian | b |
SetToRatio(TruncatedGaussian, TruncatedGaussian, Boolean)
Set this equal to numerator/denominator
Declaration
public void SetToRatio(TruncatedGaussian numerator, TruncatedGaussian denominator, bool forceProper = false)
Parameters
Type | Name | Description |
---|---|---|
TruncatedGaussian | numerator | |
TruncatedGaussian | denominator | |
Boolean | forceProper |
SetToSum(Double, TruncatedGaussian, Double, TruncatedGaussian)
Set the parameters to match the moments of a mixture distribution.
Declaration
public void SetToSum(double weight1, TruncatedGaussian dist1, double weight2, TruncatedGaussian dist2)
Parameters
Type | Name | Description |
---|---|---|
Double | weight1 | The first weight |
TruncatedGaussian | dist1 | The first distribution |
Double | weight2 | The second weight |
TruncatedGaussian | dist2 | The second distribution |
SetToUniform()
Set the distribution to uniform with infinite bounds
Declaration
public void SetToUniform()
ToGaussian()
Get the Gaussian with the same moments as this truncated Gaussian.
Declaration
public Gaussian ToGaussian()
Returns
Type | Description |
---|---|
Gaussian |
ToString()
A human-readable string containing the parameters of the distribution
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String | String representation of the instance |
Overrides
Truncate(Double, Double)
Returns the distribution of values restricted to an interval.
Declaration
public ITruncatableDistribution<double> Truncate(double lowerBound, double upperBound)
Parameters
Type | Name | Description |
---|---|---|
Double | lowerBound | |
Double | upperBound |
Returns
Type | Description |
---|---|
ITruncatableDistribution<Double> |
Uniform()
Construct a uniform truncated Gaussian. This is mathematically equivalent to a uniform Gaussian.
Declaration
[Construction(UseWhen = "IsUniform")]
public static TruncatedGaussian Uniform()
Returns
Type | Description |
---|---|
TruncatedGaussian |
Operators
Division(TruncatedGaussian, TruncatedGaussian)
Operator overload for division
Declaration
public static TruncatedGaussian operator /(TruncatedGaussian numerator, TruncatedGaussian denominator)
Parameters
Type | Name | Description |
---|---|---|
TruncatedGaussian | numerator | |
TruncatedGaussian | denominator |
Returns
Type | Description |
---|---|
TruncatedGaussian |
Equality(TruncatedGaussian, TruncatedGaussian)
Equals operator
Declaration
public static bool operator ==(TruncatedGaussian a, TruncatedGaussian b)
Parameters
Type | Name | Description |
---|---|---|
TruncatedGaussian | a | |
TruncatedGaussian | b |
Returns
Type | Description |
---|---|
Boolean |
ExclusiveOr(TruncatedGaussian, Double)
Operator overload for exponentation
Declaration
public static TruncatedGaussian operator ^(TruncatedGaussian dist, double exponent)
Parameters
Type | Name | Description |
---|---|---|
TruncatedGaussian | dist | |
Double | exponent |
Returns
Type | Description |
---|---|
TruncatedGaussian |
Inequality(TruncatedGaussian, TruncatedGaussian)
Not equals operator
Declaration
public static bool operator !=(TruncatedGaussian a, TruncatedGaussian b)
Parameters
Type | Name | Description |
---|---|---|
TruncatedGaussian | a | |
TruncatedGaussian | b |
Returns
Type | Description |
---|---|
Boolean |
Multiply(TruncatedGaussian, TruncatedGaussian)
Operator overload for product.
Declaration
public static TruncatedGaussian operator *(TruncatedGaussian a, TruncatedGaussian b)
Parameters
Type | Name | Description |
---|---|---|
TruncatedGaussian | a | |
TruncatedGaussian | b |
Returns
Type | Description |
---|---|
TruncatedGaussian |