How to do it...

Just like the N-Gram predictor, the building of the hierarchical version is a few steps long:

  1. 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; 
} 
  1. 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); 
} 
  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 ...

Get Unity 2018 Artificial Intelligence Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.