Interface WeightFunctions<TSequence, TElement, TElementDistribution, TSequenceManipulator, TAutomaton>.IWeightFunction<TThis>
Interface for a function that maps arbitrary sequences of elements to real values, that can, but not necessarily has to be, represented as a weighted finite state automaton.
Inherited Members
Namespace: Microsoft.ML.Probabilistic.Distributions.Automata
Assembly: Microsoft.ML.Probabilistic.dll
Syntax
[Quality(QualityBand.Experimental)]
public interface IWeightFunction<TThis> : WeightFunctions<TSequence, TElement, TElementDistribution, TSequenceManipulator, TAutomaton>.IWeightFunction, IEquatable<TThis> where TThis : WeightFunctions<TSequence, TElement, TElementDistribution, TSequenceManipulator, TAutomaton>.IWeightFunction<TThis>, new()
Type Parameters
Name | Description |
---|---|
TThis | The type of a concrete weight function class. |
Remarks
Types implementing this interface must be constant and thread-safe.
Methods
Append(TSequence, Int32)
Creates a weight function f'(st) = f(s)
, where f(s)
is the current weight function
and t
is the given sequence.
Declaration
TThis Append(TSequence sequence, int group = 0)
Parameters
Type | Name | Description |
---|---|---|
TSequence | sequence | The sequence. |
Int32 | group | The group. |
Returns
Type | Description |
---|---|
TThis | The created weight function. |
Append(TThis, Int32)
Creates a weight function f'(s) = sum_{tu=s} f(t)g(u)
, where f(t)
is the current weight function
and g(u)
is the given weight function.
Declaration
TThis Append(TThis weightFunction, int group = 0)
Parameters
Type | Name | Description |
---|---|---|
TThis | weightFunction | The weight function to append. |
Int32 | group | The group. |
Returns
Type | Description |
---|---|
TThis | The created weight function. |
GetGroups()
If the current weight function uses groups, returns a dictionary [group index] -> group. Otherwise, returns an empty dictionary.
Declaration
Dictionary<int, TThis> GetGroups()
Returns
Type | Description |
---|---|
Dictionary<Int32, TThis> | A possibly empty dictionary [group index] -> group. |
MaxDiff(TThis)
Gets a value indicating how close this weight function is to a given one in terms of weights they assign to sequences.
Declaration
double MaxDiff(TThis that)
Parameters
Type | Name | Description |
---|---|---|
TThis | that | The other weight function. |
Returns
Type | Description |
---|---|
Double | A non-negative value, which is close to zero if the two weight functions assign similar values to all sequences. |
NormalizeStructure()
Returns the weight function converted to the normalized form e.g. using special case structures for point masses and functions with small support.
Declaration
TThis NormalizeStructure()
Returns
Type | Description |
---|---|
TThis |
Product(TThis)
Computes the product of the current weight function and a given one.
Declaration
TThis Product(TThis weightFunction)
Parameters
Type | Name | Description |
---|---|---|
TThis | weightFunction | The weight function to compute the product with. |
Returns
Type | Description |
---|---|
TThis | The computed product. |
Repeat(Int32, Nullable<Int32>)
Creates a weight function g(s) = sum_{k=Kmin}^{Kmax} sum_{t1 t2 ... tk = s} f(t1)f(t2)...f(tk)
,
where f(t)
is the current weight function, and Kmin
and Kmax
are the minimum
and the maximum number of factors in a sum term.
Declaration
TThis Repeat(int minTimes = 1, int? maxTimes = null)
Parameters
Type | Name | Description |
---|---|---|
Int32 | minTimes | The minimum number of factors in a sum term. Defaults to 1. |
Nullable<Int32> | maxTimes | An optional maximum number of factors in a sum term. |
Returns
Type | Description |
---|---|
TThis | The created weight function. |
ScaleLog(Double)
Scales the weight function and returns the result.
Declaration
TThis ScaleLog(double logScale)
Parameters
Type | Name | Description |
---|---|---|
Double | logScale | The logarithm of the scale. |
Returns
Type | Description |
---|---|
TThis | The scaled weight function. |
Sum(TThis)
Computes the sum of the current weight function and a given weight function.
Declaration
TThis Sum(TThis weightFunction)
Parameters
Type | Name | Description |
---|---|---|
TThis | weightFunction | The weight function to compute the sum with. |
Returns
Type | Description |
---|---|
TThis | The computed sum. |
Sum(Double, TThis, Double)
Computes the weighted sum of the current weight function and a given weight function.
Declaration
TThis Sum(double weight1, TThis weightFunction, double weight2)
Parameters
Type | Name | Description |
---|---|---|
Double | weight1 | The weight of the current weight function. |
TThis | weightFunction | The weight function to compute the sum with. |
Double | weight2 | The weight of the |
Returns
Type | Description |
---|---|
TThis |
SumLog(Double, TThis, Double)
Computes the weighted sum of the current weight function and a given weight function.
Declaration
TThis SumLog(double logWeight1, TThis weightFunction, double logWeight2)
Parameters
Type | Name | Description |
---|---|---|
Double | logWeight1 | The logarithm of the weight of the current weight function. |
TThis | weightFunction | The weight function to compute the sum with. |
Double | logWeight2 | The logarithm of the weight of the |
Returns
Type | Description |
---|---|
TThis |
TryNormalizeValues(out TThis, out Double)
Attempts to normalize the weight function so that sum of its values on all possible sequences equals to one (if it is possible) and returns the result in an out parameter. If successful, calls to AsAutomaton() methods of the resulting function produce a stochastic automaton, i.e. an automaton, in which the sum of weights of all the outgoing transitions and the ending weight is 1 for every node.
Declaration
bool TryNormalizeValues(out TThis normalizedFunction, out double logNormalizer)
Parameters
Type | Name | Description |
---|---|---|
TThis | normalizedFunction | Result of the normaliztion attempt. |
Double | logNormalizer | When the function returns, contains the logarithm of the normalizer. |
Returns
Type | Description |
---|---|
Boolean | true if the weight function was successfully normalized, false otherwise. |