TraceLab Component Library
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties
AveragePrecisionRanklistComputation.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;
18 using System.Collections.Generic;
19 using System.Linq;
20 using System.Text;
21 using TraceLabSDK;
22 using TraceLabSDK.Types;
23 using TraceLabSDK.Types.Contests;
24 
25 namespace TraceLab.Components.DevelopmentKit.Metrics.Traceability
26 {
31  {
32  #region Members
33 
34  private const string _name = "Average Precision (ranklist granularity)";
35  private const string _description = "Average precision measures average of the precision values for each correct link. This metric is calculated on the total ranklist.";
36 
40  public override string Name
41  {
42  get { return _name; }
43  }
44 
48  public override string Description
49  {
50  get { return _description; }
51  }
52 
53  private TLSimilarityMatrix _matrix;
54  private TLSimilarityMatrix _oracle;
55 
56  #endregion
57 
63  public AveragePrecisionRanklistComputation(TLSimilarityMatrix candidateMatrix, TLSimilarityMatrix answerMatrix)
64  : base()
65  {
66  _matrix = candidateMatrix;
67  _oracle = answerMatrix;
68  }
69 
73  protected override void ComputeImplementation()
74  {
75  Results = new SerializableDictionary<string, double>();
76  double sumOfPrecisions = 0.0;
77  int currentLink = 0;
78  int correctSoFar = 0;
79  TLLinksList links = _matrix.AllLinks;
80  links.Sort();
81  foreach (TLSingleLink link in links)
82  {
83  currentLink++;
84  if (_oracle.IsLinkAboveThreshold(link.SourceArtifactId, link.TargetArtifactId))
85  {
86  correctSoFar++;
87  sumOfPrecisions += correctSoFar / (double)currentLink;
88  }
89  }
90  Results.Add("AveragePrecision", sumOfPrecisions / _oracle.AllLinks.Count);
91  }
92 
96  protected override Metric GenerateSummaryImplementation()
97  {
98  BoxSummaryData data = new BoxSummaryData(Name, Description);
99  data.AddPoint(new BoxPlotPoint(Results.Values.ToArray()));
100  return data;
101  }
102  }
103 }