Class TransducerBase<TSrcSequence, TSrcElement, TSrcElementDistribution, TSrcSequenceManipulator, TSrcAutomaton, TDestSequence, TDestElement, TDestElementDistribution, TDestSequenceManipulator, TDestAutomaton, TPairDistribution, TThis>
A base class for weighted finite state transducers.
Inheritance
Inherited Members
Namespace: Microsoft.ML.Probabilistic.Distributions.Automata
Assembly: Microsoft.ML.Probabilistic.dll
Syntax
public abstract class TransducerBase<TSrcSequence, TSrcElement, TSrcElementDistribution, TSrcSequenceManipulator, TSrcAutomaton, TDestSequence, TDestElement, TDestElementDistribution, TDestSequenceManipulator, TDestAutomaton, TPairDistribution, TThis>
where TSrcSequence : class, IEnumerable<TSrcElement> where TSrcElementDistribution : IImmutableDistribution<TSrcElement, TSrcElementDistribution>, CanGetLogAverageOf<TSrcElementDistribution>, CanComputeProduct<TSrcElementDistribution>, CanCreatePartialUniform<TSrcElementDistribution>, SummableExactly<TSrcElementDistribution>, Sampleable<TSrcElement>, new()
where TSrcSequenceManipulator : ISequenceManipulator<TSrcSequence, TSrcElement>, new()
where TSrcAutomaton : Automaton<TSrcSequence, TSrcElement, TSrcElementDistribution, TSrcSequenceManipulator, TSrcAutomaton>, new()
where TDestSequence : class, IEnumerable<TDestElement> where TDestElementDistribution : IImmutableDistribution<TDestElement, TDestElementDistribution>, CanGetLogAverageOf<TDestElementDistribution>, CanComputeProduct<TDestElementDistribution>, CanCreatePartialUniform<TDestElementDistribution>, SummableExactly<TDestElementDistribution>, Sampleable<TDestElement>, new()
where TDestSequenceManipulator : ISequenceManipulator<TDestSequence, TDestElement>, new()
where TDestAutomaton : Automaton<TDestSequence, TDestElement, TDestElementDistribution, TDestSequenceManipulator, TDestAutomaton>, new()
where TPairDistribution : ImmutablePairDistributionBase<TSrcElement, TSrcElementDistribution, TDestElement, TDestElementDistribution, TPairDistribution>, new()
where TThis : TransducerBase<TSrcSequence, TSrcElement, TSrcElementDistribution, TSrcSequenceManipulator, TSrcAutomaton, TDestSequence, TDestElement, TDestElementDistribution, TDestSequenceManipulator, TDestAutomaton, TPairDistribution, TThis>, new()
Type Parameters
Name | Description |
---|---|
TSrcSequence | The type of the first sequence in a pair. |
TSrcElement | The type of an element of |
TSrcElementDistribution | The type of a distribution over |
TSrcSequenceManipulator | The type providing ways to manipulate sequences of type |
TSrcAutomaton | The type of an automaton defined on |
TDestSequence | The type of the second sequence in a pair. |
TDestElement | The type of an element of |
TDestElementDistribution | The type of a distribution over |
TDestSequenceManipulator | The type providing ways to manipulate sequences of type |
TDestAutomaton | The type of an automaton defined on |
TPairDistribution | The type of a distribution over pairs of |
TThis | The type of a concrete transducer class. |
Fields
sequencePairToWeight
An automaton defined on sequences of element pairs that represents the transducer.
Declaration
protected TransducerBase<TSrcSequence, TSrcElement, TSrcElementDistribution, TSrcSequenceManipulator, TSrcAutomaton, TDestSequence, TDestElement, TDestElementDistribution, TDestSequenceManipulator, TDestAutomaton, TPairDistribution, TThis>.PairListAutomaton sequencePairToWeight
Field Value
Type | Description |
---|---|
TransducerBase.PairListAutomaton<> |
Methods
Append(TThis)
Creates a transducer T'(a, b) = sum_{a1 a2 = a, b1 b2 = b} T(a1, b1) U(a2, b2)
,
where T(a1, b1)
is the current transducer and U(a2, b2)
is a given transducer.
The resulting transducer is also known as the Cauchy product of two transducers.
Declaration
public TThis Append(TThis transducer)
Parameters
Type | Name | Description |
---|---|---|
TThis | transducer | The transducer to append. |
Returns
Type | Description |
---|---|
TThis | The created transducer. |
AppendInPlace(TThis, Int32)
Replaces the current transducer with a transducer T'(a, b) = sum_{a1 a2 = a, b1 b2 = b} T(a1, b1) U(a2, b2)
,
where T(a1, b1)
is the current transducer and U(a2, b2)
is a given transducer.
The resulting transducer is also known as the Cauchy product of two transducers.
Declaration
public void AppendInPlace(TThis transducer, int group = 0)
Parameters
Type | Name | Description |
---|---|---|
TThis | transducer | The transducer to append. |
Int32 | group | The group. |
Clone()
Creates a copy of this transducer.
Declaration
public TThis Clone()
Returns
Type | Description |
---|---|
TThis | The created copy. |
Concatenate(TThis[])
Creates an automaton which is the concatenation of given transducers.
Declaration
public static TThis Concatenate(params TThis[] transducers)
Parameters
Type | Name | Description |
---|---|---|
TThis[] | transducers | The transducers to concatenate. |
Returns
Type | Description |
---|---|
TThis | The created transucer. |
Concatenate(IEnumerable<TThis>)
Creates an automaton which is the concatenation of given transducers.
Declaration
public static TThis Concatenate(IEnumerable<TThis> transducers)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<TThis> | transducers | The transducers to concatenate. |
Returns
Type | Description |
---|---|
TThis | The created transucer. |
Consume(TSrcSequence)
Creates a transducer T(a, b) = I[a = A] I[b = ""]
, where A
is a given sequence.
Declaration
public static TThis Consume(TSrcSequence srcSequence)
Parameters
Type | Name | Description |
---|---|---|
TSrcSequence | srcSequence | The sequence to constrain the first transducer argument to. |
Returns
Type | Description |
---|---|
TThis | The created transducer. |
Consume(TSrcAutomaton)
Creates a transducer T(a, b) = f(a) I[b = ""]
, where f(a)
is a given automaton.
Declaration
public static TThis Consume(TSrcAutomaton srcAutomaton)
Parameters
Type | Name | Description |
---|---|---|
TSrcAutomaton | srcAutomaton | The automaton defining weights for the first transducer argument. |
Returns
Type | Description |
---|---|
TThis | The created transducer. |
ConsumeElement(TSrcElement)
Creates a transducer T(a, b) = I[a[0] = c, |a| = 1] I[b = ""]
, where c
is a given element.
Declaration
public static TThis ConsumeElement(TSrcElement srcElement)
Parameters
Type | Name | Description |
---|---|---|
TSrcElement | srcElement | The element to constrain the first transducer argument to. |
Returns
Type | Description |
---|---|
TThis | The created transducer. |
GetLogValue(TSrcSequence, TDestSequence)
Gets the logarithm of the transducer value on a given pair of sequences.
Declaration
public double GetLogValue(TSrcSequence sequence1, TDestSequence sequence2)
Parameters
Type | Name | Description |
---|---|---|
TSrcSequence | sequence1 | The first sequence. |
TDestSequence | sequence2 | The second sequence. |
Returns
Type | Description |
---|---|
Double | The logarithm of the transducer value on the given pair of sequences. |
GetValue(TSrcSequence, TDestSequence)
Gets the transducer value on a given pair of sequences.
Declaration
public double GetValue(TSrcSequence sequence1, TDestSequence sequence2)
Parameters
Type | Name | Description |
---|---|---|
TSrcSequence | sequence1 | The first sequence. |
TDestSequence | sequence2 | The second sequence. |
Returns
Type | Description |
---|---|
Double | The transducer value on the given pair of sequences. |
Optional(TThis)
Creates a transducer T'(a, b) = T(a, b) + I[a = "", b = ""]
, where T(a, b)
is a given transducer.
Declaration
public static TThis Optional(TThis transducer)
Parameters
Type | Name | Description |
---|---|---|
TThis | transducer | The transducer |
Returns
Type | Description |
---|---|
TThis | The created transducer. |
Produce(TDestSequence)
Creates a transducer T(a, b) = I[a = ""] I[b = B]
, where B
is a given sequence.
Declaration
public static TThis Produce(TDestSequence destSequence)
Parameters
Type | Name | Description |
---|---|---|
TDestSequence | destSequence | The sequence to constrain the second transducer argument to. |
Returns
Type | Description |
---|---|
TThis | The created transducer. |
Produce(TDestAutomaton)
Creates a transducer T(a, b) = g(b) I[a = ""]
, where g(b)
is a given automaton.
Declaration
public static TThis Produce(TDestAutomaton destAutomaton)
Parameters
Type | Name | Description |
---|---|---|
TDestAutomaton | destAutomaton | The automaton defining weights for the second transducer argument. |
Returns
Type | Description |
---|---|
TThis | The created transducer. |
ProduceElement(TDestElement)
Creates a transducer T(a, b) = I[a = ""] I[b[0] = c, |b| = 1]
, where c
is a given element.
Declaration
public static TThis ProduceElement(TDestElement destElement)
Parameters
Type | Name | Description |
---|---|---|
TDestElement | destElement | The element to constrain the second transducer argument to. |
Returns
Type | Description |
---|---|
TThis | The created transducer. |
ProduceElement(TDestElementDistribution)
Creates a transducer T(a, b) = I[a = ""] I[b[0] in c, |b| = 1]
, where c
is a given element distribution.
Declaration
public static TThis ProduceElement(TDestElementDistribution destElementDist)
Parameters
Type | Name | Description |
---|---|---|
TDestElementDistribution | destElementDist | The element distribution to constrain the second transducer argument to. |
Returns
Type | Description |
---|---|
TThis | The created transducer. |
ProjectSource(TSrcSequence)
Computes g(b) = f(A) T(A, b)
, where T(a, b)
is the current transducer and A
is a given sequence.
Declaration
public TDestAutomaton ProjectSource(TSrcSequence srcSequence)
Parameters
Type | Name | Description |
---|---|---|
TSrcSequence | srcSequence | The sequence to project. |
Returns
Type | Description |
---|---|
TDestAutomaton | The projection. |
Remarks
Using this method is more efficient than applying ProjectSource(TSrcAutomaton) to the automaton representation of a projected sequence.
ProjectSource(TSrcAutomaton)
Computes g(b) = sum_a f(a) T(a, b)
, where T(a, b)
is the current transducer and f(a)
is a given automaton.
Declaration
public TDestAutomaton ProjectSource(TSrcAutomaton srcAutomaton)
Parameters
Type | Name | Description |
---|---|---|
TSrcAutomaton | srcAutomaton | The automaton to project. |
Returns
Type | Description |
---|---|
TDestAutomaton | The projection. |
Remarks
The code of this method has a lot in common with the code of Automaton.SetToProduct. Unfortunately, it's not clear how to avoid the duplication in the current design.
Repeat(TThis, Int32, Nullable<Int32>)
Creates a transducer T'(a, b) = sum_{k=Kmin}^{Kmax} sum_{a1 a2 ... ak = a} sum_{b1 b2 ... bk = b} T(a1, b1)T(a2, b2)...T(ak, bk)
,
where T(a, b)
is a given transducer, and Kmin
and Kmax
are the minimum
and the maximum number of factors in a sum term.
Declaration
public static TThis Repeat(TThis transducer, int minTimes = 1, int? maxTimes = null)
Parameters
Type | Name | Description |
---|---|---|
TThis | transducer | The transducer. |
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 transducer. |
Remarks
The result is the sum of Cauchy products of the given transducer with itself, each product having a different number of factors.
Replace(TSrcSequence, TDestSequence)
Creates a transducer T(a, b) = I[a = A] I[b = B]
, where A
and B
are given sequences.
Declaration
public static TThis Replace(TSrcSequence srcSequence, TDestSequence destSequence)
Parameters
Type | Name | Description |
---|---|---|
TSrcSequence | srcSequence | The sequence to constrain the first transducer argument to. |
TDestSequence | destSequence | The sequence to constrain the second transducer argument to. |
Returns
Type | Description |
---|---|
TThis | The created transducer. |
Replace(TSrcElementDistribution, TDestElementDistribution)
Creates a transducer T(a, b) = I[a[i] is in X for all i] I[b[j] is in Y for all j]
, where X
and Y
are the supports of given element distributions.
Declaration
public static TThis Replace(TSrcElementDistribution allowedSrcElements, TDestElementDistribution allowedDestElements)
Parameters
Type | Name | Description |
---|---|---|
TSrcElementDistribution | allowedSrcElements | Specifies the elements allowed in the first transducer argument. |
TDestElementDistribution | allowedDestElements | Specifies the elements allowed in the second transducer argument. |
Returns
Type | Description |
---|---|
TThis | The created transducer. |
Replace(TSrcAutomaton, TDestAutomaton)
Creates a transducer T(a, b) = f(a) g(b)
, where f(a)
and g(b)
are given automata.
Declaration
public static TThis Replace(TSrcAutomaton srcAutomaton, TDestAutomaton destAutomaton)
Parameters
Type | Name | Description |
---|---|---|
TSrcAutomaton | srcAutomaton | The automaton defining weights for the first transducer argument. |
TDestAutomaton | destAutomaton | The automaton defining weights for the second transducer argument. |
Returns
Type | Description |
---|---|
TThis | The created transducer. |
SetTo(TThis)
Replaces this transducer with a copy of a given transducer.
Declaration
public void SetTo(TThis otherTransducer)
Parameters
Type | Name | Description |
---|---|---|
TThis | otherTransducer | The transducer to replace this transducer with. |
Sum(TThis[])
Creates a transducer T(a, b) = sum_i Ti(a, b)
, where Ti(a, b)
is an element of a given transducer collection.
Declaration
public static TThis Sum(params TThis[] transducers)
Parameters
Type | Name | Description |
---|---|---|
TThis[] | transducers | The transducers to sum. |
Returns
Type | Description |
---|---|
TThis | The created transducer. |
Sum(IEnumerable<TThis>)
Creates a transducer T(a, b) = sum_i Ti(a, b)
, where Ti(a, b)
is an element of a given transducer collection.
Declaration
public static TThis Sum(IEnumerable<TThis> transducers)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<TThis> | transducers | The transducers to sum. |
Returns
Type | Description |
---|---|
TThis | The created transducer. |