public void Add(Sequence <T> sequence) { PredictionTree <T> lastNode = null; if (!sequence.Any()) { throw new InvalidOperationException("Sequence cannot be empty."); } if (tree == null) { lastNode = tree = new PredictionTree <T>(sequence.Head, null); if (sequence.Tail.Any()) { lastNode = tree.Add(sequence.Tail); } } else { lastNode = tree.Add(sequence); } index.Add(sequence); lookup.Add(sequence.Id, lastNode); }
public void Learn(IEnumerable <T> sample) { Sequence <T> sequence = new Sequence <T>(++sampleCount, splitLength == 0 ? sample : sample.TakeLast(splitLength)); PredictionTree <T> lastNode = null; if (!sequence.Any()) { throw new InvalidOperationException("Sequence cannot be empty."); } if (tree == null) { lastNode = tree = new PredictionTree <T>(sequence.Head, null); if (sequence.Tail.Any()) { lastNode = tree.Add(sequence.Tail); } } else { lastNode = tree.Add(sequence); } invertedIndex.Add(sequence); lookupTable.Add(sequence.Id, lastNode); }
public PredictionTree <T> Add(Sequence <T> sequence) { if (!sequence.Any()) { throw new InvalidOperationException("Sequence cannot be empty."); } var head = sequence.Head; var tail = sequence.Tail; PredictionTree <T> node = null; if (Contains(head)) { node = Get(head); } else { node = Add(head); } if (tail != null && tail.Any()) { return(node.Add(tail)); } else { return(node); } }