TraceLab Component Library
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties
PrecisionRanklistComputation.cs
Go to the documentation of this file.
1 // TraceLab Component Library
2 // Copyright © 2012-2013 SEMERU
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 using System.Linq;
18 using TraceLabSDK;
19 using TraceLabSDK.Types;
20 using TraceLabSDK.Types.Contests;
21 
22 namespace TraceLab.Components.DevelopmentKit.Metrics.Traceability
23 {
28  {
29  #region Members
30 
31  private const string _name = "Precision (ranklist granularity)";
32  private const string _description = "Precision measures the fraction of correctly retrieved documents among the retrieved documents. This metric is computed on the overall ranked list.";
33 
37  public override string Name
38  {
39  get { return _name; }
40  }
41 
45  public override string Description
46  {
47  get { return _description; }
48  }
49 
50  private TLSimilarityMatrix _matrix;
51  private TLSimilarityMatrix _oracle;
52 
53  #endregion
54 
60  public PrecisionRanklistComputation(TLSimilarityMatrix candidateMatrix, TLSimilarityMatrix answerMatrix)
61  : base()
62  {
63  _matrix = candidateMatrix;
64  _oracle = answerMatrix;
65  }
66 
70  protected override void ComputeImplementation()
71  {
72  _oracle.Threshold = 0;
73  int correct = 0;
74  foreach (TLSingleLink link in _matrix.AllLinks)
75  {
76  if (_oracle.IsLinkAboveThreshold(link.SourceArtifactId, link.TargetArtifactId))
77  {
78  correct++;
79  }
80  }
81  Results = new SerializableDictionary<string, double>();
82  Results.Add("Precision", correct / (double)_matrix.Count);
83  }
84 
89  protected override Metric GenerateSummaryImplementation()
90  {
91  BoxSummaryData data = new BoxSummaryData(Name, Description);
92  data.AddPoint(new BoxPlotPoint(Results.Values.ToArray()));
93  return data;
94  }
95  }
96 }