Class DistributionStructArray<T, DomainType>
A distribution over an array of type DomainType
, where each element is independent and has distribution of type T
Inheritance
Implements
Inherited Members
Namespace: Microsoft.ML.Probabilistic.Distributions
Assembly: Microsoft.ML.Probabilistic.dll
Syntax
[Serializable]
[Quality(QualityBand.Mature)]
[DataContract]
public class DistributionStructArray<T, DomainType> : DistributionArray<T, DomainType>, IArray<T>, IList<T>, ICollection<T>, CanSetAllElementsTo<T>, IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable, SettableTo<T[]>, SettableTo<Array<T>>, ConvertibleToArray, IDistribution<DomainType[]>, IDistribution, ICloneable, Diffable, SettableToUniform, HasPoint<DomainType[]>, CanGetLogProb<DomainType[]>, Sampleable<DomainType[]>, IArrayFactory<T, DistributionStructArray<T, DomainType>>, SettableTo<DistributionStructArray<T, DomainType>>, SettableToProduct<DistributionStructArray<T, DomainType>>, SettableToProduct<DistributionStructArray<T, DomainType>, DistributionStructArray<T, DomainType>>, SettableToRatio<DistributionStructArray<T, DomainType>>, SettableToRatio<DistributionStructArray<T, DomainType>, DistributionStructArray<T, DomainType>>, SettableToPower<DistributionStructArray<T, DomainType>>, SettableToWeightedSum<DistributionStructArray<T, DomainType>>, CanGetLogAverageOf<DistributionStructArray<T, DomainType>>, CanGetLogAverageOfPower<DistributionStructArray<T, DomainType>>, CanGetAverageLog<DistributionStructArray<T, DomainType>> where T : struct, SettableToProduct<T>, SettableToRatio<T>, SettableToPower<T>, SettableToWeightedSum<T>, CanGetLogAverageOf<T>, CanGetLogAverageOfPower<T>, CanGetAverageLog<T>, IDistribution<DomainType>, Sampleable<DomainType>
Type Parameters
Name | Description |
---|---|
T | Distribution type of an element. Must be a value type all the way down, i.e. must not hold any references. |
DomainType | Domain type of an element |
Remarks
This is an extension of DistributionArray that requires T to be a value type. This class only exists for efficiency, to avoid unnecessary cloning.
Constructors
DistributionStructArray()
Parameterless constructor needed for serialization
Declaration
protected DistributionStructArray()
DistributionStructArray(T, Int32)
Create a new distribution struct array of a specified value and length
Declaration
public DistributionStructArray(T value, int length)
Parameters
Type | Name | Description |
---|---|---|
T | value | |
Int32 | length |
DistributionStructArray(T[])
Create a new distribution struct array from an array of distributions
Declaration
public DistributionStructArray(T[] array)
Parameters
Type | Name | Description |
---|---|---|
T[] | array |
DistributionStructArray(Array<T>)
Copy constructor
Declaration
public DistributionStructArray(Array<T> that)
Parameters
Type | Name | Description |
---|---|---|
Array<T> | that |
DistributionStructArray(Int32)
Create a new distribution struct array of a specified length
Declaration
public DistributionStructArray(int length)
Parameters
Type | Name | Description |
---|---|---|
Int32 | length |
DistributionStructArray(Int32, Func<Int32, T>)
Create a new distribution struct array of a specified length and initial values.
Declaration
public DistributionStructArray(int length, Func<int, T> init)
Parameters
Type | Name | Description |
---|---|---|
Int32 | length | |
Func<Int32, T> | init | Function that maps an index to a value. |
Methods
Clone()
Clone the distribution
Declaration
public override object Clone()
Returns
Type | Description |
---|---|
Object |
Overrides
CreateArray(Int32, Func<Int32, T>)
Declaration
public DistributionStructArray<T, DomainType> CreateArray(int length, Func<int, T> init)
Parameters
Type | Name | Description |
---|---|---|
Int32 | length | |
Func<Int32, T> | init |
Returns
Type | Description |
---|---|
DistributionStructArray<T, DomainType> |
GetAverageLog(DistributionStructArray<T, DomainType>)
The expected logarithm of that distribution under this distribution.
Declaration
public double GetAverageLog(DistributionStructArray<T, DomainType> that)
Parameters
Type | Name | Description |
---|---|---|
DistributionStructArray<T, DomainType> | that | The distribution to take the logarithm of. |
Returns
Type | Description |
---|---|
Double |
|
Remarks
This is also known as the cross entropy.
For a DistributionArray, this specializes to:
sum_i sum_x this[i].Evaluate(x)*Math.Log(that[i].Evaluate(x))
= sum_i this[i].GetAverageLog(that[i])
GetLogAverageOf(DistributionStructArray<T, DomainType>)
The log-probability that two distributions would draw the same sample.
Declaration
public double GetLogAverageOf(DistributionStructArray<T, DomainType> that)
Parameters
Type | Name | Description |
---|---|---|
DistributionStructArray<T, DomainType> | that |
Returns
Type | Description |
---|---|
Double |
|
Remarks
This can be considered a type of inner product between distributions.
Another name might be "LogAverage" to go with "GetAverageLog".
For a DistributionArray, this specializes to:
sum_i Math.Log(sum_x this[i].Evaluate(x)*that[i].Evaluate(x))
= sum_i this[i].GetLogAverageOf(that[i])
GetLogAverageOfPower(DistributionStructArray<T, DomainType>, Double)
Get the integral of this distribution times another distribution raised to a power.
Declaration
public double GetLogAverageOfPower(DistributionStructArray<T, DomainType> that, double power)
Parameters
Type | Name | Description |
---|---|---|
DistributionStructArray<T, DomainType> | that | |
Double | power |
Returns
Type | Description |
---|---|
Double |
MaxDiff(Object)
The maximum difference in parameters between this distribution array and that distribution array
Declaration
public override double MaxDiff(object that)
Parameters
Type | Name | Description |
---|---|---|
Object | that | That distribution array |
Returns
Type | Description |
---|---|
Double | The maximum difference |
Overrides
Sample(DomainType[])
Get a sample from the distribution
Declaration
public override DomainType[] Sample(DomainType[] result)
Parameters
Type | Name | Description |
---|---|---|
DomainType[] | result | Where to put the result |
Returns
Type | Description |
---|---|
DomainType[] | A sample |
Overrides
SetTo(DistributionStructArray<T, DomainType>)
Set the parameters of this distribution to match those of the given distribution (by value)
Declaration
public void SetTo(DistributionStructArray<T, DomainType> that)
Parameters
Type | Name | Description |
---|---|---|
DistributionStructArray<T, DomainType> | that |
SetToPower(DistributionStructArray<T, DomainType>, Double)
Set the parameters to represent the power of a source distribution to some exponent
Declaration
public void SetToPower(DistributionStructArray<T, DomainType> a, double exponent)
Parameters
Type | Name | Description |
---|---|---|
DistributionStructArray<T, DomainType> | a | The source distribution array |
Double | exponent | The exponent |
SetToProduct(DistributionStructArray<T, DomainType>, DistributionStructArray<T, DomainType>)
Set the parameters to represent the product of two distributions
Declaration
public void SetToProduct(DistributionStructArray<T, DomainType> a, DistributionStructArray<T, DomainType> b)
Parameters
Type | Name | Description |
---|---|---|
DistributionStructArray<T, DomainType> | a | The first distribution array |
DistributionStructArray<T, DomainType> | b | The second distribution array |
SetToRatio(DistributionStructArray<T, DomainType>, DistributionStructArray<T, DomainType>, Boolean)
Set the parameters to represent the ratio of two distributions
Declaration
public void SetToRatio(DistributionStructArray<T, DomainType> numerator, DistributionStructArray<T, DomainType> denominator, bool forceProper)
Parameters
Type | Name | Description |
---|---|---|
DistributionStructArray<T, DomainType> | numerator | The numerator distribution array |
DistributionStructArray<T, DomainType> | denominator | The denominator distribution array |
Boolean | forceProper |
SetToSum(Double, DistributionStructArray<T, DomainType>, Double, DistributionStructArray<T, DomainType>)
Set the parameters to match the moments of a mixture of two distributions
Declaration
public void SetToSum(double weight1, DistributionStructArray<T, DomainType> a, double weight2, DistributionStructArray<T, DomainType> b)
Parameters
Type | Name | Description |
---|---|---|
Double | weight1 | The first weight |
DistributionStructArray<T, DomainType> | a | The first distribution array |
Double | weight2 | The second weight |
DistributionStructArray<T, DomainType> | b | The second distribution array |