Search Results for

    Show / Hide Table of Contents

    Class WeightFunctions<TSequence, TElement, TElementDistribution, TSequenceManipulator, TAutomaton>.DictionaryWeightFunction<TThis>

    An implementation of WeightFunctions<TSequence, TElement, TElementDistribution, TSequenceManipulator, TAutomaton>.IWeightFunction<TThis> that stores the entire support of the weight function along with the associated weights in a dictionary.

    Inheritance
    Object
    WeightFunctions<TSequence, TElement, TElementDistribution, TSequenceManipulator, TAutomaton>.DictionaryWeightFunction<TThis>
    ListDictionaryWeightFunction<TElement, TElementDistribution>
    ListDictionaryWeightFunction<TList, TElement, TElementDistribution>
    StringDictionaryWeightFunction
    Implements
    WeightFunctions.IWeightFunction<TThis>
    WeightFunctions.IWeightFunction<>
    IEquatable<TThis>
    Inherited Members
    Object.Equals(Object, Object)
    Object.GetType()
    Object.MemberwiseClone()
    Object.ReferenceEquals(Object, Object)
    Namespace: Microsoft.ML.Probabilistic.Distributions.Automata
    Assembly: Microsoft.ML.Probabilistic.dll
    Syntax
    [Serializable]
    [DataContract]
    [Quality(QualityBand.Experimental)]
    public class DictionaryWeightFunction<TThis> : WeightFunctions<TSequence, TElement, TElementDistribution, TSequenceManipulator, TAutomaton>.IWeightFunction<TThis>, WeightFunctions<TSequence, TElement, TElementDistribution, TSequenceManipulator, TAutomaton>.IWeightFunction, IEquatable<TThis> where TThis : WeightFunctions<TSequence, TElement, TElementDistribution, TSequenceManipulator, TAutomaton>.DictionaryWeightFunction<TThis>, new()
    Type Parameters
    Name Description
    TThis

    The type of a concrete dictionary weight function class.

    Constructors

    DictionaryWeightFunction()

    Declaration
    public DictionaryWeightFunction()

    DictionaryWeightFunction(IReadOnlyDictionary<TSequence, Weight>)

    Declaration
    protected DictionaryWeightFunction(IReadOnlyDictionary<TSequence, Weight> dictionary)
    Parameters
    Type Name Description
    IReadOnlyDictionary<TSequence, Weight> dictionary

    Fields

    dictionary

    Declaration
    [DataMember]
    protected IReadOnlyDictionary<TSequence, Weight> dictionary
    Field Value
    Type Description
    IReadOnlyDictionary<TSequence, Weight>

    Properties

    Dictionary

    A dictionary containing the entire support of the current weight function and the corresponding weights.

    Declaration
    public IReadOnlyDictionary<TSequence, Weight> Dictionary { get; }
    Property Value
    Type Description
    IReadOnlyDictionary<TSequence, Weight>

    ElementDistributionFactory

    Declaration
    protected static TElementDistribution ElementDistributionFactory { get; }
    Property Value
    Type Description
    TElementDistribution

    IsPointMass

    Gets a value indicating whether the current weight function assigns a non-zero weight to exactly one point.

    Declaration
    public bool IsPointMass { get; }
    Property Value
    Type Description
    Boolean

    Point

    Gets the only point to which the current function assigns a non-zero weight.

    Declaration
    public TSequence Point { get; }
    Property Value
    Type Description
    TSequence
    Exceptions
    Type Condition
    InvalidOperationException

    Thrown when an attempt is made to get the Point of a non-pointmass weight function.

    SequenceManipulator

    Declaration
    protected static TSequenceManipulator SequenceManipulator { get; }
    Property Value
    Type Description
    TSequenceManipulator

    UsesAutomatonRepresentation

    Gets a value indicating whether the current weight function is represented as an automaton internally.

    Declaration
    public bool UsesAutomatonRepresentation { get; }
    Property Value
    Type Description
    Boolean

    UsesGroups

    Checks if the weight function uses groups.

    Declaration
    public bool UsesGroups { get; }
    Property Value
    Type Description
    Boolean

    true if the weight function uses groups, false otherwise.

    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
    public 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
    public 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.

    AsAutomaton()

    Returns an automaton representation of the current weight function. If the weight function is normalized, the resulting automaton is stochastic, i.e. the sum of weights of all the outgoing transitions and the ending weight is 1 for every node.

    Declaration
    public virtual TAutomaton AsAutomaton()
    Returns
    Type Description
    TAutomaton

    EnumeratePaths()

    Declaration
    public IEnumerable<Tuple<List<TElementDistribution>, double>> EnumeratePaths()
    Returns
    Type Description
    IEnumerable<Tuple<List<TElementDistribution>, Double>>

    EnumerateSupport(Int32)

    Enumerates support of this weight function when possible.

    Declaration
    public IEnumerable<TSequence> EnumerateSupport(int maxCount = 1000000)
    Parameters
    Type Name Description
    Int32 maxCount

    The maximum support enumeration count.

    Returns
    Type Description
    IEnumerable<TSequence>

    The sequences in the support of this weight function

    Exceptions
    Type Condition
    AutomatonEnumerationCountException

    Thrown if enumeration is too large.

    Equals(TThis)

    Declaration
    public bool Equals(TThis other)
    Parameters
    Type Name Description
    TThis other
    Returns
    Type Description
    Boolean

    Equals(Object)

    Declaration
    public override bool Equals(object obj)
    Parameters
    Type Name Description
    Object obj
    Returns
    Type Description
    Boolean
    Overrides
    Object.Equals(Object)

    FillDictionary(IDictionary<TSequence, Weight>, IEnumerable<KeyValuePair<TSequence, Weight>>)

    Fills the supplied empty sequence to weight dictionary with values from the given collection. If the supplied collection contains multiple entries for the same sequence, the weights for that sequence are summed.

    Declaration
    protected static void FillDictionary(IDictionary<TSequence, Weight> dictionaryToFill, IEnumerable<KeyValuePair<TSequence, Weight>> sequenceWeightPairs)
    Parameters
    Type Name Description
    IDictionary<TSequence, Weight> dictionaryToFill

    The target empty dictionary.

    IEnumerable<KeyValuePair<TSequence, Weight>> sequenceWeightPairs

    The collection of pairs of a sequence and the weight on that sequence.

    FromDistinctValues(IEnumerable<KeyValuePair<TSequence, Double>>)

    Creates a sequence to weight dictionary using the supplied sequenceWeightPairs. If the supplied collection is expected to not contain multiple entries for the same sequence.

    Declaration
    public static TThis FromDistinctValues(IEnumerable<KeyValuePair<TSequence, double>> sequenceWeightPairs)
    Parameters
    Type Name Description
    IEnumerable<KeyValuePair<TSequence, Double>> sequenceWeightPairs

    The collection of pairs of a sequence and the weight on that sequence.

    Returns
    Type Description
    TThis

    FromDistinctWeights(IEnumerable<KeyValuePair<TSequence, Weight>>)

    Creates a sequence to weight dictionary using the supplied sequenceWeightPairs. If the supplied collection is expected to not contain multiple entries for the same sequence.

    Declaration
    [Construction(new string[]{"Dictionary"})]
    public static TThis FromDistinctWeights(IEnumerable<KeyValuePair<TSequence, Weight>> sequenceWeightPairs)
    Parameters
    Type Name Description
    IEnumerable<KeyValuePair<TSequence, Weight>> sequenceWeightPairs

    The collection of pairs of a sequence and the weight on that sequence.

    Returns
    Type Description
    TThis

    FromPoint(TSequence)

    Creates a sequence to weight dictionary with point being its only key which corresponds to a unit weight.

    Declaration
    public static TThis FromPoint(TSequence point)
    Parameters
    Type Name Description
    TSequence point

    The only sequence contained in the dictionary.

    Returns
    Type Description
    TThis

    FromValues(IEnumerable<KeyValuePair<TSequence, Double>>)

    Creates a sequence to weight dictionary using the supplied sequenceWeightPairs. If the supplied collection contains multiple entries for the same sequence, the weights for that sequence are summed.

    Declaration
    public static TThis FromValues(IEnumerable<KeyValuePair<TSequence, double>> sequenceWeightPairs)
    Parameters
    Type Name Description
    IEnumerable<KeyValuePair<TSequence, Double>> sequenceWeightPairs

    The collection of pairs of a sequence and the weight on that sequence.

    Returns
    Type Description
    TThis

    FromWeights(IEnumerable<KeyValuePair<TSequence, Weight>>)

    Creates a sequence to weight dictionary using the supplied sequenceWeightPairs. If the supplied collection contains multiple entries for the same sequence, the weights for that sequence are summed.

    Declaration
    public static TThis FromWeights(IEnumerable<KeyValuePair<TSequence, Weight>> sequenceWeightPairs)
    Parameters
    Type Name Description
    IEnumerable<KeyValuePair<TSequence, Weight>> sequenceWeightPairs

    The collection of pairs of a sequence and the weight on that sequence.

    Returns
    Type Description
    TThis

    GetGroups()

    If the current weight function uses groups, returns a dictionary [group index] -> group. Otherwise, returns an empty dictionary.

    Declaration
    public Dictionary<int, TThis> GetGroups()
    Returns
    Type Description
    Dictionary<Int32, TThis>

    A possibly empty dictionary [group index] -> group.

    GetHashCode()

    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    Int32
    Overrides
    Object.GetHashCode()

    GetLogNormalizer()

    Computes the logarithm of the normalizer (sum of values of the weight function on all sequences).

    Declaration
    public double GetLogNormalizer()
    Returns
    Type Description
    Double

    The logarithm of the normalizer.

    Remarks

    Returns PositiveInfinity if the sum diverges.

    GetLogNormalizerOfProduct(TThis)

    Computes the logarithm of the normalizer (sum of values of the weight function on all sequences) of the product of the current and the given weight functions.

    Declaration
    protected virtual double GetLogNormalizerOfProduct(TThis weightFunction)
    Parameters
    Type Name Description
    TThis weightFunction

    The given weight function.

    Returns
    Type Description
    Double

    The logarithm of the normalizer.

    GetLogNormalizerOfSquare()

    Computes the logarithm of the normalizer (sum of values of the weight function on all sequences) of the square of the current weight function.

    Declaration
    protected double GetLogNormalizerOfSquare()
    Returns
    Type Description
    Double

    The logarithm of the normalizer.

    GetLogSimilarity(TThis)

    Gets a value indicating how close this weight function is to a given one in terms of weights they assign to sequences.

    Declaration
    protected double GetLogSimilarity(TThis that)
    Parameters
    Type Name Description
    TThis that

    The other weight function.

    Returns
    Type Description
    Double

    The logarithm of a non-negative value, which is close to zero if the two automata assign similar values to all sequences.

    GetLogValue(TSequence)

    Computes the logarithm of the value of the weight function on a given sequence.

    Declaration
    public double GetLogValue(TSequence sequence)
    Parameters
    Type Name Description
    TSequence sequence

    The sequence to compute the value on.

    Returns
    Type Description
    Double

    The logarithm of the value.

    HasGroup(Int32)

    Determines whether this weight function has the specified group (if applicable).

    Declaration
    public bool HasGroup(int group)
    Parameters
    Type Name Description
    Int32 group

    The specified group.

    Returns
    Type Description
    Boolean

    True if it the weight function has this group, false otherwise.

    IsZero()

    Checks whether the current weight function is zero on all sequences.

    Declaration
    public bool IsZero()
    Returns
    Type Description
    Boolean

    true if the current weight function is zero on all sequences, false otherwise.

    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
    public 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
    public TThis NormalizeStructure()
    Returns
    Type Description
    TThis

    Product(TThis)

    Computes the product of the current weight function and a given one.

    Declaration
    public virtual 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, Int32, 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
    public TThis Repeat(int minTimes, int maxTimes, int expectedResultSupportSize)
    Parameters
    Type Name Description
    Int32 minTimes

    The minimum number of factors in a sum term. Defaults to 1.

    Int32 maxTimes

    The maximum number of factors in a sum term.

    Int32 expectedResultSupportSize

    Predicted size of the support of the resulting weight function. Does not have to be correct, but when it is, the performance is slightly improved.

    Returns
    Type Description
    TThis

    The created weight function.

    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
    public 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
    public TThis ScaleLog(double logScale)
    Parameters
    Type Name Description
    Double logScale

    The logarithm of the scale.

    Returns
    Type Description
    TThis

    The scaled weight function.

    SetDistinctWeights(IEnumerable<KeyValuePair<TSequence, Weight>>)

    Replaces the internal sequence to weight dictionary with a new one using the supplied sequenceWeightPairs. If the supplied collection is expected to not contain multiple entries for the same sequence.

    Declaration
    protected virtual void SetDistinctWeights(IEnumerable<KeyValuePair<TSequence, Weight>> sequenceWeightPairs)
    Parameters
    Type Name Description
    IEnumerable<KeyValuePair<TSequence, Weight>> sequenceWeightPairs

    The collection of pairs of a sequence and the weight on that sequence.

    Remarks

    Should only ever be called in factory methods.

    SetWeights(IEnumerable<KeyValuePair<TSequence, Weight>>)

    Replaces the internal sequence to weight dictionary with a new one using the supplied sequenceWeightPairs. If the supplied collection contains multiple entries for the same sequence, the weights for that sequence are summed.

    Declaration
    protected virtual void SetWeights(IEnumerable<KeyValuePair<TSequence, Weight>> sequenceWeightPairs)
    Parameters
    Type Name Description
    IEnumerable<KeyValuePair<TSequence, Weight>> sequenceWeightPairs

    The collection of pairs of a sequence and the weight on that sequence.

    Remarks

    Should only ever be called in factory methods.

    Sum(TThis)

    Computes the sum of the current weight function and a given weight function.

    Declaration
    public 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
    public 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 weightFunction.

    Returns
    Type Description
    TThis

    SumLog(Double, TThis, Double)

    Computes the weighted sum of the current weight function and a given weight function.

    Declaration
    public 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 weightFunction.

    Returns
    Type Description
    TThis

    ToString()

    Declaration
    public override string ToString()
    Returns
    Type Description
    String
    Overrides
    Object.ToString()

    ToString(Action<TElementDistribution, StringBuilder>)

    Declaration
    public string ToString(Action<TElementDistribution, StringBuilder> appendElement)
    Parameters
    Type Name Description
    Action<TElementDistribution, StringBuilder> appendElement
    Returns
    Type Description
    String

    TryEnumerateSupport(Int32, out IEnumerable<TSequence>)

    Tries to enumerate support of this weight function.

    Declaration
    public bool TryEnumerateSupport(int maxCount, out IEnumerable<TSequence> result)
    Parameters
    Type Name Description
    Int32 maxCount

    The maximum support enumeration count.

    IEnumerable<TSequence> result

    The sequences in the support of this weight function

    Returns
    Type Description
    Boolean

    True if successful, false otherwise

    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
    public virtual 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.

    Implements

    WeightFunctions<TSequence, TElement, TElementDistribution, TSequenceManipulator, TAutomaton>.IWeightFunction<TThis>
    WeightFunctions<TSequence, TElement, TElementDistribution, TSequenceManipulator, TAutomaton>.IWeightFunction
    System.IEquatable<T>
    In This Article
    Back to top Copyright © .NET Foundation. All rights reserved.