Struct ConjugateDirichlet
Represents the distribution proportion to x^{Shape-1} exp(-Ratex) / B(x,D)^K where B(x,D)=Gamma(x)^D/Gamma(Dx)
Implements
Inherited Members
Namespace: Microsoft.ML.Probabilistic.Distributions
Assembly: Microsoft.ML.Probabilistic.dll
Syntax
[Serializable]
[DataContract]
[Quality(QualityBand.Experimental)]
public struct ConjugateDirichlet : IDistribution<double>, IDistribution, ICloneable, HasPoint<double>, CanGetLogProb<double>, SettableTo<ConjugateDirichlet>, SettableToProduct<ConjugateDirichlet>, SettableToProduct<ConjugateDirichlet, ConjugateDirichlet>, Diffable, SettableToUniform, SettableToRatio<ConjugateDirichlet>, SettableToRatio<ConjugateDirichlet, ConjugateDirichlet>, SettableToPower<ConjugateDirichlet>, SettableToWeightedSum<ConjugateDirichlet>, Sampleable<double>, CanGetMean<double>, CanGetVariance<double>, CanGetMeanAndVarianceOut<double, double>, CanSetMeanAndVariance<double, double>, CanGetLogAverageOf<ConjugateDirichlet>, CanGetLogAverageOfPower<ConjugateDirichlet>, CanGetAverageLog<ConjugateDirichlet>, CanGetLogNormalizer
Constructors
ConjugateDirichlet(ConjugateDirichlet)
Copy constructor.
Declaration
public ConjugateDirichlet(ConjugateDirichlet that)
Parameters
| Type | Name | Description |
|---|---|---|
| ConjugateDirichlet | that |
ConjugateDirichlet(Double, Double, Double, Double)
Creates a Conjugate Dirichlet distribution with given shape and scale parameters (scale = 1/rate)
Declaration
public ConjugateDirichlet(double shape, double scale, double D, double K)
Parameters
| Type | Name | Description |
|---|---|---|
| Double | shape | |
| Double | scale | scale = 1/rate |
| Double | D | |
| Double | K |
Remarks
The distribution is x^{Shape-1} exp(-Ratex) / B(x,D)^K
where B(x,D)=Gamma(x)^D/Gamma(Dx).
Fields
approximationMethod
Approximation method to use for non-analytic expectations.
Declaration
public static ConjugateDirichlet.ApproximationMethod approximationMethod
Field Value
| Type | Description |
|---|---|
| ConjugateDirichlet.ApproximationMethod |
D
Parameter D for the distribution
Declaration
[DataMember]
public double D
Field Value
| Type | Description |
|---|---|
| Double |
K
Parameter K for the distribution
Declaration
[DataMember]
public double K
Field Value
| Type | Description |
|---|---|
| Double |
Rate
Rate parameter for the distribution
Declaration
[DataMember]
public double Rate
Field Value
| Type | Description |
|---|---|
| Double |
Shape
Shape parameter for the distribution
Declaration
[DataMember]
public double Shape
Field Value
| Type | Description |
|---|---|
| Double |
Properties
IsPointMass
Asks whether the instance is a point mass
Declaration
[IgnoreDataMember]
public readonly bool IsPointMass { get; }
Property Value
| Type | Description |
|---|---|
| Boolean |
Point
Sets/gets the instance as a point mass
Declaration
[IgnoreDataMember]
public double Point { get; set; }
Property Value
| Type | Description |
|---|---|
| Double |
Methods
Clone()
Clones this Conjugate Dirichlet.
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 Conjugate Dirichlet type |
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
FromMeanAndMeanLog(Double, Double)
Constructs a Conjugate Dirichlet distribution with the given mean and mean logarithm.
Declaration
public static ConjugateDirichlet FromMeanAndMeanLog(double mean, double meanLog)
Parameters
| Type | Name | Description |
|---|---|---|
| Double | mean | Desired expected value. |
| Double | meanLog | Desired expected logarithm. |
Returns
| Type | Description |
|---|---|
| ConjugateDirichlet | A new Gamma distribution. |
Remarks
This function is equivalent to maximum-likelihood estimation of a Gamma distribution from data given by sufficient statistics. This function is significantly slower than the other constructors since it involves nonlinear optimization. The algorithm is a generalized Newton iteration, described in "Estimating a Gamma distribution" by T. Minka, 2002.
FromMeanAndVariance(Double, Double)
Creates a new Gamma distribution from mean and variance
Declaration
public static ConjugateDirichlet FromMeanAndVariance(double mean, double variance)
Parameters
| Type | Name | Description |
|---|---|---|
| Double | mean | Mean |
| Double | variance | Variance |
Returns
| Type | Description |
|---|---|
| ConjugateDirichlet | A new Gamma instance |
FromNatural(Double, Double, Double, Double)
Constructs a Conjugate Dirichlet distribution from its natural parameters.
Declaration
public static ConjugateDirichlet FromNatural(double shapeMinus1, double rate, double D, double K)
Parameters
| Type | Name | Description |
|---|---|---|
| Double | shapeMinus1 | shape - 1 |
| Double | rate | rate = 1/scale |
| Double | D | |
| Double | K |
Returns
| Type | Description |
|---|---|
| ConjugateDirichlet | A new Conjugate Dirichlet distribution |
FromShapeAndRate(Double, Double)
Constructs a Gamma distribution with the given shape and rate parameters.
Declaration
[Construction(new string[]{"Shape", "Rate"})]
public static ConjugateDirichlet FromShapeAndRate(double shape, double rate)
Parameters
| Type | Name | Description |
|---|---|---|
| Double | shape | shape |
| Double | rate | rate = 1/scale |
Returns
| Type | Description |
|---|---|
| ConjugateDirichlet | A new Gamma distribution. |
FromShapeAndScale(Double, Double)
Constructs a Gamma distribution with the given shape and scale parameters.
Declaration
public static ConjugateDirichlet FromShapeAndScale(double shape, double scale)
Parameters
| Type | Name | Description |
|---|---|---|
| Double | shape | shape |
| Double | scale | scale |
Returns
| Type | Description |
|---|---|
| ConjugateDirichlet | A new Gamma distribution. |
GammaApproximation()
This is an asymptotic approximation to this distribution, derived from the Rocktaeschel approximation: ln Gamma(x) \approx (x-.5)ln(x) - x +.5ln(2*pi)
Declaration
public Gamma GammaApproximation()
Returns
| Type | Description |
|---|---|
| Gamma | A gamma approximation to this distribution |
GetAverageLog(ConjugateDirichlet)
The expected logarithm of that distribution under this distribution.
Declaration
public double GetAverageLog(ConjugateDirichlet that)
Parameters
| Type | Name | Description |
|---|---|---|
| ConjugateDirichlet | 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(ConjugateDirichlet)
The log of the integral of the product of this Conjugate Dirichlet and that Conjugate Dirichlet
Declaration
public double GetLogAverageOf(ConjugateDirichlet that)
Parameters
| Type | Name | Description |
|---|---|---|
| ConjugateDirichlet | that | That Conjugate Dirichlet |
Returns
| Type | Description |
|---|---|
| Double | The log inner product |
GetLogAverageOfPower(ConjugateDirichlet, Double)
Declaration
public double GetLogAverageOfPower(ConjugateDirichlet that, double power)
Parameters
| Type | Name | Description |
|---|---|---|
| ConjugateDirichlet | that | |
| Double | power |
Returns
| Type | Description |
|---|---|
| Double |
GetLogNormalizer()
Gets log normalizer
Declaration
public double GetLogNormalizer()
Returns
| Type | Description |
|---|---|
| Double |
GetLogProb(Double)
Logarithm of this Conjugate Dirichlet density function.
Declaration
public double GetLogProb(double x)
Parameters
| Type | Name | Description |
|---|---|---|
| Double | x | Where to evaluate the density |
Returns
| Type | Description |
|---|---|
| Double | log(Conjugate Dirichlet(x)) |
GetLogProb(Double, Double, Double, Double, Double)
Logarithm of the Conjugate Dirichlet density function.
Declaration
public static double GetLogProb(double x, double shape, double rate, double D, double K)
Parameters
| Type | Name | Description |
|---|---|---|
| Double | x | Where to evaluate the density |
| Double | shape | Shape parameter |
| Double | rate | Rate parameter |
| Double | D | D parameter |
| Double | K | K parameter |
Returns
| Type | Description |
|---|---|
| Double | log(Conjugate Dirichlet(x;shape,rate,D,K)) |
Remarks
The distribution is x^{Shape-1} exp(-Ratex) / B(x,D)^K
where B(x,D)=Gamma(x)^D/Gamma(Dx)
GetMean()
Gets the expected value E(x) - calculated as shape/rate
Declaration
public double GetMean()
Returns
| Type | Description |
|---|---|
| Double | E(x) |
GetMeanAndVariance(out Double, out Double)
Gets the mean and variance. Note for K!=0 this requires quadrature.
Declaration
public void GetMeanAndVariance(out double mean, out double variance)
Parameters
| Type | Name | Description |
|---|---|---|
| Double | mean | Where to put the mean |
| Double | variance | Where to put the variance |
GetMeanInverse()
Computes E[1/x]
Declaration
public double GetMeanInverse()
Returns
| Type | Description |
|---|---|
| Double |
GetMeanLog()
Computes E[log(x)] using quadrature if necessary
Declaration
public double GetMeanLog()
Returns
| Type | Description |
|---|---|
| Double | E[log(x)] |
GetMeanLogGamma(Double)
Compute E[log G(factor * x)] using quadrature
Declaration
public double GetMeanLogGamma(double factor)
Parameters
| Type | Name | Description |
|---|---|---|
| Double | factor | Multiplier for x |
Returns
| Type | Description |
|---|---|
| Double | E[log G(factor * x)] |
GetMeanPower(Double)
Computes E[x^power]
Declaration
public double GetMeanPower(double power)
Parameters
| Type | Name | Description |
|---|---|---|
| Double | power |
Returns
| Type | Description |
|---|---|
| Double |
GetMode()
Declaration
public double GetMode()
Returns
| Type | Description |
|---|---|
| Double |
GetScale()
Gets the scale (1/rate)
Declaration
public double GetScale()
Returns
| Type | Description |
|---|---|
| Double |
GetShapeAndScale(out Double, out Double)
Gets the shape and scale (1/rate)
Declaration
public void GetShapeAndScale(out double shape, out double scale)
Parameters
| Type | Name | Description |
|---|---|---|
| Double | shape | Where to put the shape |
| Double | scale | Where to put the scale |
GetUnnormalisedLogProb(Double)
Declaration
public double GetUnnormalisedLogProb(double x)
Parameters
| Type | Name | Description |
|---|---|---|
| Double | x |
Returns
| Type | Description |
|---|---|
| Double |
GetVariance()
Gets the variance - calculated as shape/rate^2
Declaration
public double GetVariance()
Returns
| Type | Description |
|---|---|
| Double | Variance |
IsProper()
Asks whether this Conjugate Dirichlet instance is proper or not. A Conjugate Dirichlet distribution is proper if it's approximating gamma is proper
Declaration
public bool IsProper()
Returns
| Type | Description |
|---|---|
| Boolean | True if proper, false otherwise |
IsProper(Double, Double)
Asks whether a Conjugate Dirichlet distribution is proper or not. A Conjugate Dirichlet distribution is proper only if Shape > 0 and Rate > 0.
Declaration
public static bool IsProper(double shape, double rate)
Parameters
| Type | Name | Description |
|---|---|---|
| Double | shape | shape parameter for the Conjugate Dirichlet |
| Double | rate | rate parameter for the Conjugate Dirichlet |
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 Conjugate Dirichlet and that Conjugate Dirichlet
Declaration
public double MaxDiff(object thatd)
Parameters
| Type | Name | Description |
|---|---|---|
| Object | thatd | That Conjugate Dirichlet |
Returns
| Type | Description |
|---|---|
| Double | The maximum difference |
Remarks
a.MaxDiff(b) == b.MaxDiff(a)
Newton1DMaximise(Double, Converter<Double, Double>, Converter<Double, Double>, Converter<Double, Double>)
Declaration
public static double Newton1DMaximise(double initx, Converter<double, double> f, Converter<double, double> dfxfunc, Converter<double, double> dhxfunc)
Parameters
| Type | Name | Description |
|---|---|---|
| Double | initx | |
| Converter<Double, Double> | f | |
| Converter<Double, Double> | dfxfunc | |
| Converter<Double, Double> | dhxfunc |
Returns
| Type | Description |
|---|---|
| Double |
PointMass(Double)
Creates a point mass Conjugate Dirichlet distribution
Declaration
public static ConjugateDirichlet PointMass(double mean)
Parameters
| Type | Name | Description |
|---|---|---|
| Double | mean | The location of the point mass |
Returns
| Type | Description |
|---|---|
| ConjugateDirichlet | A new point mass Conjugate Dirichlet distribution |
Sample()
Samples from this Conjugate Dirichlet distribution
Declaration
public double Sample()
Returns
| Type | Description |
|---|---|
| Double | The sample value |
Sample(Double)
Samples from this Conjugate Dirichlet distribution
Declaration
public double Sample(double result)
Parameters
| Type | Name | Description |
|---|---|---|
| Double | result | Ignored |
Returns
| Type | Description |
|---|---|
| Double | The sample value |
Sample(Double, Double)
Samples from a Conjugate Dirichlet distribution with given shape and scale
Declaration
public static double Sample(double shape, double scale)
Parameters
| Type | Name | Description |
|---|---|---|
| Double | shape | shape parameter |
| Double | scale | scale parameter |
Returns
| Type | Description |
|---|---|
| Double | The sample value |
SampleFromMeanAndVariance(Double, Double)
Samples from a Conjugate Dirichlet distribution with given mean and variance
Declaration
[ParameterNames(new string[]{"sample", "mean", "variance"})]
public static double SampleFromMeanAndVariance(double mean, double variance)
Parameters
| Type | Name | Description |
|---|---|---|
| Double | mean | mean parameter |
| Double | variance | variance parameter |
Returns
| Type | Description |
|---|---|
| Double | The sample value |
SetMeanAndVariance(Double, Double)
Sets the mean and variance
Declaration
public void SetMeanAndVariance(double mean, double variance)
Parameters
| Type | Name | Description |
|---|---|---|
| Double | mean | Mean |
| Double | variance | Variance |
SetNatural(Double, Double, Double, Double)
Sets the natural parameters of the distribution.
Declaration
public void SetNatural(double shapeMinus1, double rate, double D, double K)
Parameters
| Type | Name | Description |
|---|---|---|
| Double | shapeMinus1 | The shape parameter - 1. |
| Double | rate | rate = 1/scale |
| Double | D | |
| Double | K |
SetShapeAndRate(Double, Double)
Sets the shape and rate (rate = 1/scale) parameters of the distribution.
Declaration
public void SetShapeAndRate(double shape, double rate)
Parameters
| Type | Name | Description |
|---|---|---|
| Double | shape | |
| Double | rate | rate = 1/scale |
SetShapeAndScale(Double, Double)
Sets the shape and scale for this instance
Declaration
public void SetShapeAndScale(double shape, double scale)
Parameters
| Type | Name | Description |
|---|---|---|
| Double | shape | Shape |
| Double | scale | Scale |
SetTo(ConjugateDirichlet)
Sets this Conjugate Dirichlet instance to have the parameter values of that Conjugate Dirichlet instance
Declaration
public void SetTo(ConjugateDirichlet that)
Parameters
| Type | Name | Description |
|---|---|---|
| ConjugateDirichlet | that | That Conjugate Dirichlet |
SetToPower(ConjugateDirichlet, Double)
Sets the parameters to represent the power of a source Conjugate Dirichlet to some exponent.
Declaration
public void SetToPower(ConjugateDirichlet dist, double exponent)
Parameters
| Type | Name | Description |
|---|---|---|
| ConjugateDirichlet | dist | The source Conjugate Dirichlet |
| Double | exponent | The exponent |
SetToProduct(ConjugateDirichlet, ConjugateDirichlet)
Sets the parameters to represent the product of two Gammas.
Declaration
public void SetToProduct(ConjugateDirichlet a, ConjugateDirichlet b)
Parameters
| Type | Name | Description |
|---|---|---|
| ConjugateDirichlet | a | The first Conjugate Dirichlet |
| ConjugateDirichlet | b | The second Conjugate Dirichlet |
Remarks
The result may not be proper. No error is thrown in this case.
SetToRatio(ConjugateDirichlet, ConjugateDirichlet, Boolean)
Sets the parameters to represent the ratio of two Conjugate Dirichlets.
Declaration
public void SetToRatio(ConjugateDirichlet numerator, ConjugateDirichlet denominator, bool forceProper)
Parameters
| Type | Name | Description |
|---|---|---|
| ConjugateDirichlet | numerator | The numerator Conjugate Dirichlet |
| ConjugateDirichlet | denominator | The denominator Conjugate Dirichlet |
| Boolean | forceProper |
Remarks
The result may not be proper. No error is thrown in this case.
SetToSum(Double, ConjugateDirichlet, Double, ConjugateDirichlet)
Set the mean and variance to match a mixture of two Gammas.
Declaration
public void SetToSum(double weight1, ConjugateDirichlet dist1, double weight2, ConjugateDirichlet dist2)
Parameters
| Type | Name | Description |
|---|---|---|
| Double | weight1 | The first weight |
| ConjugateDirichlet | dist1 | The first Conjugate Dirichlet |
| Double | weight2 | The second weight |
| ConjugateDirichlet | dist2 | The second Conjugate Dirichlet |
SetToUniform()
Sets this Conjugate Dirichlet instance to be a uniform distribution
Declaration
public void SetToUniform()
SmartProposal(out Double, out Double)
Find a Laplace approximation to the density of this distribution under a change of variable x=log(y)
Declaration
public void SmartProposal(out double mean, out double variance)
Parameters
| Type | Name | Description |
|---|---|---|
| Double | mean | Mean of approximation |
| Double | variance | Variance of approximation |
ToString()
ToString override
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| String | String representation of the instance |
Overrides
Uniform()
Create a uniform Conjugate Dirichlet distribution.
Declaration
[Construction(UseWhen = "IsUniform")]
public static ConjugateDirichlet Uniform()
Returns
| Type | Description |
|---|---|
| ConjugateDirichlet | A new uniform Conjugate Dirichlet distribution |
Operators
Division(ConjugateDirichlet, ConjugateDirichlet)
Creates a new Conjugate Dirichlet which the ratio of two other Conjugate Dirichlets
Declaration
public static ConjugateDirichlet operator /(ConjugateDirichlet numerator, ConjugateDirichlet denominator)
Parameters
| Type | Name | Description |
|---|---|---|
| ConjugateDirichlet | numerator | numerator Conjugate Dirichlet |
| ConjugateDirichlet | denominator | denominator Conjugate Dirichlet |
Returns
| Type | Description |
|---|---|
| ConjugateDirichlet | Result |
Equality(ConjugateDirichlet, ConjugateDirichlet)
Equals operator
Declaration
public static bool operator ==(ConjugateDirichlet a, ConjugateDirichlet b)
Parameters
| Type | Name | Description |
|---|---|---|
| ConjugateDirichlet | a | |
| ConjugateDirichlet | b |
Returns
| Type | Description |
|---|---|
| Boolean |
ExclusiveOr(ConjugateDirichlet, Double)
Raises a distribution to a power.
Declaration
public static ConjugateDirichlet operator ^(ConjugateDirichlet dist, double exponent)
Parameters
| Type | Name | Description |
|---|---|---|
| ConjugateDirichlet | dist | The distribution. |
| Double | exponent | The power to raise to. |
Returns
| Type | Description |
|---|---|
| ConjugateDirichlet |
|
Inequality(ConjugateDirichlet, ConjugateDirichlet)
Not equals operator
Declaration
public static bool operator !=(ConjugateDirichlet a, ConjugateDirichlet b)
Parameters
| Type | Name | Description |
|---|---|---|
| ConjugateDirichlet | a | |
| ConjugateDirichlet | b |
Returns
| Type | Description |
|---|---|
| Boolean |
Multiply(ConjugateDirichlet, ConjugateDirichlet)
Creates a new Conjugate Dirichlet which the product of two other Conjugate Dirichlets
Declaration
public static ConjugateDirichlet operator *(ConjugateDirichlet a, ConjugateDirichlet b)
Parameters
| Type | Name | Description |
|---|---|---|
| ConjugateDirichlet | a | First Conjugate Dirichlet |
| ConjugateDirichlet | b | Second Conjugate Dirichlet |
Returns
| Type | Description |
|---|---|
| ConjugateDirichlet | Result |