/// <summary> /// Adds a series of transitions labeled with the elements of a given sequence to the current state, /// as well as the intermediate states. All the added transitions have unit weight. /// </summary> /// <param name="sequence">The sequence.</param> /// <param name="destinationState"> /// The last state in the transition series. /// If the value of this parameter is <see langword="null"/>, a new state will be created. /// </param> /// <param name="group">The group of the added transitions.</param> /// <returns>The last state in the added transition series.</returns> public State AddTransitionsForSequence(TSequence sequence, State destinationState = null, byte group = 0) { State currentState = this; IEnumerator <TElement> enumerator = sequence.GetEnumerator(); bool moveNext = enumerator.MoveNext(); while (moveNext) { TElement element = enumerator.Current; moveNext = enumerator.MoveNext(); currentState = currentState.AddTransition(element, Weight.One, moveNext ? null : destinationState, group); } return(currentState); }
/// <summary> /// parse the definition of a database sequence /// </summary> /// <param name="cur2">the current node</param> /// <returns></returns> protected TSequence ParseSequence(XmlNode cur2) { TSequence element; element = new TSequence(); element.strName = GetAttribute(cur2, "name"); element.strDescription = GetAttribute(cur2, "descr"); element.strArea = GetAttribute(cur2, "area"); element.bCycleOnLimit = GetAttribute(cur2, "cycleonlimit") == "yes"; element.iInitial = GetIntAttribute(cur2, "initial"); element.iMinVal = GetIntAttribute(cur2, "minval"); element.iMaxVal = GetIntAttribute(cur2, "maxval"); element.iIncrement = GetIntAttribute(cur2, "increment"); return(element); }
private static Boolean WriteSequence(StreamWriter ASw, TSequence ASequence) { ASw.WriteLine("CREATE SEQUENCE \"{0}\"", ASequence.strName); ASw.WriteLine(" INCREMENT BY {0}", ASequence.iIncrement.ToString()); ASw.WriteLine(" MINVALUE {0}", ASequence.iMinVal.ToString()); ASw.WriteLine(" MAXVALUE {0}", ASequence.iMaxVal.ToString()); ASw.Write(" START WITH {0}", ASequence.iInitial.ToString()); if (ASequence.bCycleOnLimit) { ASw.WriteLine(); ASw.Write(" CYCLE"); } ASw.WriteLine(";"); return(true); }
/// <summary> /// Adds a series of transitions labeled with the elements of a given sequence to the current state, /// as well as the intermediate states. All the added transitions have unit weight. /// </summary> /// <param name="sequence">The sequence.</param> /// <param name="destinationState"> /// The last state in the transition series. /// If the value of this parameter is <see langword="null"/>, a new state will be created. /// </param> /// <param name="group">The group of the added transitions.</param> /// <returns>The last state in the added transition series.</returns> public State AddTransitionsForSequence(TSequence sequence, State destinationState = default(State), int group = 0) { var currentState = this; using (var enumerator = sequence.GetEnumerator()) { var moveNext = enumerator.MoveNext(); while (moveNext) { var element = enumerator.Current; moveNext = enumerator.MoveNext(); currentState = currentState.AddTransition( element, Weight.One, moveNext ? default(State) : destinationState, group); } } return(currentState); }
public MultiRepresentationWeightFunction <TDictionary> Append(TSequence sequence, int group = 0) { switch (weightFunction) { case null: return(Zero()); case PointMassWeightFunction pointMass: return(group == 0 ? FromPointMass(pointMass.Append(sequence)) : FromAutomaton(pointMass.AsAutomaton().Append(sequence, group))); case TDictionary dictionary: return(group == 0 ? FromDictionary(dictionary.Append(sequence)) : FromAutomaton(dictionary.AsAutomaton().Append(sequence, group))); case TAutomaton automaton: return(FromAutomaton(automaton.Append(sequence, group))); default: throw new InvalidOperationException("Current function has an invalid type"); } }
/// <summary> /// Adds a series of transitions labeled with the elements of a given sequence to the current state, /// as well as the intermediate states. All the added transitions have unit weight. /// </summary> /// <param name="sequence">The sequence.</param> /// <param name="destinationStateIndex"> /// The last state in the transition series. /// If the value of this parameter is <see langword="null"/>, a new state will be created. /// </param> /// <param name="group">The group of the added transitions.</param> /// <returns>The last state in the added transition series.</returns> public StateBuilder AddTransitionsForSequence( TSequence sequence, int?destinationStateIndex = null, int group = 0) { var currentState = this; using (var enumerator = sequence.GetEnumerator()) { var moveNext = enumerator.MoveNext(); while (moveNext) { var element = enumerator.Current; moveNext = enumerator.MoveNext(); currentState = currentState.AddTransition( element, Weight.One, moveNext ? null : destinationStateIndex, group); } } return(currentState); }
/// <summary> /// Computes the logarithm of the value of the automaton /// having this state as the start state on a given sequence. /// </summary> /// <param name="sequence">The sequence.</param> /// <returns>The logarithm of the value on the sequence.</returns> public double GetLogValue(TSequence sequence) { var valueCache = new Dictionary <IntPair, Weight>(IntPair.DefaultEqualityComparer); return(this.DoGetValue(sequence, 0, valueCache).LogValue); }
public static PointMassWeightFunction FromPoint(TSequence point) => new PointMassWeightFunction() { Point = point };
/// <summary> /// Recursively computes the value of the automaton on a given sequence. /// </summary> /// <param name="sequence">The sequence to compute the value on.</param> /// <param name="sequencePosition">The current position in the sequence.</param> /// <param name="valueCache">A lookup table for memoization.</param> /// <returns>The value computed from the current state.</returns> private Weight DoGetValue( TSequence sequence, int sequencePosition, Dictionary <(int, int), Weight> valueCache)
/// <summary> /// Computes the logarithm of the value of the automaton /// having this state as the start state on a given sequence. /// </summary> /// <param name="sequence">The sequence.</param> /// <returns>The logarithm of the value on the sequence.</returns> public double GetLogValue(TSequence sequence) { var valueCache = new Dictionary <(int, int), Weight>(); return(this.DoGetValue(sequence, 0, valueCache).LogValue); }
private static Boolean WriteSequence(StreamWriter ASw, TSequence ASequence) { ASw.WriteLine("CREATE SEQUENCE \"{0}\"", ASequence.strName); ASw.WriteLine(" INCREMENT BY {0}", ASequence.iIncrement.ToString()); ASw.WriteLine(" MINVALUE {0}", ASequence.iMinVal.ToString()); ASw.WriteLine(" MAXVALUE {0}", ASequence.iMaxVal.ToString()); ASw.Write(" START WITH {0}", ASequence.iInitial.ToString()); if (ASequence.bCycleOnLimit) { ASw.WriteLine(); ASw.Write(" CYCLE"); } ASw.WriteLine(";"); return true; }
/// <inheritdoc/> public TThis Append(TSequence sequence, int group = 0) { Argument.CheckIfValid(group == 0, nameof(group), "Groups are not supported."); return(FromDistinctWeights(Dictionary.Select(kvp => new KeyValuePair <TSequence, Weight>(SequenceManipulator.Concat(kvp.Key, sequence), kvp.Value)))); }
public double GetLogValue(TSequence sequence) => weightFunction?.GetLogValue(sequence) ?? double.NegativeInfinity;
/// <summary> /// Creates a point mass weight function. /// </summary> /// <param name="point">The point.</param> /// <returns>The created point mass weight function.</returns> public static MultiRepresentationWeightFunction <TDictionary> FromPoint(TSequence point) => FromPointMass(PointMassWeightFunction.FromPoint(point));
/// <summary> /// parse the definition of a database sequence /// </summary> /// <param name="cur2">the current node</param> /// <returns></returns> protected TSequence ParseSequence(XmlNode cur2) { TSequence element; element = new TSequence(); element.strName = GetAttribute(cur2, "name"); element.strDescription = GetAttribute(cur2, "descr"); element.strArea = GetAttribute(cur2, "area"); element.bCycleOnLimit = GetAttribute(cur2, "cycleonlimit") == "yes"; element.iInitial = GetIntAttribute(cur2, "initial"); element.iMinVal = GetIntAttribute(cur2, "minval"); element.iMaxVal = GetIntAttribute(cur2, "maxval"); element.iIncrement = GetIntAttribute(cur2, "increment"); return element; }