Struct TruncatedGamma
A distribution over real numbers between an upper and lower bound. If LowerBound=0 and UpperBound=Inf, it reduces to an ordinary Gamma distribution.
Assembly: Microsoft.ML.Probabilistic.dll
Syntax
[Serializable]
[DataContract]
[Quality(QualityBand.Preview)]
public struct TruncatedGamma : IDistribution<double>, IDistribution, ICloneable, HasPoint<double>, CanGetLogProb<double>, SettableTo<TruncatedGamma>, Diffable, SettableToProduct<TruncatedGamma>, SettableToProduct<TruncatedGamma, TruncatedGamma>, SettableToUniform, SettableToRatio<TruncatedGamma>, SettableToRatio<TruncatedGamma, TruncatedGamma>, SettableToPower<TruncatedGamma>, Sampleable<double>, SettableToWeightedSum<TruncatedGamma>, CanGetMean<double>, CanGetVariance<double>, CanGetMeanAndVarianceOut<double, double>, CanGetLogNormalizer, CanGetLogAverageOf<TruncatedGamma>, CanGetLogAverageOfPower<TruncatedGamma>, CanGetAverageLog<TruncatedGamma>, CanGetMode<double>, CanGetProbLessThan<double>, CanGetQuantile<double>
Constructors
TruncatedGamma(Gamma)
Create a truncated Gamma equivalent to a Gamma, i.e. with no truncation.
Declaration
public TruncatedGamma(Gamma that)
Parameters
Type |
Name |
Description |
Gamma |
that |
|
TruncatedGamma(Gamma, Double, Double)
Create a truncated Gamma from a Gamma and bounds
Declaration
[Construction(new string[]{"Gamma", "LowerBound", "UpperBound"})]
public TruncatedGamma(Gamma Gamma, double lowerBound, double upperBound)
Parameters
TruncatedGamma(TruncatedGamma)
Create a new TruncatedGamma distribution equal to that
Declaration
public TruncatedGamma(TruncatedGamma that)
Parameters
TruncatedGamma(Double, Double, Double, Double)
Create a truncated Gamma from untruncated (shape, scale) and bounds
Declaration
public TruncatedGamma(double shape, double scale, double lowerBound, double upperBound)
Parameters
Fields
Gamma
Declaration
[DataMember]
public Gamma Gamma
Field Value
LowerBound
Declaration
[DataMember]
public double LowerBound
Field Value
UpperBound
Declaration
[DataMember]
public double UpperBound
Field Value
Properties
IsPointMass
True if the distribution is a point mass.
Declaration
[IgnoreDataMember]
public readonly bool IsPointMass { get; }
Property Value
Point
Set this distribution to a point mass, or get its location
Declaration
[IgnoreDataMember]
public double Point { get; set; }
Property Value
Methods
Clone()
Make a deep copy of this distribution.
Declaration
Returns
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
Overrides
FromGamma(Gamma)
Create a truncated Gamma equivalent to a Gamma, i.e. with no truncation.
Declaration
public static TruncatedGamma FromGamma(Gamma Gamma)
Parameters
Type |
Name |
Description |
Gamma |
Gamma |
|
Returns
GammaProbBetween(Double, Double, Double, Double, Boolean)
Computes GammaLower(a, ru) - GammaLower(a, rl) to high accuracy.
Declaration
public static double GammaProbBetween(double shape, double rate, double lowerBound, double upperBound, bool regularized = true)
Parameters
Returns
GammaUpperRatio(Double, Double, Boolean)
Computes GammaUpper(s,x)/(x^(s-1)*exp(-x)) - 1
to high accuracy
Declaration
public static double GammaUpperRatio(double s, double x, bool regularized = true)
Parameters
Type |
Name |
Description |
Double |
s |
|
Double |
x |
A real number gt;= 45 and gt; s /0.99
|
Boolean |
regularized |
|
Returns
GetAverageLog(TruncatedGamma)
Get the average logarithm of that distribution under this distribution, i.e. int this(x) log( that(x) ) dx
Declaration
public double GetAverageLog(TruncatedGamma that)
Parameters
Returns
GetHashCode()
A hash of the distribution parameter values
Declaration
public override int GetHashCode()
Returns
Overrides
GetLogAverageOf(TruncatedGamma)
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(TruncatedGamma that)
Parameters
Returns
GetLogAverageOfPower(TruncatedGamma, Double)
Get the integral of this distribution times another distribution raised to a power.
Declaration
public double GetLogAverageOfPower(TruncatedGamma that, double power)
Parameters
Returns
GetLogNormalizer()
Gets the log of the normalizer for the truncated Gamma density function
Declaration
public double GetLogNormalizer()
Returns
GetLogProb(Double)
Get the log probability density at value.
Declaration
public double GetLogProb(double value)
Parameters
Type |
Name |
Description |
Double |
value |
|
Returns
GetMean()
Returns the mean (first moment) of the distribution
Declaration
Returns
GetMeanAndVariance(out Double, out Double)
Get the mean and variance after truncation.
Declaration
public void GetMeanAndVariance(out double mean, out double variance)
Parameters
GetMeanLog()
Gets E[log(x)] after truncation.
Declaration
public double GetMeanLog()
Returns
GetMeanPower(Double)
Declaration
public double GetMeanPower(double power)
Parameters
Type |
Name |
Description |
Double |
power |
|
Returns
GetMode()
Get the mode (highest density point) of this distribution
Declaration
Returns
GetNormalizer()
Gets the normalizer for the truncated Gamma density function
Declaration
public double GetNormalizer()
Returns
GetProbBetween(Double, Double)
Returns the probability mass in an interval.
Declaration
public double GetProbBetween(double lowerBound, double upperBound)
Parameters
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(Gamma, Double, Double, Double)
Declaration
public static double GetQuantile(Gamma gamma, double lowerBound, double upperBound, double probability)
Parameters
Returns
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
IsProper()
Returns true if this distribution is proper
Declaration
Returns
Asks whether this instance is uniform. If the upper and lower bounds are finite the distribution
is not uniform.
Declaration
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
PointMass(Double)
Create a point mass distribution.
Declaration
[Construction(new string[]{"Point"}, UseWhen = "IsPointMass")]
public static TruncatedGamma PointMass(double point)
Parameters
Type |
Name |
Description |
Double |
point |
The location of the point mass
|
Returns
Type |
Description |
TruncatedGamma |
A new TruncatedGamma with all probability concentrated on the given point.
|
Sample()
Sample from the distribution
Declaration
Returns
Type |
Description |
Double |
The sample value
|
Sample(Gamma, Double, Double)
Sample from a TruncatedGamma distribution with the specified parameters
Declaration
public static double Sample(Gamma gamma, double lowerBound, double upperBound)
Parameters
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
|
SetTo(TruncatedGamma)
Set this distribution equal to value.
Declaration
public void SetTo(TruncatedGamma value)
Parameters
SetToPower(TruncatedGamma, Double)
Set this equal to (dist)^exponent
Declaration
public void SetToPower(TruncatedGamma dist, double exponent)
Parameters
SetToProduct(TruncatedGamma, TruncatedGamma)
Set this distribution equal to the product of a and b
Declaration
public void SetToProduct(TruncatedGamma a, TruncatedGamma b)
Parameters
SetToRatio(TruncatedGamma, TruncatedGamma, Boolean)
Set this equal to numerator/denominator
Declaration
public void SetToRatio(TruncatedGamma numerator, TruncatedGamma denominator, bool forceProper = false)
Parameters
SetToSum(Double, TruncatedGamma, Double, TruncatedGamma)
Set the parameters to match the moments of a mixture distribution.
Declaration
public void SetToSum(double weight1, TruncatedGamma dist1, double weight2, TruncatedGamma dist2)
Parameters
Set the distribution to uniform with infinite bounds
Declaration
public void SetToUniform()
ToGamma()
Get the Gamma with the same moments as this truncated Gamma.
Declaration
Returns
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
Construct a uniform truncated Gamma. This is mathematically equivalent to
a uniform Gamma.
Declaration
[Construction(UseWhen = "IsUniform")]
public static TruncatedGamma Uniform()
Returns
Operators
Division(TruncatedGamma, TruncatedGamma)
Operator overload for division
Declaration
public static TruncatedGamma operator /(TruncatedGamma numerator, TruncatedGamma denominator)
Parameters
Returns
Equality(TruncatedGamma, TruncatedGamma)
Declaration
public static bool operator ==(TruncatedGamma a, TruncatedGamma b)
Parameters
Returns
ExclusiveOr(TruncatedGamma, Double)
Operator overload for exponentation
Declaration
public static TruncatedGamma operator ^(TruncatedGamma dist, double exponent)
Parameters
Returns
Inequality(TruncatedGamma, TruncatedGamma)
Declaration
public static bool operator !=(TruncatedGamma a, TruncatedGamma b)
Parameters
Returns
Multiply(TruncatedGamma, TruncatedGamma)
Operator overload for product.
Declaration
public static TruncatedGamma operator *(TruncatedGamma a, TruncatedGamma b)
Parameters
Returns
Implements