public void BlockEnumerator_Next_WithInputShorterThatBlockSize_ReturnsFalse() { var enumerator = new BlockEnumerator <int>(new int[] { 1, 2, 3 }, 4); bool result = enumerator.Next(); Assert.That(result, Is.False); }
public void BlockEnumerator_Next_WithEmptyInput_ReturnsFalse() { var enumerator = new BlockEnumerator <int>(new int[0], 1); bool result = enumerator.Next(); Assert.That(result, Is.False); }
public void BlockEnumerator_Next_WithInputLongerThatBlockSize_EnumeratesByBlock() { var enumerator = new BlockEnumerator <int>(new[] { 1, 2, 3, 4, 5 }, 2); Assert.That(enumerator.Next(), Is.True); Assert.That(enumerator.CurrentBlock, Is.EquivalentTo(new[] { 1, 2 })); Assert.That(enumerator.Next(), Is.True); Assert.That(enumerator.CurrentBlock, Is.EquivalentTo(new[] { 2, 3 })); Assert.That(enumerator.Next(), Is.True); Assert.That(enumerator.CurrentBlock, Is.EquivalentTo(new[] { 3, 4 })); Assert.That(enumerator.Next(), Is.True); Assert.That(enumerator.CurrentBlock, Is.EquivalentTo(new[] { 4, 5 })); Assert.That(enumerator.Next(), Is.False); Assert.That(enumerator.CurrentBlock, Is.Null); }
public void Learn(IEnumerable <T> seq) { Guard.NotNull(seq, nameof(seq)); var enumerator = new BlockEnumerator <T>(seq, 2); while (enumerator.Next()) { T first = enumerator.CurrentBlock[0]; T second = enumerator.CurrentBlock[1]; _states[first].Links[_states[second]] += 1; } }
public void Learn(IEnumerable <T> seq) { Guard.NotNull(seq, nameof(seq)); var enumerator = new BlockEnumerator <T>(seq, _order + 1); while (enumerator.Next()) { T[] first = enumerator.CurrentBlock.Take(_order).ToArray(); T[] second = enumerator.CurrentBlock.Skip(1).Take(_order).ToArray(); #warning Storing the last item of the key in the MArkov state may not be appropriate for order > 1 _states[first].Links[_states[second]] += 1; } }