/// <summary> /// Reorganizes source chain. /// </summary> /// <param name="source"> /// Source chain. /// </param> /// <returns> /// <see cref="AbstractChain"/>. /// </returns> /// <exception cref="InvalidOperationException"> /// Thrown if level is less than 0. /// </exception> public override AbstractChain Reorganize(AbstractChain source) { if (level < 0) { throw new InvalidOperationException("Markov chain level can't be less than 0"); } if (level == 0) { return source; } var result = new BaseChain(); result.ClearAndSetNewLength(source.GetLength() + level); for (int i = 0; i < source.GetLength(); i++) { result[i] = source[i]; } var iterator = new IteratorStart(source, level, 1); iterator.Reset(); iterator.Next(); AbstractChain addition = iterator.Current(); for (int i = 0; i < addition.GetLength(); i++) { result[source.GetLength() + i] = addition[i]; } return result; }
/// <summary> /// Reorganizes <see cref="AbstractChain"/> into <see cref="AbstractChain"/>. /// </summary> /// <param name="source"> /// Source chain. /// </param> /// <returns> /// The <see cref="AbstractChain"/>. /// </returns> public override AbstractChain Reorganize(AbstractChain source) { var result = source.Clone() as AbstractChain; if (result != null) { return result; } result = new BaseChain(); result.ClearAndSetNewLength(source.GetLength()); var iteratorRead = new IteratorSimpleStart(source, 1); var iteratorWrite = new IteratorWritableStart(result); iteratorRead.Reset(); iteratorWrite.Reset(); iteratorRead.Next(); iteratorWrite.Next(); for (int i = 0; i < source.GetLength(); i++) { iteratorWrite.WriteValue(iteratorRead.Current()); iteratorRead.Next(); iteratorWrite.Next(); } return result; }
/// <summary> /// Reorganizes <see cref="AbstractChain"/> into <see cref="AbstractChain"/>. /// </summary> /// <param name="source"> /// Source chain. /// </param> /// <returns> /// The <see cref="AbstractChain"/>. /// </returns> public override AbstractChain Reorganize(AbstractChain source) { var resent = new BaseChain(); resent.ClearAndSetNewLength(source.GetLength()); for (int i = 0; i < source.GetLength(); i++) { var phantom = source[i] as ValuePhantom; resent.Set(phantom != null ? phantom[0] : source[i], i); } return resent; }
/// <summary> /// Initializes a new instance of the <see cref="IteratorBase"/> class. /// </summary> /// <param name="source"> /// Source chain. /// </param> /// <param name="length"> /// Length of subsequence. /// </param> /// <param name="step"> /// Shift of iterator. /// </param> /// <exception cref="ArgumentException"> /// Thrown if one or more arguments are invalid. /// </exception> public IteratorBase(AbstractChain source, int length, int step) { if (source == null || length <= 0 || source.GetLength() < length) { throw new ArgumentException("Iterator arguments are invalid."); } Length = length; Step = step; Source = source; MaxPosition = Source.GetLength() - Length; Reset(); }
/// <summary> /// Initializes a new instance of the <see cref="IteratorSimpleStart"/> class. /// </summary> /// <param name="source"> /// Source chain. /// </param> /// <param name="step"> /// Shift of iterator. /// </param> /// <exception cref="ArgumentException"> /// Thrown if one or more arguments are invalid. /// </exception> public IteratorSimpleStart(AbstractChain source, int step) { if (source == null || source.GetLength() < 1) { throw new ArgumentException("Sequence for iteration is null or empty.", "source"); } Length = 1; Step = step; Source = source; MaxPosition = Source.GetLength() - Length; Reset(); }