private List<ComparableEvent> Index(int eventCount, ITrainingEventReader eventReader, Dictionary<string, int> predicateIndex) { var outcomeMap = new Dictionary<string, int>(); int outcomeCount = 0; var eventsToCompare = new List<ComparableEvent>(eventCount); var indexedContext = new List<int>(); while (eventReader.HasNext()) { TrainingEvent currentTrainingEvent = eventReader.ReadNextEvent(); string[] eventContext = currentTrainingEvent.Context; ComparableEvent comparableEvent; int outcomeId; string outcome = currentTrainingEvent.Outcome; if (outcomeMap.ContainsKey(outcome)) { outcomeId = outcomeMap[outcome]; } else { outcomeId = outcomeCount++; outcomeMap.Add(outcome, outcomeId); } for (int currentPredicate = 0; currentPredicate < eventContext.Length; currentPredicate++) { string predicate = eventContext[currentPredicate]; if (predicateIndex.ContainsKey(predicate)) { indexedContext.Add(predicateIndex[predicate]); } } // drop events with no active features if (indexedContext.Count > 0) { comparableEvent = new ComparableEvent(outcomeId, indexedContext.ToArray()); eventsToCompare.Add(comparableEvent); } else { //"Dropped event " + currentTrainingEvent.Outcome + ":" + currentTrainingEvent.Context); } // recycle the list indexedContext.Clear(); } SetOutcomeLabels(ToIndexedStringArray(outcomeMap)); SetPredicateLabels(ToIndexedStringArray(predicateIndex)); return eventsToCompare; }
private List<ComparableEvent> Index(List<TrainingEvent> events, Dictionary<string, int> predicateIndex) { var map = new Dictionary<string, int>(); int eventCount = events.Count; int outcomeCount = 0; var eventsToCompare = new List<ComparableEvent>(eventCount); var indexedContext = new List<int>(); for (int eventIndex = 0; eventIndex < eventCount; eventIndex++) { TrainingEvent currentTrainingEvent = events[eventIndex]; string[] eventContext = currentTrainingEvent.Context; ComparableEvent comparableEvent; int outcomeIndex; string outcome = currentTrainingEvent.Outcome; if (map.ContainsKey(outcome)) { outcomeIndex = map[outcome]; } else { outcomeIndex = outcomeCount++; map.Add(outcome, outcomeIndex); } for (int currentEventContext = 0; currentEventContext < eventContext.Length; currentEventContext++) { string predicate = eventContext[currentEventContext]; if (predicateIndex.ContainsKey(predicate)) { indexedContext.Add(predicateIndex[predicate]); } } // drop events with no active features if (indexedContext.Count > 0) { comparableEvent = new ComparableEvent(outcomeIndex, indexedContext.ToArray()); eventsToCompare.Add(comparableEvent); } else { //"Dropped event " + oEvent.Outcome + ":" + oEvent.Context); } // recycle the list indexedContext.Clear(); } SetOutcomeLabels(ToIndexedStringArray(map)); SetPredicateLabels(ToIndexedStringArray(predicateIndex)); return eventsToCompare; }