Class Automaton<TSequence, TElement, TElementDistribution, TSequenceManipulator, TThis>
Abstract base class for a weighted finite state automaton. It can be viewed as a function that maps arbitrary sequences of elements to real values.
Inheritance
Implements
Inherited Members
Namespace: Microsoft.ML.Probabilistic.Distributions.Automata
Assembly: Microsoft.ML.Probabilistic.dll
Syntax
[Quality(QualityBand.Experimental)]
[DataContract]
[Serializable]
public abstract class Automaton<TSequence, TElement, TElementDistribution, TSequenceManipulator, TThis> : WeightFunctions<TSequence, TElement, TElementDistribution, TSequenceManipulator, TThis>.IWeightFunction<TThis>, WeightFunctions<TSequence, TElement, TElementDistribution, TSequenceManipulator, TThis>.IWeightFunction, IEquatable<TThis> where TSequence : class, IEnumerable<TElement> where TElementDistribution : IImmutableDistribution<TElement, TElementDistribution>, CanGetLogAverageOf<TElementDistribution>, CanComputeProduct<TElementDistribution>, CanCreatePartialUniform<TElementDistribution>, SummableExactly<TElementDistribution>, new()
where TSequenceManipulator : ISequenceManipulator<TSequence, TElement>, new()
where TThis : Automaton<TSequence, TElement, TElementDistribution, TSequenceManipulator, TThis>, new()
Type Parameters
Name | Description |
---|---|
TSequence | The type of a sequence. |
TElement | The immutable type of a sequence element. |
TElementDistribution | The immutable type of a distribution over sequence elements. |
TSequenceManipulator | The type providing ways to manipulate sequences. |
TThis | The type of a concrete automaton class. |
Remarks
An automaton represented by this class has the following properties:
- Its states and transitions form a directed graph rooted at the Start;
- Each state has an associated cost for being an accepting ("end") state;
- Each transition has an associated cost for using it;
- A transition can have an associated distribution over elements. In that case an additional cost is being paid for using that transition with a specific element. The cost is equal to the log-probability of that element under the distribution;
- If a transition doesn't have an associated distribution over elements, it is an epsilon transition which can be used with no element only.
This class is constant and thread-safe (though, not truly immutable, as some properties are evaluated lazily and stored afterwards) and all implementations must preserve this property - some algorithms used to implement this class rely on it. For the same reason, implementations are not allowed to add new data fields.
Constructors
Automaton()
Initializes a new instance of the Automaton<TSequence, TElement, TElementDistribution, TSequenceManipulator, TThis> class by setting it to be zero everywhere.
Declaration
protected Automaton()
Properties
Data
Immutable container for automaton data - states and transitions.
Declaration
[DataMember]
public Automaton<TSequence, TElement, TElementDistribution, TSequenceManipulator, TThis>.DataContainer Data { get; protected set; }
Property Value
Type | Description |
---|---|
Automaton.DataContainer<> |
GlobalMaxStateCount
Gets or sets the maximum number of states an automaton can have. This setting is shared by all threads of the program.
Declaration
public static int GlobalMaxStateCount { set; }
Property Value
Type | Description |
---|---|
Int32 |
Remarks
This value can only be set because it is intended to be a program-level setting. For inspecting the value use the MaxStateCount.
IsEpsilonFree
Gets a value indicating whether this automaton is epsilon-free.
Declaration
public bool IsEpsilonFree { get; }
Property Value
Type | Description |
---|---|
Boolean |
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 |
LogValueOverride
Gets a value that, if not null, will be returned when computing the log value of any sequence which is in the support of this automaton (i.e. has non-zero value under the automaton).
Declaration
public double? LogValueOverride { get; }
Property Value
Type | Description |
---|---|
Nullable<Double> |
Remarks
This should only be non-null if the distribution this automaton represents is improper and there is a need to override the actual automaton value.
MaxDeadStateCount
Gets or sets the maximum number of "dead" states (states from which an end state cannot be reached) an automaton can have before the dead state removal procedure will be run.
Declaration
public static int MaxDeadStateCount { get; set; }
Property Value
Type | Description |
---|---|
Int32 |
MaxStateCount
Declaration
public static int MaxStateCount { get; }
Property Value
Type | Description |
---|---|
Int32 |
MaxStateCountBeforeSimplification
Gets or sets the maximum number of states an automaton can have before an attempt to simplify it will be made.
Declaration
public static int MaxStateCountBeforeSimplification { get; set; }
Property Value
Type | Description |
---|---|
Int32 |
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. |
PruneStatesWithLogEndWeightLessThan
Gets a value for truncating small weights. If non-null, any transition whose weight falls below this value in a normalized automaton will be removed following a product operation.
Declaration
public double? PruneStatesWithLogEndWeightLessThan { get; }
Property Value
Type | Description |
---|---|
Nullable<Double> |
Remarks
TODO: We need to develop more elegant automaton approximation methods, this is a simple placeholder for those.
SequenceManipulator
Gets the sequence manipulator.
Declaration
public static TSequenceManipulator SequenceManipulator { get; }
Property Value
Type | Description |
---|---|
TSequenceManipulator |
Start
Gets the start state of the automaton.
Declaration
public Automaton<TSequence, TElement, TElementDistribution, TSequenceManipulator, TThis>.State Start { get; }
Property Value
Type | Description |
---|---|
Automaton.State<> |
Remarks
Only a state from States can be specified as the value of this property.
States
Gets the collection of the states of the automaton.
Declaration
public Automaton<TSequence, TElement, TElementDistribution, TSequenceManipulator, TThis>.StateCollection States { get; }
Property Value
Type | Description |
---|---|
Automaton.StateCollection<> |
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
Determines whether this automaton has groups.
Declaration
public bool UsesGroups { get; }
Property Value
Type | Description |
---|---|
Boolean | True if it the automaton has groups, false otherwise. |
Methods
Append(TSequence, Int32)
Creates an automaton f'(st) = f(s)
, where f(s)
is the current automaton
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 automaton. |
Append(TThis, Int32)
Creates an automaton f'(s) = sum_{tu=s} f(t)g(u)
, where f(t)
is the current automaton
and g(u)
is the given automaton.
The resulting automaton is also known as the Cauchy product of two automata.
Declaration
public TThis Append(TThis automaton, int group = 0)
Parameters
Type | Name | Description |
---|---|---|
TThis | automaton | The automaton to append. |
Int32 | group | The group. |
Returns
Type | Description |
---|---|
TThis | The created automaton. |
ApplyFunction<TDstSequence, TDstElement, TDstElementDistribution, TDstSequenceManipulator, TDstAutomaton>(Func<Option<TElementDistribution>, Weight, Int32, (Option<TDstElementDistribution>, Weight)>)
Creates an automaton obtained by performing a transition transformation on the current automaton.
Declaration
public TDstAutomaton ApplyFunction<TDstSequence, TDstElement, TDstElementDistribution, TDstSequenceManipulator, TDstAutomaton>(Func<Option<TElementDistribution>, Weight, int, (Option<TDstElementDistribution>, Weight)> transitionTransform)
where TDstSequence : class, IEnumerable<TDstElement> where TDstElementDistribution : IImmutableDistribution<TDstElement, TDstElementDistribution>, CanGetLogAverageOf<TDstElementDistribution>, CanComputeProduct<TDstElementDistribution>, CanCreatePartialUniform<TDstElementDistribution>, SummableExactly<TDstElementDistribution>, new()
where TDstSequenceManipulator : ISequenceManipulator<TDstSequence, TDstElement>, new()
where TDstAutomaton : Automaton<TDstSequence, TDstElement, TDstElementDistribution, TDstSequenceManipulator, TDstAutomaton>, new()
Parameters
Type | Name | Description |
---|---|---|
Func<Option<TElementDistribution>, Weight, Int32, (T1, T2)<Option<TDstElementDistribution>, Weight>> | transitionTransform | The transition transformation. |
Returns
Type | Description |
---|---|
TDstAutomaton |
Type Parameters
Name | Description |
---|---|
TDstSequence | The type of a created automaton sequence. |
TDstElement | The type of a created automaton sequence element. |
TDstElementDistribution | The type of a distribution over created automaton sequence elements. |
TDstSequenceManipulator | The type providing ways to manipulate created automaton sequences. |
TDstAutomaton | The type of a created automaton. |
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 TThis AsAutomaton()
Returns
Type | Description |
---|---|
TThis |
Clone()
Creates a copy of the automaton.
Declaration
public TThis Clone()
Returns
Type | Description |
---|---|
TThis | The created copy. |
ComputeCondensation(Automaton<TSequence, TElement, TElementDistribution, TSequenceManipulator, TThis>.State)
Computes a condensation of the underlying automaton graph.
Declaration
public Automaton<TSequence, TElement, TElementDistribution, TSequenceManipulator, TThis>.Condensation ComputeCondensation(Automaton<TSequence, TElement, TElementDistribution, TSequenceManipulator, TThis>.State root)
Parameters
Type | Name | Description |
---|---|---|
Automaton.State<> | root | The root of the condensation. |
Returns
Type | Description |
---|---|
Automaton.Condensation<> | The computed condensation. |
ComputeCondensation(Automaton<TSequence, TElement, TElementDistribution, TSequenceManipulator, TThis>.State, Func<Automaton<TSequence, TElement, TElementDistribution, TSequenceManipulator, TThis>.Transition, Boolean>, Boolean)
Computes a condensation of the underlying automaton graph.
Declaration
public Automaton<TSequence, TElement, TElementDistribution, TSequenceManipulator, TThis>.Condensation ComputeCondensation(Automaton<TSequence, TElement, TElementDistribution, TSequenceManipulator, TThis>.State root, Func<Automaton<TSequence, TElement, TElementDistribution, TSequenceManipulator, TThis>.Transition, bool> transitionFilter, bool useApproximateClosure)
Parameters
Type | Name | Description |
---|---|---|
Automaton.State<> | root | The root of the condensation. |
Func<Automaton.Transition<>, Boolean> | transitionFilter | A function specifying whether the transition should be treated as an edge of the automaton graph while building the condensation. |
Boolean | useApproximateClosure | Specifies whether ApproximateClosure(Weight) should be used instead of Closure(Weight) in semiring computations. |
Returns
Type | Description |
---|---|
Automaton.Condensation<> | The computed condensation. |
Concatenate(TThis[])
Creates an automaton which is the concatenation of given automata.
Declaration
public static TThis Concatenate(params TThis[] automata)
Parameters
Type | Name | Description |
---|---|---|
TThis[] | automata | The automata to multiply. |
Returns
Type | Description |
---|---|
TThis | The created automaton. |
Concatenate(IEnumerable<TThis>)
Creates an automaton which is the concatenation of given automata.
Declaration
public static TThis Concatenate(IEnumerable<TThis> automata)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<TThis> | automata | The automata to multiply. |
Returns
Type | Description |
---|---|
TThis | The created automaton. |
Constant(Double)
Creates an automaton which maps every sequence to a given value.
Declaration
public static TThis Constant(double value)
Parameters
Type | Name | Description |
---|---|---|
Double | value | The value to map every sequence to. |
Returns
Type | Description |
---|---|
TThis | The created automaton. |
Constant(Double, TElementDistribution)
Creates an automaton which maps every allowed sequence to a given value and maps all other sequences to zero. A sequence is allowed if all its elements have non-zero probability under a given distribution.
Declaration
public static TThis Constant(double value, TElementDistribution allowedElements)
Parameters
Type | Name | Description |
---|---|---|
Double | value | The value to map every sequence to. |
TElementDistribution | allowedElements | The distribution representing allowed sequence elements. |
Returns
Type | Description |
---|---|
TThis | The created automaton. |
ConstantLog(Double)
Creates an automaton which maps every sequence to a given value.
Declaration
public static TThis ConstantLog(double logValue)
Parameters
Type | Name | Description |
---|---|---|
Double | logValue | The logarithm of the value to map every sequence to. |
Returns
Type | Description |
---|---|
TThis | The created automaton. |
ConstantLog(Double, TElementDistribution)
Creates an automaton which maps every allowed sequence to a given value and maps all other sequences to zero. A sequence is allowed if all its elements have non-zero probability under a given distribution.
Declaration
public static TThis ConstantLog(double logValue, TElementDistribution allowedElements)
Parameters
Type | Name | Description |
---|---|---|
Double | logValue | The logarithm of the value to map every sequence to. |
TElementDistribution | allowedElements | The distribution representing allowed sequence elements. |
Returns
Type | Description |
---|---|
TThis | The created automaton. |
ConstantOn(Double, TSequence)
Creates an automaton which has a given value on a given sequence and is zero everywhere else.
Declaration
public static TThis ConstantOn(double value, TSequence sequence)
Parameters
Type | Name | Description |
---|---|---|
Double | value | The value of the automaton on the given sequence. |
TSequence | sequence | The sequence. |
Returns
Type | Description |
---|---|
TThis | The created automaton. |
ConstantOn(Double, TSequence[])
Creates an automaton which has a given value on given sequences and is zero everywhere else.
Declaration
public static TThis ConstantOn(double value, params TSequence[] sequences)
Parameters
Type | Name | Description |
---|---|---|
Double | value | The value of the automaton on the given sequences. |
TSequence[] | sequences | The sequences. |
Returns
Type | Description |
---|---|
TThis | The created automaton. |
Remarks
If the same sequence is specified multiple times, the value of the created automaton on that sequence will be scaled by the number of the sequence occurrences.
ConstantOn(Double, IEnumerable<TSequence>)
Creates an automaton which has a given value on given sequences and is zero everywhere else.
Declaration
public static TThis ConstantOn(double value, IEnumerable<TSequence> sequences)
Parameters
Type | Name | Description |
---|---|---|
Double | value | The value of the automaton on the given sequences. |
IEnumerable<TSequence> | sequences | The sequences. |
Returns
Type | Description |
---|---|
TThis | The created automaton. |
Remarks
If the same sequence is specified multiple times, the value of the created automaton on that sequence will be scaled by the number of the sequence occurrences.
ConstantOnElement(Double, TElement)
Creates an automaton which has a given value on the sequence consisting of a given element only and is zero everywhere else.
Declaration
public static TThis ConstantOnElement(double value, TElement element)
Parameters
Type | Name | Description |
---|---|---|
Double | value | The value of the automaton on the sequence consisting of the given element only. |
TElement | element | The element. |
Returns
Type | Description |
---|---|
TThis | The created automaton. |
ConstantOnElement(Double, TElementDistribution)
Creates an automaton which has a given value on the sequence consisting of a single element from a set of allowed elements and is zero everywhere else. An element is allowed if it has non-zero probability under a given distribution.
Declaration
public static TThis ConstantOnElement(double value, TElementDistribution allowedElements)
Parameters
Type | Name | Description |
---|---|---|
Double | value | The value of the automaton on the sequence consisting of the given element only. |
TElementDistribution | allowedElements | The distribution representing allowed elements. |
Returns
Type | Description |
---|---|
TThis | The created automaton. |
ConstantOnElementLog(Double, TElement)
Creates an automaton which has a given value on the sequence consisting of a given element only and is zero everywhere else.
Declaration
public static TThis ConstantOnElementLog(double logValue, TElement element)
Parameters
Type | Name | Description |
---|---|---|
Double | logValue | The logarithm of the value of the automaton on the sequence consisting of the given element only. |
TElement | element | The element. |
Returns
Type | Description |
---|---|
TThis | The created automaton. |
ConstantOnElementLog(Double, TElementDistribution)
Creates an automaton which has a given value on the sequence consisting of a single element from a set of allowed elements and is zero everywhere else. An element is allowed if it has non-zero probability under a given distribution.
Declaration
public static TThis ConstantOnElementLog(double logValue, TElementDistribution allowedElements)
Parameters
Type | Name | Description |
---|---|---|
Double | logValue | The logarithm of the value of the automaton on the sequence consisting of the given element only. |
TElementDistribution | allowedElements | The distribution representing allowed elements. |
Returns
Type | Description |
---|---|
TThis | The created automaton. |
ConstantOnLog(Double, TSequence)
Creates an automaton which has a given value on a given sequence and is zero everywhere else.
Declaration
public static TThis ConstantOnLog(double logValue, TSequence sequence)
Parameters
Type | Name | Description |
---|---|---|
Double | logValue | The logarithm of the value of the automaton on the given sequence. |
TSequence | sequence | The sequence. |
Returns
Type | Description |
---|---|
TThis | The created automaton. |
ConstantOnLog(Double, TSequence[])
Creates an automaton which has a given value on given sequences and is zero everywhere else.
Declaration
public static TThis ConstantOnLog(double logValue, params TSequence[] sequences)
Parameters
Type | Name | Description |
---|---|---|
Double | logValue | The logarithm of the value of the automaton on the given sequences. |
TSequence[] | sequences | The sequences. |
Returns
Type | Description |
---|---|
TThis | The created automaton. |
Remarks
If the same sequence is specified multiple times, the value of the created automaton on that sequence will be scaled by the number of the sequence occurrences.
ConstantOnLog(Double, IEnumerable<TSequence>)
Creates an automaton which has a given value on given sequences and is zero everywhere else.
Declaration
public static TThis ConstantOnLog(double logValue, IEnumerable<TSequence> sequences)
Parameters
Type | Name | Description |
---|---|---|
Double | logValue | The logarithm of the value of the automaton on the given sequences. |
IEnumerable<TSequence> | sequences | The sequences. |
Returns
Type | Description |
---|---|
TThis | The created automaton. |
Remarks
If the same sequence is specified multiple times, the value of the created automaton on that sequence will be scaled by the number of the sequence occurrences.
ConstantOnSupport(Double)
Creates an automaton constant on the support of the current automaton.
Declaration
public TThis ConstantOnSupport(double value)
Parameters
Type | Name | Description |
---|---|---|
Double | value | The desired value on the support of the current automaton. |
Returns
Type | Description |
---|---|
TThis | Resulting automaton. |
Remarks
This function will fail if the current automaton cannot be determinized.
ConstantOnSupportLog(Double)
Creates an automaton constant on the support of the current automaton.
Declaration
public TThis ConstantOnSupportLog(double logValue)
Parameters
Type | Name | Description |
---|---|---|
Double | logValue | The logarithm of the desired value on the support of the current automaton. |
Returns
Type | Description |
---|---|
TThis | Resulting automaton. |
Exceptions
Type | Condition |
---|---|
NotImplementedException | Thrown if if the current automaton cannot be determinized. |
Empty(Double)
Creates an automaton which has a given value on the empty sequence and is zero everywhere else.
Declaration
public static TThis Empty(double value = 1)
Parameters
Type | Name | Description |
---|---|---|
Double | value | The value of the automaton on the empty sequence. |
Returns
Type | Description |
---|---|
TThis | The created automaton. |
EnumeratePaths()
Enumerates paths through this automaton.
Declaration
public IEnumerable<Tuple<List<TElementDistribution>, double>> EnumeratePaths()
Returns
Type | Description |
---|---|
IEnumerable<Tuple<List<TElementDistribution>, Double>> | The paths through this automaton, with their log weights |
EnumerateSupport(Int32)
Enumerates support of this automaton when possible. Element distributions must be either point mass or implement CanEnumerateSupport<T>.
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 automaton |
Exceptions
Type | Condition |
---|---|
AutomatonEnumerationCountException | Thrown if enumeration is too large. |
InvalidOperationException | Thrown if distribution on some transition is not enumerable. |
Equals(TThis)
Checks if other
is an automaton that defines the same weighted regular language.
Declaration
public bool Equals(TThis other)
Parameters
Type | Name | Description |
---|---|---|
TThis | other | The automaton to compare this automaton with. |
Returns
Type | Description |
---|---|
Boolean | true if this automaton is equal to |
Equals(Object)
Checks if obj
is an automaton that defines the same weighted regular language.
Declaration
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
Object | obj | The object to compare this automaton with. |
Returns
Type | Description |
---|---|
Boolean | true if this automaton is equal to |
Overrides
FromData(Automaton<TSequence, TElement, TElementDistribution, TSequenceManipulator, TThis>.DataContainer)
Creates an automaton from a given array of states and a start state. Used by quoting to embed automata in the generated inference code.
Declaration
[Construction(new string[]{"Data"})]
public static TThis FromData(Automaton<TSequence, TElement, TElementDistribution, TSequenceManipulator, TThis>.DataContainer data)
Parameters
Type | Name | Description |
---|---|---|
Automaton.DataContainer<> | data | Quoted automaton state. |
Returns
Type | Description |
---|---|
TThis | The created automaton. |
FromLogValues(IEnumerable<KeyValuePair<TSequence, Double>>)
Creates an automaton which has given values on given sequences and is zero everywhere else.
Declaration
public static TThis FromLogValues(IEnumerable<KeyValuePair<TSequence, double>> sequenceToLogValue)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<KeyValuePair<TSequence, Double>> | sequenceToLogValue | The collection of pairs of a sequence and the logarithm of the automaton value on that sequence. |
Returns
Type | Description |
---|---|
TThis | The created automaton. |
Remarks
If the same sequence is presented in the collection of pairs multiple times, the value of the automaton on that sequence will be equal to the sum of the values in the collection.
FromValues(IEnumerable<KeyValuePair<TSequence, Double>>)
Creates an automaton which has given values on given sequences and is zero everywhere else.
Declaration
public static TThis FromValues(IEnumerable<KeyValuePair<TSequence, double>> sequenceToValue)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<KeyValuePair<TSequence, Double>> | sequenceToValue | The collection of pairs of a sequence and the automaton value on that sequence. |
Returns
Type | Description |
---|---|
TThis | The created automaton. |
Remarks
If the same sequence is presented in the collection of pairs multiple times, the value of the automaton on that sequence will be equal to the sum of the values in the collection.
GetConverger(TThis, Double)
Gets an automaton such that every given automaton, if multiplied by it, becomes normalizable.
Declaration
public static TThis GetConverger(TThis automata, double decayWeight = 0.99)
Parameters
Type | Name | Description |
---|---|---|
TThis | automata | The automata. |
Double | decayWeight | The decay weight. |
Returns
Type | Description |
---|---|
TThis | An automaton, product with which will make every given automaton normalizable. |
GetConverger(TThis[], Double)
Gets an automaton such that every given automaton, if multiplied by it, becomes normalizable.
Declaration
public static TThis GetConverger(TThis[] automata, double decayWeight = 0.99)
Parameters
Type | Name | Description |
---|---|---|
TThis[] | automata | The automata. |
Double | decayWeight | The decay weight. |
Returns
Type | Description |
---|---|
TThis | An automaton, product with which will make every given automaton normalizable. |
GetEpsilonClosure()
Returns an epsilon closure of the current automaton.
Declaration
public TThis GetEpsilonClosure()
Returns
Type | Description |
---|---|
TThis |
Remarks
The resulting automaton will be equal to the current one, but have no epsilon transitions.
GetGroups()
Declaration
public Dictionary<int, TThis> GetGroups()
Returns
Type | Description |
---|---|
Dictionary<Int32, TThis> |
GetHashCode()
Gets the hash code of this automaton.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
Int32 | The hash code. |
Overrides
GetLogNormalizer()
Computes the logarithm of the normalizer (sum of values of the automaton on all sequences).
Declaration
public double GetLogNormalizer()
Returns
Type | Description |
---|---|
Double | The logarithm of the normalizer. |
Remarks
Returns PositiveInfinity if the sum diverges.
GetLogValue(TSequence)
Computes the logarithm of the value of the automaton 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. |
GetOutgoingTransitionsForDeterminization(Automaton<TSequence, TElement, TElementDistribution, TSequenceManipulator, TThis>.Determinization.WeightedStateSet)
Overridden in the derived classes to compute a set of outgoing transitions from a given state of the determinization result.
Declaration
protected abstract IEnumerable<Automaton<TSequence, TElement, TElementDistribution, TSequenceManipulator, TThis>.Determinization.OutgoingTransition> GetOutgoingTransitionsForDeterminization(Automaton<TSequence, TElement, TElementDistribution, TSequenceManipulator, TThis>.Determinization.WeightedStateSet sourceState)
Parameters
Type | Name | Description |
---|---|---|
Automaton.Determinization.WeightedStateSet<> | sourceState | The source state of the determinized automaton represented as a set of (stateId, weight) pairs, where state ids correspond to states of the original automaton. |
Returns
Type | Description |
---|---|
IEnumerable<Automaton.Determinization.OutgoingTransition<>> | A collection of (element distribution, weight, weighted state set) triples corresponding to outgoing transitions from |
GetValue(TSequence)
Computes the value of the automaton on a given sequence.
Declaration
public double GetValue(TSequence sequence)
Parameters
Type | Name | Description |
---|---|---|
TSequence | sequence | The sequence to compute the value on. |
Returns
Type | Description |
---|---|
Double | The computed value. |
HasGroup(Int32)
Determines whether this automaton has the specified group.
Declaration
public bool HasGroup(int group)
Parameters
Type | Name | Description |
---|---|---|
Int32 | group | The specified group. |
Returns
Type | Description |
---|---|
Boolean | True if it the automaton has this group, false otherwise. |
IsCanonicConstant()
Checks whether the automaton is a canonic representation of a constant, as produced by ConstantLog(Double).
Declaration
public bool IsCanonicConstant()
Returns
Type | Description |
---|---|
Boolean | true if the automaton is a canonic representation of the constant, false otherwise. |
Remarks
The time complexity of this function is O(1), so it can be used to treat constants specially in performance-critical code.
IsCanonicZero()
Checks whether the automaton is a canonic representation of zero, as produced by Zero().
Declaration
public bool IsCanonicZero()
Returns
Type | Description |
---|---|
Boolean | true if the automaton is a canonic representation of zero, false otherwise. |
Remarks
The time complexity of this function is O(1), so it can be used to treat zero specially in performance-critical code. All the operations on automata resulting in zero produce the canonic representation.
IsDeterministic()
Tests whether the automaton is deterministic, i.e. it's epsilon free and for every state and every element there is at most one transition that allows for that element.
Declaration
public bool IsDeterministic()
Returns
Type | Description |
---|---|
Boolean | true if the automaton is deterministic, false otherwise. |
IsZero()
Checks whether the automaton is zero on all sequences.
Declaration
public bool IsZero()
Returns
Type | Description |
---|---|
Boolean | true if the automaton is zero on all sequences, false otherwise. |
Remarks
The time complexity of this function is not constant, so it should not be used when treating zero specially for performance reasons. Use IsCanonicZero() instead.
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 |
NormalizeValues()
Normalizes the automaton so that the sum of its values over all possible sequences equals to one and returns the logarithm of the normalizer.
Declaration
public TThis NormalizeValues()
Returns
Type | Description |
---|---|
TThis | Will be set to the normalized automaton if the normalization was successful, or to the current automaton otherwise. |
Remarks
The only automaton which cannot be normalized, but has a finite normalizer, is zero.
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown if the automaton cannot be normalized (i.e. if the normalizer is zero or positive infinity). |
Product(TThis)
Computes the product of the current automaton and a given one.
Declaration
public TThis Product(TThis automaton)
Parameters
Type | Name | Description |
---|---|---|
TThis | automaton | The automaton to compute the product with. |
Returns
Type | Description |
---|---|
TThis | The computed product. |
Product(TThis, Boolean)
Computes the product of the current automaton and a given one.
Declaration
public TThis Product(TThis automaton, bool tryDeterminize)
Parameters
Type | Name | Description |
---|---|---|
TThis | automaton | The automaton to compute the product with. |
Boolean | tryDeterminize | Whether to try to determinize the result. |
Returns
Type | Description |
---|---|
TThis | The computed product. |
Product(TThis[])
Creates an automaton which is the product of given automata.
Declaration
public static TThis Product(params TThis[] automata)
Parameters
Type | Name | Description |
---|---|---|
TThis[] | automata | The automata to multiply. |
Returns
Type | Description |
---|---|
TThis | The created automaton. |
Product(IEnumerable<TThis>)
Creates an automaton which is the product of given automata.
Declaration
public static TThis Product(IEnumerable<TThis> automata)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<TThis> | automata | The automata to multiply. |
Returns
Type | Description |
---|---|
TThis | The created automaton. |
Read(Func<Double>, Func<Int32>, Func<TElementDistribution>)
Reads an automaton from.
Declaration
public static TThis Read(Func<double> readDouble, Func<int> readInt32, Func<TElementDistribution> readElementDistribution)
Parameters
Type | Name | Description |
---|---|---|
Func<Double> | readDouble | |
Func<Int32> | readInt32 | |
Func<TElementDistribution> | readElementDistribution |
Returns
Type | Description |
---|---|
TThis |
Remarks
Serialization format is a bit unnatural, but we do it for compatibility with old serialized data. So we don't have to maintain 2 versions of deserialization.
RemoveDeadStates()
Optimizes the automaton by removing all states which can't reach end states.
Declaration
public TThis RemoveDeadStates()
Returns
Type | Description |
---|---|
TThis | Result automaton. Simplified automaton, if there were states to be removed, current automaton otherwise. |
Repeat(TThis, Vector)
Creates an automaton g(s) = sum_k v(k) sum_{t1 t2 ... tk = s} f(t1)f(t2)...f(tk)
,
where f(t)
is the given automaton, and v(k)
is a weight function given as a vector.
Declaration
public static TThis Repeat(TThis automaton, Vector repetitionNumberWeights)
Parameters
Type | Name | Description |
---|---|---|
TThis | automaton | The automaton. |
Vector | repetitionNumberWeights | The weight vector. |
Returns
Type | Description |
---|---|
TThis | The created automaton. |
Remarks
The result is a weighted sum of Cauchy products of the given automaton with itself, each product having a different number of factors.
Repeat(TThis, Int32, Nullable<Int32>)
Creates an automaton g(s) = sum_{k=Kmin}^{Kmax} sum_{t1 t2 ... tk = s} f(t1)f(t2)...f(tk)
,
where f(t)
is the given automaton, and Kmin
and Kmax
are the minimum
and the maximum number of factors in a sum term.
Declaration
public static TThis Repeat(TThis automaton, int minTimes = 1, int? maxTimes = null)
Parameters
Type | Name | Description |
---|---|---|
TThis | automaton | The automaton. |
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 automaton. |
Remarks
The result is the sum of Cauchy products of the given automaton with itself, each product having a different number of factors.
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. |
Reverse()
Creates an automaton f'(s) = f(reverse(s))
,
where reverse
is a sequence reverse function.
Declaration
public TThis Reverse()
Returns
Type | Description |
---|---|
TThis | The created automaton. |
Scale(Double)
Scales the automaton and returns the result.
Declaration
public TThis Scale(double scale)
Parameters
Type | Name | Description |
---|---|---|
Double | scale | The scale. |
Returns
Type | Description |
---|---|
TThis | The scaled automaton. |
ScaleLog(Double)
Scales the automaton 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 automaton. |
Simplify(out TThis)
Attempts to simplify the structure of the automaton, reducing the number of states and transitions.
Declaration
public bool Simplify(out TThis result)
Parameters
Type | Name | Description |
---|---|---|
TThis | result | Result automaton. Simplified automaton, if the operation was successful, current automaton otherwise. |
Returns
Type | Description |
---|---|
Boolean | true if the simplification was successful, false otherwise. |
Sum(TThis)
Computes the sum of the current automaton and a given automaton.
Declaration
public TThis Sum(TThis automaton)
Parameters
Type | Name | Description |
---|---|---|
TThis | automaton | The automaton to compute the sum with. |
Returns
Type | Description |
---|---|
TThis | The computed sum. |
Sum(TThis[])
Creates an automaton which is a sum of given automata.
Declaration
public static TThis Sum(params TThis[] automata)
Parameters
Type | Name | Description |
---|---|---|
TThis[] | automata | The automata to sum. |
Returns
Type | Description |
---|---|
TThis | The created automaton. |
Sum(IEnumerable<TThis>)
Creates an automaton which is a sum of given automata.
Declaration
public static TThis Sum(IEnumerable<TThis> automata)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<TThis> | automata | The automata to sum. |
Returns
Type | Description |
---|---|
TThis | The created automaton. |
Sum(Double, TThis, Double)
Computes the weighted sum of the current automaton and a given automaton.
Declaration
public TThis Sum(double weightThis, TThis other, double weightOther)
Parameters
Type | Name | Description |
---|---|---|
Double | weightThis | The weight of the current automaton. |
TThis | other | The given automaton. |
Double | weightOther | The weight of |
Returns
Type | Description |
---|---|
TThis |
SumLog(Double, TThis, Double)
Computes the weighted sum of the current automaton and a given automaton.
Declaration
public TThis SumLog(double logWeightThis, TThis other, double logWeightOther)
Parameters
Type | Name | Description |
---|---|---|
Double | logWeightThis | The logarithm of the weight of the current automaton. |
TThis | other | The given automaton. |
Double | logWeightOther | The logarithm of the weight of |
Returns
Type | Description |
---|---|
TThis |
ToString()
Returns a string that represents the automaton.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String | A string that represents the automaton. |
Overrides
ToString(IAutomatonFormat)
Returns a string that represents the automaton.
Declaration
public string ToString(IAutomatonFormat format)
Parameters
Type | Name | Description |
---|---|---|
IAutomatonFormat | format | The format. |
Returns
Type | Description |
---|---|
String | A string that represents the automaton. |
ToString(Action<TElementDistribution, StringBuilder>)
Returns a string that represents the automaton.
Declaration
public string ToString(Action<TElementDistribution, StringBuilder> appendElement)
Parameters
Type | Name | Description |
---|---|---|
Action<TElementDistribution, StringBuilder> | appendElement | Optional method for appending at the element distribution level. |
Returns
Type | Description |
---|---|
String | A string that represents the automaton. |
TryComputePoint()
Attempts to find the only sequence which has non-zero value under the automaton.
Declaration
public TSequence TryComputePoint()
Returns
Type | Description |
---|---|
TSequence | The only sequence having non-zero value, if found. null, if the automaton is zero everywhere or is non-zero on more than one sequence. |
Remarks
Recursive implementation would be simpler but prone to stack overflows with large automata
TryDeterminize()
Attempts to determinize the automaton, i.e. modify it such that for every state and every element there is at most one transition that allows for that element, and there are no epsilon transitions.
Declaration
public TThis TryDeterminize()
Returns
Type | Description |
---|---|
TThis | Result automaton. Determinized automaton, if the operation was successful, current automaton or an equvalent automaton without epsilon transitions otherwise. |
Remarks
TryDeterminize(out TThis)
Attempts to determinize the automaton, i.e. modify it such that for every state and every element there is at most one transition that allows for that element, and there are no epsilon transitions.
Declaration
public bool TryDeterminize(out TThis result)
Parameters
Type | Name | Description |
---|---|---|
TThis | result | Result automaton. Determinized automaton, if the operation was successful, current automaton or an equvalent automaton without epsilon transitions otherwise. |
Returns
Type | Description |
---|---|
Boolean | true if the determinization attempt was successful and the automaton is now deterministic, false otherwise. |
Remarks
TryEnumerateSupport(Int32, out IEnumerable<TSequence>)
Tries to enumerate support of this automaton. Element distributions must be either point mass or implement CanEnumerateSupport<T>.
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 automaton |
Returns
Type | Description |
---|---|
Boolean | True if successful, false otherwise |
TryEnumerateSupport(Int32, out IEnumerable<TSequence>, Int32, Boolean)
Tries to enumerate support of this automaton. Element distributions must be either point mass or implement CanEnumerateSupport<T>.
Declaration
public bool TryEnumerateSupport(int maxCount, out IEnumerable<TSequence> result, int maxTraversedPaths, bool stopOnNonPointMassElementDistribution)
Parameters
Type | Name | Description |
---|---|---|
Int32 | maxCount | The maximum support enumeration count. |
IEnumerable<TSequence> | result | The sequences in the support of this automaton |
Int32 | maxTraversedPaths | Maximum number of paths in the automaton this function is allowed to traverse before stopping. Can be used to limit the performance impact of this call in cases when the support is useful only if it can be obtained quickly. |
Boolean | stopOnNonPointMassElementDistribution | When set to true, the enumeration is canceled upon encountering a non-point mass element distribution on a transition. |
Returns
Type | Description |
---|---|
Boolean | True if successful, false otherwise |
TryGetConstantOnSupportLog(Double, out TThis)
Tries to create an automaton constant on the support of the current automaton.
Declaration
public bool TryGetConstantOnSupportLog(double logValue, out TThis automaton)
Parameters
Type | Name | Description |
---|---|---|
Double | logValue | The logarithm of the desired value on the support of |
TThis | automaton | The resulting automaton. |
Returns
Type | Description |
---|---|
Boolean | True if successful, false otherwise. |
Remarks
This function will return false if the current automaton cannot be determinized.
TryNormalizeValues(out TThis)
Attempts to normalize the automaton so that sum of its values on all possible sequences equals to one (if it is possible).
Declaration
public bool TryNormalizeValues(out TThis result)
Parameters
Type | Name | Description |
---|---|---|
TThis | result | Will be set to the normalized automaton if the normalization was successful, or to the current automaton otherwise. |
Returns
Type | Description |
---|---|
Boolean | true if the automaton was successfully normalized, false otherwise. |
TryNormalizeValues(out TThis, out Double)
Attempts to normalize the automaton 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, produces 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 bool TryNormalizeValues(out TThis normalizedAutomaton, out double logNormalizer)
Parameters
Type | Name | Description |
---|---|---|
TThis | normalizedAutomaton | Will be set to the normalized automaton if the normalization was successful, or to the current automaton otherwise. |
Double | logNormalizer | When the function returns, contains the logarithm of the normalizer. |
Returns
Type | Description |
---|---|
Boolean | true if the normalization was successful, false otherwise. |
WeightedSum(Double, TThis, Double, TThis)
Creates an automaton which is a weighted sum of a given pair of automata.
Declaration
public static TThis WeightedSum(double weight1, TThis automaton1, double weight2, TThis automaton2)
Parameters
Type | Name | Description |
---|---|---|
Double | weight1 | The weight of the first automaton. |
TThis | automaton1 | The first automaton. |
Double | weight2 | The weight of the second automaton. |
TThis | automaton2 | The second automaton. |
Returns
Type | Description |
---|---|
TThis | The created automaton. |
WeightedSumLog(Double, TThis, Double, TThis)
Creates an automaton which is a weighted sum of a given pair of automata.
Declaration
public static TThis WeightedSumLog(double logWeight1, TThis automaton1, double logWeight2, TThis automaton2)
Parameters
Type | Name | Description |
---|---|---|
Double | logWeight1 | The logarithm of the weight of the first automaton. |
TThis | automaton1 | The first automaton. |
Double | logWeight2 | The logarithm of the weight of the second automaton. |
TThis | automaton2 | The second automaton. |
Returns
Type | Description |
---|---|
TThis | The created automaton. |
WithData(Automaton<TSequence, TElement, TElementDistribution, TSequenceManipulator, TThis>.DataContainer)
Declaration
protected TThis WithData(Automaton<TSequence, TElement, TElementDistribution, TSequenceManipulator, TThis>.DataContainer data)
Parameters
Type | Name | Description |
---|---|---|
Automaton.DataContainer<> | data |
Returns
Type | Description |
---|---|
TThis |
WithGroup(Int32)
Creates a copy of the current automaton with all transitions set to have the specified group.
Declaration
public TThis WithGroup(int group)
Parameters
Type | Name | Description |
---|---|---|
Int32 | group | The specified group. |
Returns
Type | Description |
---|---|
TThis |
WithGroupsClear()
Creates a copy of the current automaton with the group for all transitions cleared.
Declaration
public TThis WithGroupsClear()
Returns
Type | Description |
---|---|
TThis |
WithLogValueOverride(Nullable<Double>)
Creates a copy of the current automaton with a different value of LogValueOverride.
Declaration
public TThis WithLogValueOverride(double? logValueOverride)
Parameters
Type | Name | Description |
---|---|---|
Nullable<Double> | logValueOverride | New LogValueOverride. |
Returns
Type | Description |
---|---|
TThis | The created automaton. |
WithPruneStatesWithLogEndWeightLessThan(Nullable<Double>)
Creates a copy of the current automaton with a different value of PruneStatesWithLogEndWeightLessThan.
Declaration
public TThis WithPruneStatesWithLogEndWeightLessThan(double? pruneStatesWithLogEndWeightLessThan)
Parameters
Type | Name | Description |
---|---|---|
Nullable<Double> | pruneStatesWithLogEndWeightLessThan |
Returns
Type | Description |
---|---|
TThis | The created automaton. |
Write(Action<Double>, Action<Int32>, Action<TElementDistribution>)
Writes the current automaton.
Declaration
public void Write(Action<double> writeDouble, Action<int> writeInt32, Action<TElementDistribution> writeElementDistribution)
Parameters
Type | Name | Description |
---|---|---|
Action<Double> | writeDouble | |
Action<Int32> | writeInt32 | |
Action<TElementDistribution> | writeElementDistribution |
Remarks
Serialization format is a bit unnatural, but we do it for compatibility with old serialized data. So we don't have to maintain 2 versions of deserialization.
Zero()
Creates an automaton which maps every sequence to zero.
Declaration
public static TThis Zero()
Returns
Type | Description |
---|---|
TThis | The created automaton. |