TraceLab Component Library
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties
DeltaUtils.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.Types;
22 
23 namespace TraceLab.Components.DevelopmentKit.Postprocessors.CSTI
24 {
28  public static class DeltaUtils
29  {
35  public static double Compute(TLSimilarityMatrix matrix)
36  {
37  List<double> DeltaLookup = new List<double>();
38  foreach (string source in matrix.SourceArtifactsIds)
39  {
40  DeltaLookup.Add(ComputeForSourceArtifact(matrix, source));
41  }
42  DeltaLookup.Sort();
43  if (DeltaLookup.Count % 2 == 0)
44  {
45  return (DeltaLookup[DeltaLookup.Count / 2] + DeltaLookup[(DeltaLookup.Count / 2) + 1]) / 2.0;
46  }
47  else
48  {
49  return DeltaLookup[Convert.ToInt32(Math.Ceiling(DeltaLookup.Count / 2.0))];
50  }
51  }
52 
59  public static double ComputeForSourceArtifact(TLSimilarityMatrix matrix, string source)
60  {
61  matrix.Threshold = double.MinValue;
62  double min = Double.MaxValue;
63  double max = Double.MinValue;
64  foreach (TLSingleLink link in matrix.GetLinksAboveThresholdForSourceArtifact(source))
65  {
66  if (link.Score < min)
67  {
68  min = link.Score;
69  }
70  if (link.Score > max)
71  {
72  max = link.Score;
73  }
74  }
75  double delta = (max - min) / 2.0;
76  // according to R scripts
77  if (delta < 0.05)
78  {
79  delta = Math.Pow(delta, 4) / 4;
80  }
81  return delta;
82  }
83  }
84 }