TraceLab Component Library
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties
TraceabilityMetricsRanklistComponent.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 TraceLab.Components.DevelopmentKit.Metrics;
19 using TraceLab.Components.DevelopmentKit.Metrics.Traceability;
20 using TraceLab.Components.Library.Metrics.Controller;
21 using TraceLabSDK;
22 using TraceLabSDK.Types;
23 using TraceLabSDK.Types.Contests;
24 
25 namespace TraceLab.Components.Library.Metrics.Traceability
26 {
27  [Component(Name = "Traceability Metrics - Ranklist granularity",
28  Description = "Computes various traceability metrics on a similarity matrix at the ranklist granularity.",
29  Author = "SEMERU; Evan Moritz",
30  Version = "1.0.0.0",
31  ConfigurationType = typeof(TraceabilityMetricsRanklistConfig))]
32  [IOSpec(IOSpecType.Input, "CandidateMatrix", typeof(TLSimilarityMatrix))]
33  [IOSpec(IOSpecType.Input, "AnswerMatrix", typeof(TLSimilarityMatrix))]
34  [Tag("Metrics.Traceability")]
35  public class TraceabilityMetricsRanklistComponent : BaseComponent
36  {
37  private TraceabilityMetricsRanklistConfig _config;
38 
39  public TraceabilityMetricsRanklistComponent(ComponentLogger log)
40  : base(log)
41  {
42  _config = new TraceabilityMetricsRanklistConfig();
43  Configuration = _config;
44  }
45 
46  public override void Compute()
47  {
48  Logger.Trace("Starting metrics computation: " + _config.TechniqueName);
49  TLSimilarityMatrix matrix = (TLSimilarityMatrix)Workspace.Load("CandidateMatrix");
50  TLSimilarityMatrix oracle = (TLSimilarityMatrix)Workspace.Load("AnswerMatrix");
51  TLExperimentResults exResults = new TLExperimentResults(_config.TechniqueName);
52  #region Precision
53  if (_config.Precision)
54  {
55  Logger.Trace("Computing precision...");
56  IMetricComputation computation = new PrecisionRanklistComputation(matrix, oracle);
57  computation.Compute();
58  ResultsController.Instance.AddResult(_config.TechniqueName, _config.DatasetName, computation);
59  }
60  else
61  {
62  Logger.Trace("Skipped precision computation.");
63  }
64  #endregion
65  #region Recall
66  if (_config.Recall)
67  {
68  Logger.Trace("Computing recall...");
69  IMetricComputation computation = new RecallRanklistComputation(matrix, oracle);
70  computation.Compute();
71  ResultsController.Instance.AddResult(_config.TechniqueName, _config.DatasetName, computation);
72  }
73  else
74  {
75  Logger.Trace("Skipped recall computation.");
76  }
77  #endregion
78  #region Average Precision
79  if (_config.AveragePrecision)
80  {
81  Logger.Trace("Computing average precision...");
82  IMetricComputation computation = new AveragePrecisionRanklistComputation(matrix, oracle);
83  computation.Compute();
84  ResultsController.Instance.AddResult(_config.TechniqueName, _config.DatasetName, computation);
85  }
86  else
87  {
88  Logger.Trace("Skipped average precision computation.");
89  }
90  #endregion
91  #region PR curve
92  if (_config.PRCurve)
93  {
94  Logger.Trace("Computing precision-recall curve...");
95  IMetricComputation computation = new PrecisionRecallCurveComputation(matrix, oracle);
96  computation.Compute();
97  ResultsController.Instance.AddResult(_config.TechniqueName, _config.DatasetName, computation);
98  }
99  else
100  {
101  Logger.Trace("Skipped precision-recall curve computation.");
102  }
103  #endregion
104  }
105  }
106 }