private Evaluation MatchResultWithGroundTruth(ActualTopics actualTopics, CandidateTopics candTopics, int topK) { Evaluation eval = new Evaluation(topK); int topicHitCount = 0; int keywordHitCount = 0; for (int top = 0; top < topK; top++) { actualTopics.Match(candTopics.CandidateKeywords[top].Word, ref topicHitCount, ref keywordHitCount); eval.KeywordPercisionAtK[top] = keywordHitCount / (float)(top + 1); // top+1 because index starts from 0 in array eval.KeywordRecallAtK[top] = keywordHitCount / (float)actualTopics.TotalKeywords; eval.TopicPercisionAtK[top] = topicHitCount / (float)(top + 1); eval.TopicRecallAtK[top] = topicHitCount / (float)actualTopics.TotalTopics; if (eval.KeywordPercisionAtK[top] > 0 || eval.KeywordRecallAtK[top] > 0) { eval.KeywordF1AtK[top] = 2 * (eval.KeywordPercisionAtK[top] * eval.KeywordRecallAtK[top]) / (eval.KeywordPercisionAtK[top] + eval.KeywordRecallAtK[top]); } else { eval.KeywordF1AtK[top] = 0; } if (eval.TopicPercisionAtK[top] > 0 || eval.TopicRecallAtK[top] > 0) { eval.TopicF1AtK[top] = 2 * (eval.TopicPercisionAtK[top] * eval.TopicRecallAtK[top]) / (eval.TopicPercisionAtK[top] + eval.TopicRecallAtK[top]); } else { eval.TopicF1AtK[top] = 0; } } return(eval); }
public bool AddSlidingWindow(string filePath) { ActualTopics topics; try { if (filePath.Length > 0) { string[] readLines = File.ReadAllText(filePath).Split(new char[] { '\n' }); topics = new ActualTopics(); topics.LoadMendatoryWords(readLines[0].Trim()); if (readLines.Length > 1) { topics.LoadOptionalWords(readLines[1].Trim()); } else { topics.LoadOptionalWords(""); } TimeSlot.Add(Path.GetFileName(filePath), topics); } return(true); } catch (Exception ex) { throw ex; } }