TraceLab Component Library
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties
MeanAveragePrecisionComputation.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 = "Mean Average Precision";
35  private const string _description = "Mean average precision measures average of the average precision values for each correct link per query.";
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 MeanAveragePrecisionComputation(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  IMetricComputation avgP = new AveragePrecisionQueryComputation(_matrix, _oracle);
77  avgP.Compute();
78  Results.Add("MeanAveragePrecision", avgP.Results.Values.Average());
79  }
80 
84  protected override Metric GenerateSummaryImplementation()
85  {
86  BoxSummaryData data = new BoxSummaryData(Name, Description);
87  data.AddPoint(new BoxPlotPoint(Results.Values.ToArray()));
88  return data;
89  }
90  }
91 }