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);
        }
Ejemplo n.º 3
0
        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);
            }
        }
Ejemplo n.º 4
0
        public PredictionTree <T> Add(T item)
        {
            var child = new PredictionTree <T>(item, this);

            children.Add(child);
            return(child);
        }
Ejemplo n.º 5
0
        public T[] GetSequence(int sequenceId)
        {
            PredictionTree <T> node = lookup[sequenceId];
            List <T>           list = new List <T>
            {
                node.Item
            };

            while (node.Parent != null)
            {
                node = node.Parent;
                list.Add(node.Item);
            }
            list.Reverse();
            return(list.ToArray());
        }
Ejemplo n.º 6
0
 public PredictionTree(T item, PredictionTree <T> parent)
 {
     this.item   = item;
     this.parent = parent;
 }
Ejemplo n.º 7
0
 public void Add(int sequenceId, PredictionTree <T> node)
 {
     lookup.Add(sequenceId, node);
 }