Class SequenceDistribution<TSequence, TElement, TElementDistribution, TSequenceManipulator, TAutomaton, TWeightFunction, TWeightFunctionFactory, TThis>
A base class for implementations of distributions over sequences.
Inheritance
Implements
Inherited Members
Namespace: Microsoft.ML.Probabilistic.Distributions
Assembly: Microsoft.ML.Probabilistic.dll
Syntax
[Serializable]
[DataContract]
[Quality(QualityBand.Experimental)]
public abstract class SequenceDistribution<TSequence, TElement, TElementDistribution, TSequenceManipulator, TAutomaton, TWeightFunction, TWeightFunctionFactory, TThis> : IDistribution<TSequence>, IDistribution, ICloneable, Diffable, SettableToUniform, HasPoint<TSequence>, CanGetLogProb<TSequence>, SettableTo<TThis>, SettableToProduct<TThis>, SettableToProduct<TThis, TThis>, SettableToRatio<TThis>, SettableToRatio<TThis, TThis>, SettableToPower<TThis>, CanGetLogAverageOf<TThis>, CanGetLogAverageOfPower<TThis>, CanGetAverageLog<TThis>, SettableToWeightedSumExact<TThis>, SettableToWeightedSum<TThis>, SettableToPartialUniform<TThis>, CanGetLogNormalizer, Sampleable<TSequence> where TSequence : class, IEnumerable<TElement> where TElementDistribution : IImmutableDistribution<TElement, TElementDistribution>, CanGetLogAverageOf<TElementDistribution>, CanComputeProduct<TElementDistribution>, CanCreatePartialUniform<TElementDistribution>, SummableExactly<TElementDistribution>, Sampleable<TElement>, new()
where TSequenceManipulator : ISequenceManipulator<TSequence, TElement>, new()
where TAutomaton : Automaton<TSequence, TElement, TElementDistribution, TSequenceManipulator, TAutomaton>, new()
where TWeightFunction : WeightFunctions<TSequence, TElement, TElementDistribution, TSequenceManipulator, TAutomaton>.IWeightFunction<TWeightFunction>, new()
where TWeightFunctionFactory : WeightFunctions<TSequence, TElement, TElementDistribution, TSequenceManipulator, TAutomaton>.IWeightFunctionFactory<TWeightFunction>, new()
where TThis : SequenceDistribution<TSequence, TElement, TElementDistribution, TSequenceManipulator, TAutomaton, TWeightFunction, TWeightFunctionFactory, TThis>, new()
Type Parameters
| Name | Description |
|---|---|
| TSequence | The type of a sequence. |
| TElement | The type of a sequence element. |
| TElementDistribution | The type of a distribution over sequence elements. |
| TSequenceManipulator | The type providing ways to manipulate sequences. |
| TAutomaton | The type of a weighted finite state automaton that can be used to represent every valid function mapping sequences to weights. |
| TWeightFunction | The type of an underlying function mapping sequences to weights. |
| TWeightFunctionFactory | The type of the factory for |
| TThis | The type of a concrete distribution class. |
Constructors
SequenceDistribution()
Initializes a new instance of the SequenceDistribution<TSequence, TElement, TElementDistribution, TSequenceManipulator, TAutomaton, TWeightFunction, TWeightFunctionFactory, TThis> class with a null weight function. The weight function must be set by the subclass constructor or factory method.
Declaration
protected SequenceDistribution()
Properties
IsEmpty
Gets a value indicating whether the current distribution puts all probability mass on the empty sequence.
Declaration
public bool IsEmpty { get; }
Property Value
| Type | Description |
|---|---|
| Boolean |
IsPointMass
Gets a value indicating whether the current distribution represents a point mass.
Declaration
public bool IsPointMass { get; }
Property Value
| Type | Description |
|---|---|
| Boolean |
Point
Gets or sets the point mass represented by the distribution.
Declaration
public TSequence Point { get; set; }
Property Value
| Type | Description |
|---|---|
| TSequence |
UsesAutomatonRepresentation
Gets a value indicating whether the current distribution is represented as an automaton internally.
Declaration
public bool UsesAutomatonRepresentation { get; }
Property Value
| Type | Description |
|---|---|
| Boolean |
Methods
Any(Int32, Nullable<Int32>)
Creates a uniform distribution over sequences of length within the given bounds.
If maxLength is set to null,
there will be no upper bound on the length, and the resulting distribution will thus be improper.
Declaration
public static TThis Any(int minLength = 0, int? maxLength = null)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | minLength | The minimum possible sequence length. |
| Nullable<Int32> | maxLength | The maximum possible sequence length, or null for no upper bound on length. Defaults to null. |
Returns
| Type | Description |
|---|---|
| TThis | The created distribution. |
Append(TSequence, Int32)
Creates a distribution over concatenations of sequences from the current distribution and a given sequence.
Declaration
public TThis Append(TSequence sequence, int group = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| TSequence | sequence | The sequence to append. |
| Int32 | group | The group for the appended sequence. |
Returns
| Type | Description |
|---|---|
| TThis | The distribution over the concatenations of sequences. |
Remarks
The result is equivalent to the distribution produced by the following sampling procedure:
- Sample a random sequence from the current distribution.
-
Append
sequenceto it and output the result.
Append(TElement, Int32)
Creates a distribution over concatenations of sequences from the current distribution and a given element.
Declaration
public TThis Append(TElement element, int group = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| TElement | element | The element to append. |
| Int32 | group | The group for the appended element. |
Returns
| Type | Description |
|---|---|
| TThis | The distribution over the concatenations of sequences and the element. |
Remarks
The result is equivalent to the distribution produced by the following sampling procedure:
- Sample a random sequence from the current distribution.
- Append the given element to the sampled sequence and output the result.
Append(TElementDistribution, Int32)
Creates a distribution over concatenations of sequences from the current distribution and elements from a given distribution.
Declaration
public TThis Append(TElementDistribution elementDistribution, int group = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| TElementDistribution | elementDistribution | The distribution to generate the elements from. |
| Int32 | group | The group for the appended element. |
Returns
| Type | Description |
|---|---|
| TThis | The distribution over the concatenations of sequences and elements. |
Remarks
The result is equivalent to the distribution produced by the following sampling procedure:
- Sample a random sequence from the current distribution.
-
2) Sample a random element from
elementDistribution. - 3) Append the sampled element to the sampled sequence and output the result.
Append(TThis, Int32)
Creates a distribution over concatenations of sequences from the current distribution and sequences from a given distribution.
Declaration
public TThis Append(TThis dist, int group = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| TThis | dist | The distribution over the sequences to append. |
| Int32 | group | The group for the appended sequence. |
Returns
| Type | Description |
|---|---|
| TThis | The distribution over the concatenations of sequences. |
Remarks
The result is equivalent to the distribution produced by the following sampling procedure:
- Sample a random sequence from the current distribution.
-
Sample a random sequence from
dist. - Output the concatenation of the sampled pair of sequences.
AppendInPlace(TSequence, Int32)
Replaces the current distribution by a distribution over concatenations of sequences from the current distribution and a given sequence.
Declaration
public void AppendInPlace(TSequence sequence, int group = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| TSequence | sequence | The sequence to append. |
| Int32 | group | The group for the appended sequence. |
Remarks
The result is equivalent to the distribution produced by the following sampling procedure:
- Sample a random sequence from the current distribution.
-
Append
sequenceto it and output the result.
AppendInPlace(TElement, Int32)
Replaces the current distribution by a distribution over concatenations of sequences from the current distribution and a given element.
Declaration
public void AppendInPlace(TElement element, int group = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| TElement | element | The element to append. |
| Int32 | group | The group for the appended element. |
Remarks
The result is equivalent to the distribution produced by the following sampling procedure:
- Sample a random sequence from the current distribution.
- Append the given element to the sampled sequence and output the result.
AppendInPlace(TElementDistribution, Int32)
Replaces the current distribution by a distribution over concatenations of sequences from the current distribution and elements from a given distribution.
Declaration
public void AppendInPlace(TElementDistribution elementDistribution, int group = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| TElementDistribution | elementDistribution | The distribution to generate the elements from. |
| Int32 | group | The group for the appended element. |
Remarks
The result is equivalent to the distribution produced by the following sampling procedure:
- Sample a random sequence from the current distribution.
-
Sample a random element from
elementDistribution. - Append the sampled element to the sampled sequence and output the result.
AppendInPlace(TThis, Int32)
Replaces the current distribution by a distribution over concatenations of sequences from the current distribution and sequences from a given distribution.
Declaration
public void AppendInPlace(TThis dist, int group = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| TThis | dist | The distribution over the sequences to append. |
| Int32 | group | The group for the appended sequence. |
Remarks
The result is equivalent to the distribution produced by the following sampling procedure:
- Sample a random sequence from the current distribution.
-
Sample a random sequence from
dist. - Output the concatenation of the sampled pair of sequences.
ApplyTransducer<TTransducer>(TTransducer)
Computes a distribution g(b) = sum_a f(a) T(a, b), where f(a) is the current distribution and T(a, b) is a given transducer.
Declaration
public TThis ApplyTransducer<TTransducer>(TTransducer transducer)
where TTransducer : Transducer<TSequence, TElement, TElementDistribution, TSequenceManipulator, TAutomaton, TTransducer>, new()
Parameters
| Type | Name | Description |
|---|---|---|
| TTransducer | transducer | The transducer to project on. |
Returns
| Type | Description |
|---|---|
| TThis | The projection. |
Type Parameters
| Name | Description |
|---|---|
| TTransducer |
Clone()
Creates a copy of the current distribution.
Declaration
public TThis Clone()
Returns
| Type | Description |
|---|---|
| TThis | The created copy. |
Concatenate(IEnumerable<TElementDistribution>, Boolean, Boolean)
Creates a distribution over sequences induced by a given list of distributions over sequence elements where the sequence can optionally end at any length, and the last element can optionally repeat without limit.
Declaration
public static TThis Concatenate(IEnumerable<TElementDistribution> elementDistributions, bool allowEarlyEnd = false, bool repeatLastElement = false)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<TElementDistribution> | elementDistributions | Enumerable of distributions over sequence elements and the transition weights. |
| Boolean | allowEarlyEnd | Allow the sequence to end at any point. |
| Boolean | repeatLastElement | Repeat the last element. |
Returns
| Type | Description |
|---|---|
| TThis | The created distribution. |
Contains(TSequence)
Returns true if the given sequence is in the support of this distribution (i.e. has non-zero probability).
Declaration
public bool Contains(TSequence sequence)
Parameters
| Type | Name | Description |
|---|---|---|
| TSequence | sequence | The sequence to check. |
Returns
| Type | Description |
|---|---|
| Boolean | True if the sequence has non-zero probability under this distribiton, false otherwise. |
Converge(TThis, Double)
Converges an improper sequence distribution
Declaration
public static TThis Converge(TThis dist, double decayWeight = 0.99)
Parameters
| Type | Name | Description |
|---|---|---|
| TThis | dist | The original distribution. |
| Double | decayWeight | The decay weight. |
Returns
| Type | Description |
|---|---|
| TThis | The converged distribution. |
Empty()
Creates a distribution which puts all probability mass on the empty sequence.
Declaration
[Construction(UseWhen = "IsEmpty")]
public static TThis Empty()
Returns
| Type | Description |
|---|---|
| TThis | The created distribution. |
EnumerateComponents()
Enumerates components of this distribution.
Declaration
public IEnumerable<Tuple<List<TElementDistribution>, double>> EnumerateComponents()
Returns
| Type | Description |
|---|---|
| IEnumerable<Tuple<List<TElementDistribution>, Double>> | For each component, the list of element distributions and the log mixture weight for that component. |
Remarks
Any sequence distribution can be represented as a mixture of 'simple' sequence distributions where each element is independent. This method enumerates through the components of this distribution treated as such a mixture. Each component is returned as a list of the independent element distributions for each element.
For some distributions, the number of components may be very large.
EnumerateSupport(Int32, Boolean)
Enumerates support of this distribution when possible. Only point mass elements are supported.
Declaration
public IEnumerable<TSequence> EnumerateSupport(int maxCount = 1000000, bool tryDeterminize = true)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | maxCount | The maximum support enumeration count. |
| Boolean | tryDeterminize | Try to determinize if this distribution uses a string automaton representation. |
Returns
| Type | Description |
|---|---|
| IEnumerable<TSequence> | The strings supporting this distribution |
Exceptions
| Type | Condition |
|---|---|
| AutomatonException | Thrown if enumeration is too large. |
Equals(Object)
Checks if obj equals to this distribution (i.e. represents the same distribution over sequences).
Declaration
public override bool Equals(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| Object | obj | The object to compare this distribution with. |
Returns
| Type | Description |
|---|---|
| Boolean | true if this distribution is equal to |
Overrides
FromWeightFunction(TAutomaton)
Creates a distribution from a given weight (non-normalized probability) function.
Declaration
[Construction(new string[]{"ToAutomaton"}, UseWhen = "UsesAutomatonRepresentation")]
public static TThis FromWeightFunction(TAutomaton weightFunction)
Parameters
| Type | Name | Description |
|---|---|---|
| TAutomaton | weightFunction |
Returns
| Type | Description |
|---|---|
| TThis | The created distribution. |
FromWeightFunction(TWeightFunction)
Creates a distribution from a given weight (non-normalized probability) function.
Declaration
[Construction(new string[]{"GetWeightFunction"})]
public static TThis FromWeightFunction(TWeightFunction weightFunction)
Parameters
| Type | Name | Description |
|---|---|---|
| TWeightFunction | weightFunction | The weight function specifying the distribution. |
Returns
| Type | Description |
|---|---|
| TThis | The created distribution. |
GetAverageLog(TThis)
Computes the expected logarithm of a given distribution under this distribution. Not currently supported.
Declaration
public double GetAverageLog(TThis that)
Parameters
| Type | Name | Description |
|---|---|---|
| TThis | that | The distribution to take the logarithm of. |
Returns
| Type | Description |
|---|---|
| Double |
|
Remarks
This is also known as the cross entropy.
GetGroups()
Declaration
public Dictionary<int, TThis> GetGroups()
Returns
| Type | Description |
|---|---|
| Dictionary<Int32, TThis> |
GetHashCode()
Gets the hash code of this distribution.
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| Int32 | The hash code. |
Overrides
GetLogAverageOf(TThis)
Returns the logarithm of the probability that the current distribution would draw the same sample as a given one.
Declaration
public double GetLogAverageOf(TThis that)
Parameters
| Type | Name | Description |
|---|---|---|
| TThis | that | The given distribution. |
Returns
| Type | Description |
|---|---|
| Double | The logarithm of the probability that distributions would draw the same sample. |
GetLogAverageOfPower(TThis, Double)
Computes the log-integral of one distribution times another raised to a power.
Declaration
public double GetLogAverageOfPower(TThis that, double power)
Parameters
| Type | Name | Description |
|---|---|---|
| TThis | that | The other distribution |
| Double | power | The exponent |
Returns
| Type | Description |
|---|---|
| Double |
|
Remarks
This is not the same as GetLogAverageOf(that^power) because it includes the normalization constant of that.
Powers other than 1 are not currently supported.
GetLogNormalizer()
Returns the logarithm of the normalizer of the exponential family representation of this distribution. Normalizer of an improper distribution is defined to be 1.
Declaration
public double GetLogNormalizer()
Returns
| Type | Description |
|---|---|
| Double | The logarithm of the normalizer. |
Remarks
Getting the normalizer is currently supported for improper distributions only.
GetLogProb(TSequence)
Gets the logarithm of the probability of a given sequence under this distribution. If the distribution is improper, returns the logarithm of the value of the underlying unnormalized weight function.
Declaration
public double GetLogProb(TSequence sequence)
Parameters
| Type | Name | Description |
|---|---|---|
| TSequence | sequence | The sequence to get the probability for. |
Returns
| Type | Description |
|---|---|
| Double | The logarithm of the probability of the sequence. |
GetNormalizedWeightFunction()
Returns the underlying weight function.
Declaration
public TWeightFunction GetNormalizedWeightFunction()
Returns
| Type | Description |
|---|---|
| TWeightFunction | The underlying weight function. |
Remarks
The returned weight function is guaranteed to be normalized. If you don't care about an arbitrary scale factor, consider using GetWeightFunction() which has less overhead.
GetProb(TSequence)
Gets the probability of a given sequence under this distribution. If the distribution is improper, returns the value of the underlying unnormalized weight function.
Declaration
public double GetProb(TSequence sequence)
Parameters
| Type | Name | Description |
|---|---|---|
| TSequence | sequence | The sequence to get the probability for. |
Returns
| Type | Description |
|---|---|
| Double | The probability of the sequence. |
GetWeightFunction()
Returns the underlying weight function.
Declaration
public TWeightFunction GetWeightFunction()
Returns
| Type | Description |
|---|---|
| TWeightFunction | The underlying weight function. |
Remarks
The returned weight function might differ from the probability function by an arbitrary scale factor. To ensure that the weight function is normalized, use GetNormalizedWeightFunction().
HasGroup(Int32)
Declaration
public bool HasGroup(int group)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | group |
Returns
| Type | Description |
|---|---|
| Boolean |
IsPartialUniform()
Checks whether the distribution is uniform over its support.
Declaration
public bool IsPartialUniform()
Returns
| Type | Description |
|---|---|
| Boolean | true if the distribution is uniform over its support, false otherwise. |
IsProper()
Checks whether the current distribution is proper.
Declaration
public bool IsProper()
Returns
| Type | Description |
|---|---|
| Boolean | true if the current distribution is proper, false otherwise. |
IsUniform()
Checks whether the current distribution is uniform over all possible sequences.
Declaration
public bool IsUniform()
Returns
| Type | Description |
|---|---|
| Boolean | true if the current distribution is uniform over all possible sequences, false otherwise. |
IsZero()
Gets a value indicating whether the current distribution is an improper distribution which assigns zero probability to every sequence.
Declaration
public bool IsZero()
Returns
| Type | Description |
|---|---|
| Boolean | true if the current distribution is an improper distribution that assigns zero probability to every sequence, false otherwise. |
MaxDiff(Object)
Gets a value indicating how close this distribution is to a given one in terms of probabilities they assign to sequences.
Declaration
public double MaxDiff(object that)
Parameters
| Type | Name | Description |
|---|---|---|
| Object | that | The other distribution. |
Returns
| Type | Description |
|---|---|
| Double | A non-negative value, which is close to zero if the two distribution assign similar values to all sequences. |
OneOf(TSequence[])
Creates a distribution which is uniform over a given set of sequences.
Declaration
public static TThis OneOf(params TSequence[] sequences)
Parameters
| Type | Name | Description |
|---|---|---|
| TSequence[] | sequences | The set of sequences to create a distribution from. |
Returns
| Type | Description |
|---|---|
| TThis | The created distribution. |
OneOf(TThis[])
Creates a distribution which is a uniform mixture of a given set of distributions.
Declaration
public static TThis OneOf(params TThis[] distributions)
Parameters
| Type | Name | Description |
|---|---|---|
| TThis[] | distributions | The set of distributions to create a mixture from. |
Returns
| Type | Description |
|---|---|
| TThis | The created mixture distribution. |
OneOf(IEnumerable<TSequence>)
Creates a distribution which is uniform over a given set of sequences.
Declaration
public static TThis OneOf(IEnumerable<TSequence> sequences)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<TSequence> | sequences | The set of sequences to create a distribution from. |
Returns
| Type | Description |
|---|---|
| TThis | The created distribution. |
OneOf(IEnumerable<TThis>, Boolean, Boolean)
Creates a distribution which is a uniform mixture of a given set of distributions.
Declaration
public static TThis OneOf(IEnumerable<TThis> distributions, bool cloneIfSizeOne = false, bool skipNormalization = false)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<TThis> | distributions | The set of distributions to create a mixture from. |
| Boolean | cloneIfSizeOne | If the set has one element, whether to return that element or to clone it. |
| Boolean | skipNormalization | Allow normalization to be skipped as it can be expensive |
Returns
| Type | Description |
|---|---|
| TThis | The created mixture distribution. |
OneOf(IEnumerable<KeyValuePair<TSequence, Double>>)
Creates a distribution which assigns specified probabilities to given sequences. Probabilities do not have to be normalized.
Declaration
public static TThis OneOf(IEnumerable<KeyValuePair<TSequence, double>> sequenceProbPairs)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<KeyValuePair<TSequence, Double>> | sequenceProbPairs | A list of (sequence, probability) pairs. |
Returns
| Type | Description |
|---|---|
| TThis | The created distribution. |
OneOf(Double, TThis, Double, TThis)
Creates a mixture of a given pair of distributions.
Declaration
public static TThis OneOf(double weight1, TThis dist1, double weight2, TThis dist2)
Parameters
| Type | Name | Description |
|---|---|---|
| Double | weight1 | The weight of the first distribution. |
| TThis | dist1 | The first distribution. |
| Double | weight2 | The weight of the second distribution. |
| TThis | dist2 | The second distribution. |
Returns
| Type | Description |
|---|---|
| TThis | The created mixture distribution. |
OneOrMore(TSequence, Nullable<Int32>)
An alias for Repeat(TThis, Int32, Nullable<Int32>) with the minimum number of repetitions set to 1.
Declaration
public static TThis OneOrMore(TSequence sequence, int? maxTimes = null)
Parameters
| Type | Name | Description |
|---|---|---|
| TSequence | sequence | The sequence. |
| Nullable<Int32> | maxTimes | The maximum number of repetitions, or null for no upper bound. Defaults to null. |
Returns
| Type | Description |
|---|---|
| TThis | The created distribution. |
OneOrMore(TElement, Nullable<Int32>)
An alias for Repeat(TElement, Int32, Nullable<Int32>, DistributionKind) with the minimum number of repetitions set to 1 and uniformity kind set to UniformOverValue.
Declaration
public static TThis OneOrMore(TElement element, int? maxTimes = null)
Parameters
| Type | Name | Description |
|---|---|---|
| TElement | element | The element. |
| Nullable<Int32> | maxTimes | The maximum number of repetitions, or null for no upper bound. Defaults to null. |
Returns
| Type | Description |
|---|---|
| TThis | The created distribution. |
OneOrMore(TElementDistribution, Nullable<Int32>)
An alias for Repeat(TElementDistribution, Int32, Nullable<Int32>, DistributionKind) with the minimum number of repetitions set to 0 and uniformity kind set to UniformOverValue.
Declaration
public static TThis OneOrMore(TElementDistribution allowedElements, int? maxTimes = null)
Parameters
| Type | Name | Description |
|---|---|---|
| TElementDistribution | allowedElements | The allowed sequence elements. |
| Nullable<Int32> | maxTimes | The maximum number of repetitions, or null for no upper bound. Defaults to null. |
Returns
| Type | Description |
|---|---|
| TThis | The created distribution. |
OneOrMore(TThis, Nullable<Int32>)
An alias for Repeat(TThis, Int32, Nullable<Int32>) with the minimum number of repetitions set to 1.
Declaration
public static TThis OneOrMore(TThis dist, int? maxTimes = null)
Parameters
| Type | Name | Description |
|---|---|---|
| TThis | dist | The distribution. |
| Nullable<Int32> | maxTimes | The maximum number of repetitions, or null for no upper bound. Defaults to null. |
Returns
| Type | Description |
|---|---|
| TThis | The created distribution. |
Optional(TSequence, Double)
Creates a mixture of a point mass on the given sequence and a point mass representing an empty sequence.
Declaration
public static TThis Optional(TSequence sequence, double prob = 0.5)
Parameters
| Type | Name | Description |
|---|---|---|
| TSequence | sequence | The given sequence. |
| Double | prob | The probability of the component corresponding to |
Returns
| Type | Description |
|---|---|
| TThis | The created mixture. |
Optional(TThis, Double)
Creates a mixture of a given distribution and a point mass representing an empty sequence.
Declaration
public static TThis Optional(TThis dist, double prob = 0.5)
Parameters
| Type | Name | Description |
|---|---|---|
| TThis | dist | The distribution. |
| Double | prob | The probability of the component corresponding to |
Returns
| Type | Description |
|---|---|
| TThis | The created mixture. |
PointMass(TSequence)
Creates a point mass distribution.
Declaration
[Construction(new string[]{"Point"}, UseWhen = "IsPointMass")]
public static TThis PointMass(TSequence point)
Parameters
| Type | Name | Description |
|---|---|---|
| TSequence | point | The point. |
Returns
| Type | Description |
|---|---|
| TThis | The created point mass distribution. |
Product(TThis)
Returns a product of the current distribution and a given one.
Declaration
public TThis Product(TThis that)
Parameters
| Type | Name | Description |
|---|---|---|
| TThis | that | The distribution to compute the product with. |
Returns
| Type | Description |
|---|---|
| TThis | The product. |
Repeat(TSequence, Int32, Nullable<Int32>)
Creates a uniform distribution over sequences containing N repeats of the
specified sequence, where n lies within the given bounds.
If maxTimes is set to null,
there will be no upper bound on the number of repeats, and the resulting distribution will thus be improper.
Declaration
public static TThis Repeat(TSequence sequence, int minTimes = 1, int? maxTimes = null)
Parameters
| Type | Name | Description |
|---|---|---|
| TSequence | sequence | The sequence to repeat. |
| Int32 | minTimes | The minimum possible sequence length. Defaults to 1. |
| Nullable<Int32> | maxTimes | The maximum possible sequence length, or null for no upper bound on length. Defaults to null. |
Returns
| Type | Description |
|---|---|
| TThis | The created distribution. |
Repeat(TElement, Int32, Nullable<Int32>, DistributionKind)
Creates a uniform distribution over sequences of length within the given bounds.
Sequence elements are restricted to be equal to a given element.
If maxTimes is set to null,
there will be no upper bound on the length, and the resulting distribution will thus be improper.
Declaration
public static TThis Repeat(TElement element, int minTimes = 1, int? maxTimes = null, DistributionKind uniformity = DistributionKind.UniformOverValue)
Parameters
| Type | Name | Description |
|---|---|---|
| TElement | element | The element. |
| Int32 | minTimes | The minimum possible sequence length. Defaults to 1. |
| Nullable<Int32> | maxTimes | The maximum possible sequence length, or null for no upper bound on length. Defaults to null. |
| DistributionKind | uniformity | The type of uniformity. |
Returns
| Type | Description |
|---|---|
| TThis | The created distribution. |
Repeat(TElementDistribution, Int32, Nullable<Int32>, DistributionKind)
Creates a uniform distribution over sequences of length within the given bounds.
Sequence elements are restricted to be non-zero probability elements from a given distribution.
If maxTimes is set to null,
there will be no upper bound on the length, and the resulting distribution will thus be improper.
Declaration
public static TThis Repeat(TElementDistribution allowedElements, int minTimes = 1, int? maxTimes = null, DistributionKind uniformity = DistributionKind.UniformOverValue)
Parameters
| Type | Name | Description |
|---|---|---|
| TElementDistribution | allowedElements | The distribution representing allowed sequence elements. |
| Int32 | minTimes | The minimum possible sequence length. Defaults to 1. |
| Nullable<Int32> | maxTimes | The maximum possible sequence length, or null for no upper bound on length. Defaults to null. |
| DistributionKind | uniformity | The type of uniformity |
Returns
| Type | Description |
|---|---|
| TThis | The created distribution. |
Repeat(TThis, Int32, Nullable<Int32>)
Creates a distribution by applying Repeat(TThis, Int32, Nullable<Int32>) to the weight function of a given distribution, which is additionally scaled by the inverse of GetLogAverageOf(TThis) with itself. So, if the given distribution is partial uniform, the result will be partial uniform over the repetitions of sequences covered by the distribution.
If maxTimes is set to null,
there will be no upper bound on the length, and the resulting distribution will thus be improper.
Declaration
public static TThis Repeat(TThis dist, int minTimes = 1, int? maxTimes = null)
Parameters
| Type | Name | Description |
|---|---|---|
| TThis | dist | The distribution. |
| Int32 | minTimes | The minimum number of repetitions. Defaults to 1. |
| Nullable<Int32> | maxTimes | The maximum number of repetitions, or null for no upper bound. Defaults to null. |
Returns
| Type | Description |
|---|---|
| TThis | The created distribution. |
Sample()
Draws a sample from the distribution.
Declaration
public TSequence Sample()
Returns
| Type | Description |
|---|---|
| TSequence | The drawn sample. |
Sample(TSequence)
Draws a sample from the distribution.
Declaration
public TSequence Sample(TSequence result)
Parameters
| Type | Name | Description |
|---|---|---|
| TSequence | result | A pre-allocated storage for the sample (will be ignored). |
Returns
| Type | Description |
|---|---|
| TSequence | The drawn sample. |
SetLogValueOverride(Nullable<Double>)
Sets a value that, if not null, will be returned when computing the log probability of any sequence which is in the support of this distribution.
Declaration
public void SetLogValueOverride(double? logValueOverride)
Parameters
| Type | Name | Description |
|---|---|---|
| Nullable<Double> | logValueOverride | A non-null value that should be returned when computing the log probability of any sequence which is in the support of this distribution, or null to clear any existing override. |
SetTo(TThis)
Replaces the current distribution by a copy of the given distribution.
Declaration
public void SetTo(TThis that)
Parameters
| Type | Name | Description |
|---|---|---|
| TThis | that | The distribution to set the current distribution to. |
SetToPartialUniform()
Sets the distribution to be uniform over its support.
Declaration
public void SetToPartialUniform()
Remarks
This function will fail if the weight function of this distribution is represented by an automaton that cannot be determinized.
SetToPartialUniformOf(TThis)
Sets the distribution to be uniform over the support of a given distribution.
Declaration
public void SetToPartialUniformOf(TThis dist)
Parameters
| Type | Name | Description |
|---|---|---|
| TThis | dist | The distribution which support will be used to setup the current distribution. |
Remarks
This function will fail if the weight function of dist
is represented by an automaton that cannot be determinized.
SetToPower(TThis, Double)
Replaces the current distribution with a given distribution raised to a given power.
Declaration
public void SetToPower(TThis that, double power)
Parameters
| Type | Name | Description |
|---|---|---|
| TThis | that | The distribution to raise to the power. |
| Double | power | The power. |
Remarks
Only 0 and 1 are currently supported as powers.
SetToProduct(TThis, TThis)
Replaces the current distribution with a product of a given pair of distributions.
Declaration
public void SetToProduct(TThis dist1, TThis dist2)
Parameters
| Type | Name | Description |
|---|---|---|
| TThis | dist1 | The first distribution. |
| TThis | dist2 | The second distribution. |
SetToProductAndReturnLogNormalizer(TThis, TThis, Boolean)
Replaces the current distribution with a product of a given pair of distributions Returns the logarithm of the normalizer for the product (as returned by GetLogAverageOf(TThis)).
Declaration
public double SetToProductAndReturnLogNormalizer(TThis dist1, TThis dist2, bool tryDeterminize = true)
Parameters
| Type | Name | Description |
|---|---|---|
| TThis | dist1 | The first distribution. |
| TThis | dist2 | The second distribution. |
| Boolean | tryDeterminize | Whether to try to determinize the result. |
Returns
| Type | Description |
|---|---|
| Double | The logarithm of the normalizer for the product. |
SetToRatio(TThis, TThis, Boolean)
Replaces the current distribution with the ratio of a given pair of distributions. Not currently supported.
Declaration
public void SetToRatio(TThis numerator, TThis denominator, bool forceProper)
Parameters
| Type | Name | Description |
|---|---|---|
| TThis | numerator | The numerator in the ratio. |
| TThis | denominator | The denominator in the ratio. |
| Boolean | forceProper | Specifies whether the ratio must be proper. |
SetToSum(Double, TThis, Double, TThis)
Replaces the current distribution with a mixture of a given pair of distributions.
Declaration
public void SetToSum(double weight1, TThis dist1, double weight2, TThis dist2)
Parameters
| Type | Name | Description |
|---|---|---|
| Double | weight1 | The weight of the first distribution. |
| TThis | dist1 | The first distribution. |
| Double | weight2 | The weight of the second distribution. |
| TThis | dist2 | The second distribution. |
SetToSumLog(Double, TThis, Double, TThis)
Replaces the current distribution with a mixture of a given pair of distributions.
Declaration
public void SetToSumLog(double logWeight1, TThis dist1, double logWeight2, TThis dist2)
Parameters
| Type | Name | Description |
|---|---|---|
| Double | logWeight1 | The logarithm of the weight of the first distribution. |
| TThis | dist1 | The first distribution. |
| Double | logWeight2 | The logarithm of the weight of the second distribution. |
| TThis | dist2 | The second distribution. |
SetToUniform()
Replaces the current distribution with an improper distribution which assigns the probability of 1 to every sequence.
Declaration
public void SetToUniform()
SetToUniformOf(TElementDistribution)
Replaces the current distribution with an improper distribution which assigns the probability of 1 to every sequence. Sequence elements are restricted to be non-zero probability elements from a given distribution.
Declaration
public void SetToUniformOf(TElementDistribution allowedElements)
Parameters
| Type | Name | Description |
|---|---|---|
| TElementDistribution | allowedElements | The distribution representing allowed sequence elements. |
SetToUniformOf(TElementDistribution, Double)
Replaces the current distribution with an improper distribution which assigns a given probability to every sequence. Sequence elements are restricted to be non-zero probability elements from a given distribution.
Declaration
protected void SetToUniformOf(TElementDistribution allowedElements, double uniformLogProb)
Parameters
| Type | Name | Description |
|---|---|---|
| TElementDistribution | allowedElements | The distribution representing allowed sequence elements. |
| Double | uniformLogProb | The logarithm of the probability assigned to every allowed sequence. |
SetToZero()
Replaces the current distribution by an improper zero distribution.
Declaration
public void SetToZero()
SetWeightFunction(TAutomaton, Boolean)
Replaces the weight function of the current distribution with a given one.
Declaration
public void SetWeightFunction(TAutomaton weightFunction, bool normalizeStructure = true)
Parameters
| Type | Name | Description |
|---|---|---|
| TAutomaton | weightFunction | |
| Boolean | normalizeStructure | Whether to normalize the structure of the distribution |
SetWeightFunction(TWeightFunction, Boolean)
Replaces the weight function of the current distribution with a given one.
Declaration
public void SetWeightFunction(TWeightFunction weightFunction, bool normalizeStructure = true)
Parameters
| Type | Name | Description |
|---|---|---|
| TWeightFunction | weightFunction | The weight function to replace the current one with. |
| Boolean | normalizeStructure | Whether to normalize the structure of the distribution |
SingleElement(TElement)
Creates a distribution which puts all probability mass on a sequence containing only a given element.
Declaration
public static TThis SingleElement(TElement element)
Parameters
| Type | Name | Description |
|---|---|---|
| TElement | element | The element. |
Returns
| Type | Description |
|---|---|
| TThis | The created distribution. |
SingleElement(TElementDistribution)
Creates a distribution over sequences of length 1 induced by a given distribution over sequence elements.
Declaration
public static TThis SingleElement(TElementDistribution elementDistribution)
Parameters
| Type | Name | Description |
|---|---|---|
| TElementDistribution | elementDistribution | The distribution over sequence elements. |
Returns
| Type | Description |
|---|---|
| TThis | The created distribution. |
Remarks
The distribution created by this method can differ from the result of Repeat(TElementDistribution, Int32, Nullable<Int32>, DistributionKind) with both min and max number of times to repeat set to 1 since the latter always creates a partial uniform distribution.
ToAutomaton()
Returns an automaton representing the underlying weight function.
Declaration
public TAutomaton ToAutomaton()
Returns
| Type | Description |
|---|---|
| TAutomaton | An automaton representing the underlying weight function. |
Remarks
The returned weight function might differ from the probability function by an arbitrary scale factor. To ensure that the weight function is normalized, use ToNormalizedAutomaton().
ToNormalizedAutomaton()
Returns an automaton representing the underlying weight function.
Declaration
public TAutomaton ToNormalizedAutomaton()
Returns
| Type | Description |
|---|---|
| TAutomaton | An automaton representing the underlying weight function. |
Remarks
The returned weight function is guaranteed to be normalized. If you don't care about an arbitrary scale factor, consider using ToAutomaton() which has less overhead.
ToString()
Returns a string that represents the distribution.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| String | A string that represents the distribution. |
Overrides
ToString(ISequenceDistributionFormat)
Returns a string that represents the distribution.
Declaration
public string ToString(ISequenceDistributionFormat format)
Parameters
| Type | Name | Description |
|---|---|---|
| ISequenceDistributionFormat | format | The format. |
Returns
| Type | Description |
|---|---|
| String | A string that represents the distribution. |
ToString(Action<TElementDistribution, StringBuilder>)
Returns a string that represents the distribution.
Declaration
protected string ToString(Action<TElementDistribution, StringBuilder> appendRegex)
Parameters
| Type | Name | Description |
|---|---|---|
| Action<TElementDistribution, StringBuilder> | appendRegex | Optional method for appending at the element distribution level. |
Returns
| Type | Description |
|---|---|
| String | A string that represents the automaton. |
TryDeterminize()
Tries to replace the internal representation of the current distribution with an equivalent deterministic automaton, unless the current representation is guaranteed to produce a deterministic automaton on conversion.
Declaration
public bool TryDeterminize()
Returns
| Type | Description |
|---|---|
| Boolean | true if the internal representation of the current distribution was successfully replaced with a deterministic automaton or is guaranteed to produce one on direct conversion, false otherwise. |
TryEnumerateSupport(Int32, out IEnumerable<TSequence>, Boolean)
Enumerates support of this distribution when possible. Only point mass elements are supported.
Declaration
public bool TryEnumerateSupport(int maxCount, out IEnumerable<TSequence> result, bool tryDeterminize = true)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | maxCount | The maximum support enumeration count. |
| IEnumerable<TSequence> | result | The strings supporting this distribution. |
| Boolean | tryDeterminize | Try to determinize if this distribution uses a string automaton representation. |
Returns
| Type | Description |
|---|---|
| Boolean | True if successful, false otherwise. |
Exceptions
| Type | Condition |
|---|---|
| AutomatonException | Thrown if enumeration is too large. |
Uniform()
Creates an improper distribution which assigns the probability of 1 to every sequence.
Declaration
[Construction(UseWhen = "IsUniform")]
public static TThis Uniform()
Returns
| Type | Description |
|---|---|
| TThis | The created uniform distribution. |
UniformOf(TElementDistribution, Double)
Creates an improper distribution which assigns a given probability to every sequence. Sequence elements are restricted to be non-zero probability elements from a given distribution.
Declaration
protected static TThis UniformOf(TElementDistribution allowedElements, double uniformLogProb)
Parameters
| Type | Name | Description |
|---|---|---|
| TElementDistribution | allowedElements | The distribution representing allowed sequence elements. |
| Double | uniformLogProb | The logarithm of the probability assigned to every allowed sequence. |
Returns
| Type | Description |
|---|---|
| TThis | The created distribution. |
Zero()
Creates an improper distribution which assigns zero probability to every sequence.
Declaration
[Construction(UseWhen = "IsZero")]
public static TThis Zero()
Returns
| Type | Description |
|---|---|
| TThis | The created zero distribution. |
ZeroOrMore(TSequence, Nullable<Int32>)
An alias for Repeat(TThis, Int32, Nullable<Int32>) with the minimum number of repetitions set to 0.
Declaration
public static TThis ZeroOrMore(TSequence sequence, int? maxTimes = null)
Parameters
| Type | Name | Description |
|---|---|---|
| TSequence | sequence | The sequence. |
| Nullable<Int32> | maxTimes | The maximum number of repetitions, or null for no upper bound. Defaults to null. |
Returns
| Type | Description |
|---|---|
| TThis | The created distribution. |
ZeroOrMore(TElement, Nullable<Int32>)
An alias for Repeat(TElement, Int32, Nullable<Int32>, DistributionKind) with the minimum number of repetitions set to 0 and uniformity kind set to UniformOverValue.
Declaration
public static TThis ZeroOrMore(TElement element, int? maxTimes = null)
Parameters
| Type | Name | Description |
|---|---|---|
| TElement | element | The element. |
| Nullable<Int32> | maxTimes | The maximum number of repetitions, or null for no upper bound. Defaults to null. |
Returns
| Type | Description |
|---|---|
| TThis | The created distribution. |
ZeroOrMore(TElementDistribution, Nullable<Int32>)
An alias for Repeat(TElementDistribution, Int32, Nullable<Int32>, DistributionKind) with the minimum number of repetitions set to 0 and uniformity kind set to UniformOverValue.
Declaration
public static TThis ZeroOrMore(TElementDistribution allowedElements, int? maxTimes = null)
Parameters
| Type | Name | Description |
|---|---|---|
| TElementDistribution | allowedElements | The allowed sequence elements. |
| Nullable<Int32> | maxTimes | The maximum number of repetitions, or null for no upper bound. Defaults to null. |
Returns
| Type | Description |
|---|---|
| TThis | The created distribution. |
ZeroOrMore(TThis, Nullable<Int32>)
An alias for Repeat(TThis, Int32, Nullable<Int32>) with the minimum number of repetitions set to 0.
Declaration
public static TThis ZeroOrMore(TThis dist, int? maxTimes = null)
Parameters
| Type | Name | Description |
|---|---|---|
| TThis | dist | The distribution. |
| Nullable<Int32> | maxTimes | The maximum number of repetitions, or null for no upper bound. Defaults to null. |
Returns
| Type | Description |
|---|---|
| TThis | The created distribution. |
Explicit Interface Implementations
ICloneable.Clone()
Creates a copy of the current distribution.
Declaration
object ICloneable.Clone()
Returns
| Type | Description |
|---|---|
| Object | The created copy. |