Improving the predictor – Hierarchical N-Gram
The N-Gram predictor can be improved by having a handler with several other predictors ranging from 1 to n, and obtaining the best possible action after comparing the best guess from each one of them.
Getting ready...
We need to make some adjustments prior to implementing the hierarchical N-Gram predictor.
Add the following member function to the NGramPredictor
class:
public int GetActionsNum(ref T[] actions) { string key = ArrToStrKey(ref actions); if (!data.ContainsKey(key)) return 0; return data[key].total; }
How to do it...
Just like the N-Gram predictor, the building of the hierarchical version is a few steps long:
- Create the new class:
using System; using System.Collections; using System.Text; public class HierarchicalNGramP<T> { public int threshold; public NGramPredictor<T>[] predictors; private int nValue; }
- Implement the constructor for initializing member values:
public HierarchicalNGramP...