public SortedDictionary<string, double> Calculate(TLSimilarityMatrix resultMatrix, TLDataset dataset) { var answerSet = dataset.AnswerSet; var sourceArtifacts = dataset.SourceArtifacts; SortedDictionary<string, double> metricValues = new SortedDictionary<string, double>(); resultMatrix.Threshold = m_threshold; foreach (TLArtifact sourceArtifact in sourceArtifacts.Values) { int numberOfRetrieved = resultMatrix.GetCountOfLinksAboveThresholdForSourceArtifact(sourceArtifact.Id); double precision = 0.0; if (numberOfRetrieved > 0) { TLLinksList resultsListForArtifact = resultMatrix.GetLinksAboveThresholdForSourceArtifact(sourceArtifact.Id); resultsListForArtifact.Sort(); int numberOfCorrectlyRetrieved = 0; foreach (TLSingleLink link in resultsListForArtifact) { //check if this is relevant link if (answerSet.IsLinkAboveThreshold(link.SourceArtifactId, link.TargetArtifactId)) { numberOfCorrectlyRetrieved++; } } precision = (double)numberOfCorrectlyRetrieved / numberOfRetrieved; metricValues.Add(sourceArtifact.Id, precision); } } resultMatrix.Threshold = 0.0; return metricValues; }
public static double Calculate(string sourceArtifactId, TLLinksList resultList, TLSimilarityMatrix answerMatrix) { resultList.Sort(); int correct = 0; Double totalAvgPrecision = 0.0; int totalDocumentsRead = 0; foreach (TLSingleLink link in resultList) { totalDocumentsRead++; //check if this is relevant link if (answerMatrix.IsLinkAboveThreshold(link.SourceArtifactId, link.TargetArtifactId)) { correct++; Double precisionAtCurrentIteration = (double)correct / totalDocumentsRead; totalAvgPrecision += precisionAtCurrentIteration; } } int numberOfRelevant = answerMatrix.GetCountOfLinksAboveThresholdForSourceArtifact(sourceArtifactId); return totalAvgPrecision; }