public void AddRoomVisit(int room) { lastRoomsVisited.Add(room); if (lastRoomsVisited.Count == nValue) { nGramPredictor.GetMostLikely(lastRoomsVisited); } roomsEntered++; }
//computes the prediction public T GetMostLikely(T[] actions) { T bestAction = default(T); for (int i = 0; i < nValue; i++) { NGramPredictor <T> p = predictors[nValue - i - 1]; T[] subactions = new T[i + 1]; Array.Copy(actions, nValue - i - 1, subactions, 0, i + 1); int numActions = p.GetActionsNum(ref actions); if (numActions > threshold) { bestAction = p.GetMostLikely(actions); } } return(bestAction); }
public string GetMostLikely(string[] actions) { for (int i = 0; i < nValue - 1; i++) { NGramPredictor nGram = ngrams[nValue - i - 1]; //get substring string[] subActions = new string[nValue - i - 1]; int startIndex = (actions.Length - 1) - (subActions.Length - 1); for (int j = 0; j < subActions.Length; j++) { subActions[j] = actions[startIndex]; startIndex++; } string stringOfArray = string.Join("", subActions); if (stringOfArray == "") { return(String.Empty); } if (subActions.Length == 1) { stringOfArray = subActions[0]; } //check if there are enough entries if (nGram.data.ContainsKey(stringOfArray)) { KeyDataRecord data = (KeyDataRecord)nGram.data[stringOfArray]; if (data.total > threshold) { return(nGram.GetMostLikely(subActions)); } } } return(string.Empty); }