TraceLab Component Library
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties
QuadruplePCAComponent.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 TraceLab.Components.Types;
24 using TraceLab.Components.DevelopmentKit.Metrics.Traceability;
25 using RPlugin.Core;
26 
27 namespace TraceLab.Components.Library.Metrics.Traceability
28 {
29  [Component(Name = "Principal Component Analysis (quadruple)",
30  Description = "Performs PCA on four TLSimilarityMatrix.",
31  Author = "SEMERU; Evan Moritz",
32  Version = "1.0.0.0",
33  ConfigurationType = typeof(RConfig))]
34  [IOSpec(IOSpecType.Input, "Matrix1", typeof(TLSimilarityMatrix))]
35  [IOSpec(IOSpecType.Input, "Matrix2", typeof(TLSimilarityMatrix))]
36  [IOSpec(IOSpecType.Input, "Matrix3", typeof(TLSimilarityMatrix))]
37  [IOSpec(IOSpecType.Input, "Matrix4", typeof(TLSimilarityMatrix))]
38  [IOSpec(IOSpecType.Output, "Matrix1Contribution", typeof(double))]
39  [IOSpec(IOSpecType.Output, "Matrix2Contribution", typeof(double))]
40  [IOSpec(IOSpecType.Output, "Matrix3Contribution", typeof(double))]
41  [IOSpec(IOSpecType.Output, "Matrix4Contribution", typeof(double))]
42  [Tag("RPlugin.Metrics.Traceability")]
43  [Tag("Metrics.Traceability")]
44  public class QuadruplePCAComponent : BaseComponent
45  {
46  private RConfig _config;
47 
48  public QuadruplePCAComponent(ComponentLogger log)
49  : base(log)
50  {
51  _config = new RConfig();
52  Configuration = _config;
53  }
54 
55  public override void Compute()
56  {
57  TLSimilarityMatrix matrix1 = (TLSimilarityMatrix)Workspace.Load("Matrix1");
58  TLSimilarityMatrix matrix2 = (TLSimilarityMatrix)Workspace.Load("Matrix2");
59  TLSimilarityMatrix matrix3 = (TLSimilarityMatrix)Workspace.Load("Matrix3");
60  TLSimilarityMatrix matrix4 = (TLSimilarityMatrix)Workspace.Load("Matrix4");
61  REngine engine = new REngine(_config.RScriptPath);
62  double[] results = (double[])engine.Execute(new PCAScript(matrix1, matrix2, matrix3, matrix4));
63  Workspace.Store("Matrix1Contribution", results[0]);
64  Workspace.Store("Matrix2Contribution", results[1]);
65  Workspace.Store("Matrix3Contribution", results[2]);
66  Workspace.Store("Matrix4Contribution", results[3]);
67  }
68  }
69 }