Class UnnormalizedDiscrete
Represents a discrete distribution in the log domain without explicit normalization.
Implements
Inherited Members
Namespace: Microsoft.ML.Probabilistic.Distributions
Assembly: Microsoft.ML.Probabilistic.dll
Syntax
[Serializable]
[Quality(QualityBand.Experimental)]
[DataContract]
public class UnnormalizedDiscrete : IDistribution<int>, IDistribution, ICloneable, Diffable, SettableToUniform, HasPoint<int>, CanGetLogProb<int>, SettableTo<UnnormalizedDiscrete>, Sampleable<int>, SettableToProduct<UnnormalizedDiscrete>, SettableToProduct<UnnormalizedDiscrete, UnnormalizedDiscrete>, SettableToRatio<UnnormalizedDiscrete>, SettableToRatio<UnnormalizedDiscrete, UnnormalizedDiscrete>, SettableToPower<UnnormalizedDiscrete>, SettableToWeightedSum<UnnormalizedDiscrete>, CanGetLogAverageOf<UnnormalizedDiscrete>, CanGetAverageLog<UnnormalizedDiscrete>
Fields
logProb
Log probability of each value (when not a point mass). Since the distribution is unnormalized, these may be shifted by an arbitrary constant.
Declaration
[DataMember]
protected DenseVector logProb
Field Value
Type | Description |
---|---|
DenseVector |
Remarks
logprob.Length == D.
Properties
Dimension
Dimension of the unnormalised discrete distribution
Declaration
[IgnoreDataMember]
public int Dimension { get; }
Property Value
Type | Description |
---|---|
Int32 |
IsPointMass
Whether or not this instance is a point mass.
Declaration
[IgnoreDataMember]
public bool IsPointMass { get; }
Property Value
Type | Description |
---|---|
Boolean |
Point
Sets/gets this distribution as a point distribution
Declaration
[IgnoreDataMember]
public int Point { get; set; }
Property Value
Type | Description |
---|---|
Int32 |
Methods
Clone()
Clones this unnormalised discrete distribution.
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 UnnormalizedDiscrete type |
Evaluate(Int32)
Evaluates the unnormalized probability at the specified domain value
Declaration
public double Evaluate(int value)
Parameters
Type | Name | Description |
---|---|---|
Int32 | value | The point at which to evaluate |
Returns
Type | Description |
---|---|
Double | The unnormalized probability |
FromDiscrete(Discrete)
Creates an unnormalized discrete distribution from a normal discrete distribution.
Declaration
public static UnnormalizedDiscrete FromDiscrete(Discrete d)
Parameters
Type | Name | Description |
---|---|---|
Discrete | d | The discrete distribution |
Returns
Type | Description |
---|---|
UnnormalizedDiscrete |
FromLogProbs(DenseVector)
Creates an unnormalized discrete distribution from a vector of log probabilities.
Declaration
public static UnnormalizedDiscrete FromLogProbs(DenseVector logProb)
Parameters
Type | Name | Description |
---|---|---|
DenseVector | logProb |
Returns
Type | Description |
---|---|
UnnormalizedDiscrete |
GetAverageLog(UnnormalizedDiscrete)
Declaration
public double GetAverageLog(UnnormalizedDiscrete that)
Parameters
Type | Name | Description |
---|---|---|
UnnormalizedDiscrete | that |
Returns
Type | Description |
---|---|
Double |
GetLogAverageOf(UnnormalizedDiscrete)
Declaration
public double GetLogAverageOf(UnnormalizedDiscrete that)
Parameters
Type | Name | Description |
---|---|---|
UnnormalizedDiscrete | that |
Returns
Type | Description |
---|---|
Double |
GetLogProb(Int32)
Evaluates the log of the unnormalized density at the specified domain value
Declaration
public double GetLogProb(int value)
Parameters
Type | Name | Description |
---|---|---|
Int32 | value | The point at which to evaluate |
Returns
Type | Description |
---|---|
Double | The log unnormalized density |
GetProbs()
Gets the unnormalized probability vector for this distribution.
Declaration
public DenseVector GetProbs()
Returns
Type | Description |
---|---|
DenseVector |
GetWorkspace()
Gets a Vector of size this.Dimension.
Declaration
public DenseVector GetWorkspace()
Returns
Type | Description |
---|---|
DenseVector | A pointer to the internal log prob Vector of the object. |
Remarks
This function is intended to be used with SetLogProbs, to avoid allocating a new Vector. The return value should not be interpreted as a probs vector, but only a workspace filled with unknown data that can be overwritten. Until SetLogProbs is called, the distribution object is invalid once this workspace is modified.
IsUniform()
Returns whether the distribution is uniform or not
Declaration
public bool IsUniform()
Returns
Type | Description |
---|---|
Boolean | True if uniform |
MaxDiff(Object)
The maximum difference between the parameters of this discrete and that discrete
Declaration
public double MaxDiff(object that)
Parameters
Type | Name | Description |
---|---|---|
Object | that | That discrete |
Returns
Type | Description |
---|---|
Double | The maximum difference |
Sample()
Declaration
public int Sample()
Returns
Type | Description |
---|---|
Int32 |
Sample(Int32)
Declaration
public int Sample(int result)
Parameters
Type | Name | Description |
---|---|---|
Int32 | result |
Returns
Type | Description |
---|---|
Int32 |
SetLogProbs(DenseVector)
Sets the log probability vector for this distribution.
Declaration
public void SetLogProbs(DenseVector logProbs)
Parameters
Type | Name | Description |
---|---|---|
DenseVector | logProbs | A vector of non-negative, finite numbers. Need not sum to 1. |
Remarks
Instead of allocating your own Vector to pass to SetProbs, you can call GetWorkspace(), fill in the resulting Vector, and then pass it to SetProbs.
SetMaxToZero()
Rescales the unnormalised distribution, so that the max log prob is zero i.e. the max unnormalised prob is 1.
Declaration
public void SetMaxToZero()
SetTo(UnnormalizedDiscrete)
Sets the parameters of this instance to the parameters of that instance
Declaration
public void SetTo(UnnormalizedDiscrete value)
Parameters
Type | Name | Description |
---|---|---|
UnnormalizedDiscrete | value | That instance |
SetToPower(UnnormalizedDiscrete, Double)
Declaration
public void SetToPower(UnnormalizedDiscrete dist, double exponent)
Parameters
Type | Name | Description |
---|---|---|
UnnormalizedDiscrete | dist | |
Double | exponent |
SetToProduct(UnnormalizedDiscrete, UnnormalizedDiscrete)
Sets the parameters to represent the product of two unnormalized discrete distributions.
Declaration
public void SetToProduct(UnnormalizedDiscrete a, UnnormalizedDiscrete b)
Parameters
Type | Name | Description |
---|---|---|
UnnormalizedDiscrete | a | The first unnormalized discrete distribution |
UnnormalizedDiscrete | b | The second unnormalized discrete distribution |
SetToRatio(UnnormalizedDiscrete, UnnormalizedDiscrete, Boolean)
Sets the parameters to represent the ratio of two unnormalized discrete distributions.
Declaration
public void SetToRatio(UnnormalizedDiscrete numerator, UnnormalizedDiscrete denominator, bool forceProper = false)
Parameters
Type | Name | Description |
---|---|---|
UnnormalizedDiscrete | numerator | The first unnormalized discrete distribution |
UnnormalizedDiscrete | denominator | The second unnormalized discrete distribution |
Boolean | forceProper | Ignored |
SetToSum(Double, UnnormalizedDiscrete, Double, UnnormalizedDiscrete)
Declaration
public void SetToSum(double weight1, UnnormalizedDiscrete value1, double weight2, UnnormalizedDiscrete value2)
Parameters
Type | Name | Description |
---|---|---|
Double | weight1 | |
UnnormalizedDiscrete | value1 | |
Double | weight2 | |
UnnormalizedDiscrete | value2 |
SetToUniform()
Sets this instance to a uniform distribution (i.e. probabilities all equal)
Declaration
public void SetToUniform()
ToDiscrete()
Declaration
public Discrete ToDiscrete()
Returns
Type | Description |
---|---|
Discrete |
ToString()
Override of ToString method
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String | String representation of this instance |
Overrides
ToString(String)
Override of ToString method which allows custom number formatting
Declaration
public string ToString(string format)
Parameters
Type | Name | Description |
---|---|---|
String | format |
Returns
Type | Description |
---|---|
String | String representation of this instance |
Uniform(Int32)
Creates a uniform unnormalized discrete distribution over the values from 0 to numValues-1
Declaration
public static UnnormalizedDiscrete Uniform(int numValues)
Parameters
Type | Name | Description |
---|---|---|
Int32 | numValues |
Returns
Type | Description |
---|---|
UnnormalizedDiscrete |
Operators
Division(UnnormalizedDiscrete, UnnormalizedDiscrete)
Creates an unnormalized discrete distribution which is the ratio of two unnormalized discrete distributions
Declaration
public static UnnormalizedDiscrete operator /(UnnormalizedDiscrete a, UnnormalizedDiscrete b)
Parameters
Type | Name | Description |
---|---|---|
UnnormalizedDiscrete | a | The first distribution |
UnnormalizedDiscrete | b | The second distribution |
Returns
Type | Description |
---|---|
UnnormalizedDiscrete | The resulting unnormalized discrete distribution |
ExclusiveOr(UnnormalizedDiscrete, Double)
Declaration
public static UnnormalizedDiscrete operator ^(UnnormalizedDiscrete dist, double exponent)
Parameters
Type | Name | Description |
---|---|---|
UnnormalizedDiscrete | dist | |
Double | exponent |
Returns
Type | Description |
---|---|
UnnormalizedDiscrete |
Multiply(UnnormalizedDiscrete, UnnormalizedDiscrete)
Creates an unnormalized discrete distribution which is the product of two unnormalized discrete distributions
Declaration
public static UnnormalizedDiscrete operator *(UnnormalizedDiscrete a, UnnormalizedDiscrete b)
Parameters
Type | Name | Description |
---|---|---|
UnnormalizedDiscrete | a | The first distribution |
UnnormalizedDiscrete | b | The second distribution |
Returns
Type | Description |
---|---|
UnnormalizedDiscrete | The resulting unnormalized discrete distribution |