/// <summary> /// Computes the recall of each source artifact in the similarity matrix using the answer matrix provided. /// </summary> protected override void ComputeImplementation() { SerializableDictionary <string, double> sourceRecall = new SerializableDictionary <string, double>(); _oracle.Threshold = 0; foreach (string sourceArtifact in _oracle.SourceArtifactsIds) { TLLinksList links = _matrix.GetLinksAboveThresholdForSourceArtifact(sourceArtifact); int correct = 0; foreach (TLSingleLink link in links) { if (_oracle.IsLinkAboveThreshold(link.SourceArtifactId, link.TargetArtifactId)) { correct++; } } sourceRecall.Add(sourceArtifact, correct / (double)_oracle.GetCountOfLinksAboveThresholdForSourceArtifact(sourceArtifact)); } Results = sourceRecall; }
/// <summary> /// Called from MetricComputation /// </summary> protected override void ComputeImplementation() { Results = new SerializableDictionary <string, double>(); foreach (string sourceID in _oracle.SourceArtifactsIds) { double sumOfPrecisions = 0.0; int currentLink = 0; int correctSoFar = 0; TLLinksList links = _matrix.GetLinksAboveThresholdForSourceArtifact(sourceID); links.Sort(); foreach (TLSingleLink link in links) { currentLink++; if (_oracle.IsLinkAboveThreshold(sourceID, link.TargetArtifactId)) { correctSoFar++; sumOfPrecisions += correctSoFar / (double)currentLink; } } Results.Add(sourceID, sumOfPrecisions / _oracle.GetCountOfLinksAboveThresholdForSourceArtifact(sourceID)); } }
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); }