18 using System.Collections.Generic;
22 using TraceLabSDK.Types;
23 using TraceLabSDK.Types.Contests;
25 namespace TraceLab.Components.DevelopmentKit.Metrics.Traceability
35 private const string _name =
"Precision-Recall Curve";
36 private const string _description =
"Computes the precision and recall at every cutpoint in the ranklist. This is an inherent ranklist granularity (even when used in the query component).";
41 public override string Name
49 public override string Description
51 get {
return _description; }
54 private TLSimilarityMatrix _matrix;
55 private TLSimilarityMatrix _oracle;
56 private string _precisionFormat;
57 private string _recallFormat;
69 _matrix = candidateMatrix;
70 _oracle = answerMatrix;
71 _precisionFormat = String.Format(
"{{0:D{0}}}_Precision", Math.Floor(Math.Log10(candidateMatrix.Count)));
72 _recallFormat = String.Format(
"{{0:D{0}}}_Recall", Math.Floor(Math.Log10(candidateMatrix.Count)));
80 _oracle.Threshold = 0;
82 TLLinksList links = _matrix.AllLinks;
84 Results =
new SerializableDictionary<string, double>();
85 for (
int linkNumber = 1; linkNumber <= links.Count; linkNumber++)
87 if (_oracle.IsLinkAboveThreshold(links[linkNumber - 1].SourceArtifactId, links[linkNumber - 1].TargetArtifactId))
91 Results.Add(String.Format(_precisionFormat, linkNumber), correct / (double)linkNumber);
92 Results.Add(String.Format(_recallFormat, linkNumber), correct / (double)_oracle.Count);
102 LineSeries data =
new LineSeries(_name, _description);
103 for (
int i = 1; i <= Results.Count / 2; i++)
108 x = Results[String.Format(_recallFormat, i)];
109 y = Results[String.Format(_precisionFormat, i)];
111 catch (KeyNotFoundException e)
115 data.AddPoint(
new Point(x, y));