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(int windowSize) { nValue = windowSize + 1; predictors = new NGramPredictor<T>[nValue]; int i; for (i = 0; i < nValue; i++) predictors[i] = new NGramPredictor<T>(i + 1); }
- Define a function for registering a sequence, just like its predecessor:
public void RegisterSequence(T[] actions) { int i; for (i = 0; i < nValue; i++) { T[] subactions = new ...