TraceLab Component Library
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties
AffineTransformation.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 TraceLab.Components.DevelopmentKit.Utils;
18 using TraceLabSDK.Types;
19 
20 namespace TraceLab.Components.DevelopmentKit.Postprocessors
21 {
25  public static class AffineTranformation
26  {
34  public static TLSimilarityMatrix Transform(TLSimilarityMatrix large, TLSimilarityMatrix small, double lambda)
35  {
36  TLSimilarityMatrix largeNormal = Normalize(large);
37  TLSimilarityMatrix smallNormal = Normalize(small);
38  TLSimilarityMatrix combined = new TLSimilarityMatrix();
39 
40  foreach (TLSingleLink largeLink in largeNormal.AllLinks)
41  {
42  double smallLink = smallNormal.GetScoreForLink(largeLink.SourceArtifactId, largeLink.TargetArtifactId);
43  combined.AddLink(largeLink.SourceArtifactId, largeLink.TargetArtifactId, Combine(largeLink.Score, smallLink, lambda));
44  }
45 
46  return combined;
47  }
48 
56  public static double Combine(double large, double small, double lambda)
57  {
58  return (lambda * large) + ((1 - lambda) * small);
59  }
60 
66  public static TLSimilarityMatrix Normalize(TLSimilarityMatrix matrix)
67  {
68  TLSimilarityMatrix norm = new TLSimilarityMatrix();
69  double mean = TLSimilarityMatrixUtil.AverageSimilarity(matrix);
71  foreach (TLSingleLink link in matrix.AllLinks)
72  {
73  norm.AddLink(link.SourceArtifactId, link.TargetArtifactId, (link.Score - mean) / stdDev);
74  }
75  return norm;
76  }
77  }
78 }