Class SparseDistributionList<TDist, TDomain, TThis>
Abstract base class for a homogeneous sparse list of distributions. The class supports an approximation tolerance which allows elements close to the common value to be automatically reset to the common value. The list implements the interfaces which allow these distributions to participate in message passing.
Inheritance
Implements
Inherited Members
Namespace: Microsoft.ML.Probabilistic.Distributions
Assembly: Microsoft.ML.Probabilistic.dll
Syntax
[Serializable]
[DataContract]
public abstract class SparseDistributionList<TDist, TDomain, TThis> : ApproximateSparseList<TDist>, ISparseList<TDist>, ISparseEnumerable<TDist>, IList<TDist>, ICollection<TDist>, IEnumerable<TDist>, IList, ICollection, IEnumerable, IDistribution<ISparseList<TDomain>>, IDistribution, ICloneable, Diffable, SettableToUniform, HasPoint<ISparseList<TDomain>>, CanGetLogProb<ISparseList<TDomain>>, Sampleable<ISparseList<TDomain>>, SettableTo<TThis>, SettableToProduct<TThis>, SettableToProduct<TThis, TThis>, SettableToPower<TThis>, SettableToRatio<TThis>, SettableToRatio<TThis, TThis>, SettableToWeightedSum<TThis>, CanGetLogAverageOf<TThis>, CanGetLogAverageOfPower<TThis>, CanGetAverageLog<TThis>, CanGetMean<ISparseList<double>>, CanGetVariance<ISparseList<double>> where TDist : struct, SettableToUniform, Diffable, Sampleable<TDomain>, SettableToProduct<TDist>, SettableToRatio<TDist>, SettableToPower<TDist>, SettableToWeightedSum<TDist>, CanGetLogAverageOf<TDist>, CanGetAverageLog<TDist>, CanGetLogAverageOfPower<TDist>, CanGetMean<double>, CanGetVariance<double>, IDistribution<TDomain> where TThis : SparseDistributionList<TDist, TDomain, TThis>, new()
Type Parameters
| Name | Description |
|---|---|
| TDist | The distribution type for the elements of the sparse list. |
| TDomain | The domain type for the distribution elements. |
| TThis | The type of a specialized class derived from this class. |
Properties
Dimension
Gets the dimension of the sparse distribution list.
Declaration
public int Dimension { get; }
Property Value
| Type | Description |
|---|---|
| Int32 |
IsPointMass
Gets a value indicating whether the instance is a point mass.
Declaration
[IgnoreDataMember]
public bool IsPointMass { get; }
Property Value
| Type | Description |
|---|---|
| Boolean | True if all elements of the list are point masses, false otherwise. |
Point
Gets or sets the instance as a point mass.
Declaration
[IgnoreDataMember]
public ISparseList<TDomain> Point { get; set; }
Property Value
| Type | Description |
|---|---|
| ISparseList<TDomain> |
Methods
Clone()
Clones this SparseDistributionList<TDist, TDomain, TThis>.
Declaration
public object Clone()
Returns
| Type | Description |
|---|---|
| Object | The clone returned as an Object. |
Constant(Int32, TDist)
Returns a new instance of the SparseDistributionList<TDist, TDomain, TThis> class with the specified number of elements all of which are set to the specified value.
Declaration
public static TThis Constant(int size, TDist commonValue)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | size | The size of the list. |
| TDist | commonValue | The common value. |
Returns
| Type | Description |
|---|---|
| TThis | The instance. |
Constant(Int32, TDist, Double)
Returns a new instance of the SparseDistributionList<TDist, TDomain, TThis> class with the specified number of elements all of which are set to the specified value.
Declaration
public static TThis Constant(int size, TDist commonValue, double tolerance)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | size | The size of the list. |
| TDist | commonValue | The common value. |
| Double | tolerance | The tolerance for the approximation. |
Returns
| Type | Description |
|---|---|
| TThis | The new instance. |
FromSize(Int32)
Returns a new instance of the SparseDistributionList<TDist, TDomain, TThis> class with the specified number of elements all of which are set to uniform.
Declaration
public static TThis FromSize(int size)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | size | The size of the list. |
Returns
| Type | Description |
|---|---|
| TThis | The new instance. |
FromSize(Int32, Double)
Returns a new instance of the SparseDistributionList<TDist, TDomain, TThis> class with the specified number of elements all of which are set to uniform.
Declaration
public static TThis FromSize(int size, double tolerance)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | size | The size of the list. |
| Double | tolerance | The tolerance for the approximation. |
Returns
| Type | Description |
|---|---|
| TThis | The new instance. |
FromSparseList(ISparseList<TDist>)
Returns a new instance of the SparseDistributionList<TDist, TDomain, TThis> class from a sparse list of distributions.
Declaration
public static TThis FromSparseList(ISparseList<TDist> distributions)
Parameters
| Type | Name | Description |
|---|---|---|
| ISparseList<TDist> | distributions | The sparse list of distributions. |
Returns
| Type | Description |
|---|---|
| TThis | The new instance. |
FromSparseList(ISparseList<TDist>, Double)
Returns a new instance of the SparseDistributionList<TDist, TDomain, TThis> class from a sparse list of distributions.
Declaration
public static TThis FromSparseList(ISparseList<TDist> distributions, double tolerance)
Parameters
| Type | Name | Description |
|---|---|---|
| ISparseList<TDist> | distributions | The sparse list of distributions. |
| Double | tolerance | The tolerance. |
Returns
| Type | Description |
|---|---|
| TThis | The new instance. |
FromSparseValues(Int32, TDist, List<ValueAtIndex<TDist>>)
Returns a new instance of the SparseDistributionList<TDist, TDomain, TThis> class of a given length and assigns all elements the given value, except for the specified list of sparse values. This list is stored internally as is so MUST be sorted by index and must not be modified externally after being passed in.
Declaration
public static TThis FromSparseValues(int size, TDist commonValue, List<ValueAtIndex<TDist>> sortedSparseValues)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | size | The size of the list. |
| TDist | commonValue | The common value. |
| List<ValueAtIndex<TDist>> | sortedSparseValues | The sorted list of non-common values. |
Returns
| Type | Description |
|---|---|
| TThis | The new instance. |
FromSparseValues(Int32, TDist, List<ValueAtIndex<TDist>>, Double)
Returns a new instance of the SparseDistributionList<TDist, TDomain, TThis> class of a given length and assigns all elements the given value, except for the specified list of sparse values. This list is stored internally as is, so MUST be sorted by index and must not be modified externally after being passed in.
Declaration
[Construction(new string[]{"Count", "CommonValue", "SparseValues", "Tolerance"})]
public static TThis FromSparseValues(int size, TDist commonValue, List<ValueAtIndex<TDist>> sortedSparseValues, double tolerance)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | size | The size of the list. |
| TDist | commonValue | The common value. |
| List<ValueAtIndex<TDist>> | sortedSparseValues | The sorted list of non-common values. |
| Double | tolerance | The tolerance for the approximation. |
Returns
| Type | Description |
|---|---|
| TThis | The new instance. |
GetAverageLog(TThis)
Returns the expected logarithm of that sparse distribution list under this sparse distribution list.
Declaration
public double GetAverageLog(TThis that)
Parameters
| Type | Name | Description |
|---|---|---|
| TThis | that | The other distribution. |
Returns
| Type | Description |
|---|---|
| Double | The expected logarithm of the other distribution. |
GetLogAverageOf(TThis)
Returns the log probability that this distribution and another draw the same sample.
Declaration
public double GetLogAverageOf(TThis that)
Parameters
| Type | Name | Description |
|---|---|---|
| TThis | that | The other distribution. |
Returns
| Type | Description |
|---|---|
| Double | The log probability that this distribution and another draw the same sample. |
GetLogAverageOfPower(TThis, Double)
Returns the log of the integral of the product of this sparse distribution list and another sparse distribution list raised to a power.
Declaration
public double GetLogAverageOfPower(TThis that, double exponent)
Parameters
| Type | Name | Description |
|---|---|---|
| TThis | that | The other distribution. |
| Double | exponent | The exponent. |
Returns
| Type | Description |
|---|---|
| Double | The log average of the power of the second distribution. |
GetLogProb(ISparseList<TDomain>)
Evaluates the log of the density function.
Declaration
public double GetLogProb(ISparseList<TDomain> value)
Parameters
| Type | Name | Description |
|---|---|---|
| ISparseList<TDomain> | value | The point at which to evaluate the density. |
Returns
| Type | Description |
|---|---|
| Double | The log probability of the given value>. |
GetMean()
Gets the mean as a sparse list.
Declaration
public ISparseList<double> GetMean()
Returns
| Type | Description |
|---|---|
| ISparseList<Double> | The mean of this distribution. |
GetVariance()
Gets the variance as a sparse list.
Declaration
public ISparseList<double> GetVariance()
Returns
| Type | Description |
|---|---|
| ISparseList<Double> | The variance of this distribution. |
IsUniform()
Asks whether this sparse distribution list is uniform.
Declaration
public bool IsUniform()
Returns
| Type | Description |
|---|---|
| Boolean | True if all elements of the list are uniform, false otherwise. |
MaxDiff(Object)
Returns the maximum difference between the parameters of this sparse distribution list and another.
Declaration
public double MaxDiff(object thatd)
Parameters
| Type | Name | Description |
|---|---|---|
| Object | thatd | The other sparse distribution list. |
Returns
| Type | Description |
|---|---|
| Double | The maximum difference. |
Remarks
a.MaxDiff(b) == b.MaxDiff(a).
Sample()
Samples from this sparse distribution list.
Declaration
public ISparseList<TDomain> Sample()
Returns
| Type | Description |
|---|---|
| ISparseList<TDomain> | A sample from this distribution. |
Remarks
This method is inefficient in that the result will be dense even though the return type is sparse.
Sample(ISparseList<TDomain>)
Samples from this sparse distribution list.
Declaration
public ISparseList<TDomain> Sample(ISparseList<TDomain> result)
Parameters
| Type | Name | Description |
|---|---|---|
| ISparseList<TDomain> | result | Where to put the result. |
Returns
| Type | Description |
|---|---|
| ISparseList<TDomain> | A sample from this distribution. |
Remarks
This method is inefficient in that the result will be dense even though the return type is sparse.
SetTo(TThis)
Sets this sparse distribution list to another sparse distribution list.
Declaration
public void SetTo(TThis value)
Parameters
| Type | Name | Description |
|---|---|---|
| TThis | value | The other sparse distribution list. |
SetToPower(TThis, Double)
Sets this sparse distribution list to the power of another sparse distribution list.
Declaration
public void SetToPower(TThis value, double exponent)
Parameters
| Type | Name | Description |
|---|---|---|
| TThis | value | The value. |
| Double | exponent | The exponent. |
SetToProduct(TThis, TThis)
Sets this sparse distribution list to the product of two other sparse distribution lists.
Declaration
public void SetToProduct(TThis a, TThis b)
Parameters
| Type | Name | Description |
|---|---|---|
| TThis | a | Left hand side. |
| TThis | b | Right hand side. |
SetToRatio(TThis, TThis, Boolean)
Sets this sparse distribution list to the ratio of two other sparse Gaussian lists.
Declaration
public void SetToRatio(TThis numerator, TThis denominator, bool forceProper = false)
Parameters
| Type | Name | Description |
|---|---|---|
| TThis | numerator | The numerator. |
| TThis | denominator | The denominator. |
| Boolean | forceProper | Whether to force the result to be proper. |
SetToSum(Double, TThis, Double, TThis)
Creates a sparse distribution list to the weighted sums of the elements of two other sparse distribution lists.
Declaration
public void SetToSum(double weight1, TThis value1, double weight2, TThis value2)
Parameters
| Type | Name | Description |
|---|---|---|
| Double | weight1 | The first weight. |
| TThis | value1 | The first sparse distribution list. |
| Double | weight2 | The second weight. |
| TThis | value2 | The second sparse distribution list. |
SetToUniform()
Sets this sparse distribution list to be a uniform distribution.
Declaration
public void SetToUniform()