// private void RecursiveDivider(T[] itemArray, int minSize, CountTable <T> countTable, int initialArraySize) { int size = itemArray.Length; if (size > minSize) { double weight = (double)size / initialArraySize; countTable.Update(itemArray, weight); for (int n = 0; n < size; n++) { T[] subSequence = itemArray.Exclude(n, 1).ToArray(); RecursiveDivider(subSequence, minSize, countTable, initialArraySize); } } }
public T[] Predict(IEnumerable <T> target) { if (target == null) { throw new ArgumentNullException(nameof(target)); } T[] knownItems = target.Where(x => invertedIndex.ContainsKey(x)).ToArray(); // Keep only the items that were seen by the inverted index T[] result = new T[0]; T[] itemArray = knownItems; int initialSize = knownItems.Length; for (int i = minRecursion; i <= maxRecursion && result.Length == 0; i++) { CountTable <T> countTable = new CountTable <T>(invertedIndex, lookupTable); int minSize = itemArray.Length - 1; RecursiveDivider(itemArray, minSize, countTable, initialSize); result = countTable.GetBestSequence(); } return(result); }