Changeset 8483 for branches/DatasetFeatureCorrelation/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/FeatureCorrelation.cs
- Timestamp:
- 08/14/12 13:05:48 (12 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/DatasetFeatureCorrelation/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/FeatureCorrelation.cs
r8481 r8483 33 33 namespace HeuristicLab.Problems.DataAnalysis { 34 34 [StorableClass] 35 [Item("HeatMap", "Represents a heat map of double values.")] 36 public class ExtendedHeatMap : HeatMap { 37 38 private const string PrearsonsRSquared = "Pearsons R Squared"; 35 [Item("FeatureCorrelation", "Represents the correlation of features in a data set.")] 36 public class FeatureCorrelation : HeatMap { 37 38 private const string PearsonsR = "Pearsons R"; 39 private const string PearsonsRSquared = "Pearsons R Squared"; 39 40 private const string HoeffdingsDependence = "Hoeffdings Dependence"; 40 41 private const string SpearmansRank = "Spearmans Rank"; 41 42 public IEnumerable<string> CorrelationCalculators { 42 get { return new List<string>() { P rearsonsRSquared, HoeffdingsDependence, SpearmansRank }; }43 get { return new List<string>() { PearsonsR, PearsonsRSquared, HoeffdingsDependence, SpearmansRank }; } 43 44 } 44 45 … … 65 66 private BackgroundWorker bw; 66 67 67 public ExtendedHeatMap()68 public FeatureCorrelation() 68 69 : base() { 69 70 this.Title = "Feature Correlation"; 70 71 this.columnNames = Enumerable.Range(1, 2).Select(x => x.ToString()).ToList(); 71 72 this.rowNames = Enumerable.Range(1, 2).Select(x => x.ToString()).ToList(); 72 } 73 74 public ExtendedHeatMap(IDataAnalysisProblemData problemData) { 73 sortableView = true; 74 } 75 76 public FeatureCorrelation(IDataAnalysisProblemData problemData) { 75 77 this.problemData = problemData; 76 78 this.Title = "Feature Correlation"; 77 79 this.columnNames = problemData.Dataset.DoubleVariables.ToList(); 78 80 this.rowNames = problemData.Dataset.DoubleVariables.ToList(); 81 sortableView = true; 79 82 80 83 CalculateElements(problemData.Dataset); 81 84 } 82 protected ExtendedHeatMap(ExtendedHeatMaporiginal, Cloner cloner)85 protected FeatureCorrelation(FeatureCorrelation original, Cloner cloner) 83 86 : base(original, cloner) { 84 87 this.Title = "Feature Correlation"; … … 88 91 } 89 92 public override IDeepCloneable Clone(Cloner cloner) { 90 return new ExtendedHeatMap(this, cloner);93 return new FeatureCorrelation(this, cloner); 91 94 } 92 95 … … 112 115 } 113 116 bw.RunWorkerAsync(new BackgroundWorkerInfo { Dataset = dataset, Calculator = calc, Partition = partition }); 117 if (calc.Equals(PearsonsR) || calc.Equals(SpearmansRank)) { 118 Maximum = 1.0; 119 Minimum = -1.0; 120 } else if (calc.Equals(HoeffdingsDependence)) { 121 Maximum = 1.0; 122 Minimum = -0.5; 123 } else { 124 Maximum = 1.0; 125 Minimum = 0.0; 126 } 114 127 } 115 128 … … 128 141 129 142 double calculations = (Math.Pow(length, 2) + length) / 2; 143 144 worker.ReportProgress(0); 130 145 131 146 for (int i = 0; i < length; i++) { … … 150 165 } else if (calc.Equals(SpearmansRank)) { 151 166 elements[i, j] = SpearmansRankCorrelationCoefficientCalculator.Calculate(var1, var2, out error); 167 } else if (calc.Equals(PearsonsRSquared)) { 168 elements[i, j] = OnlinePearsonsRSquaredCalculator.Calculate(var1, var2, out error); 152 169 } else { 153 elements[i, j] = OnlinePearsonsRSquaredCalculator.Calculate (var1, var2, out error);170 elements[i, j] = OnlinePearsonsRSquaredCalculator.CalculateR(var1, var2, out error); 154 171 } 155 172 elements[j, i] = elements[i, j]; 156 173 if (!error.Equals(OnlineCalculatorError.None)) { 157 throw new ArgumentException("Calculator returned " + error); 174 worker.ReportProgress(100); 175 throw new ArgumentException("Calculator returned " + error + Environment.NewLine + "Maybe try another calculator."); 158 176 } 159 177 worker.ReportProgress((int)Math.Round((((Math.Pow(i, 2) + i) / 2 + j + 1.0) / calculations) * 100)); … … 172 190 OnReset(); 173 191 } 174 } else {175 Console.WriteLine("Backgroundworker canceled");176 192 } 177 193 } … … 189 205 public event EventHandler ProblemDataChanged; 190 206 protected virtual void OnProblemDataChanged() { 191 var handler = ProblemDataChanged; 192 if (handler != null) handler(this, EventArgs.Empty); 207 EventHandler handler = ProblemDataChanged; 208 if (handler != null) 209 handler(this, EventArgs.Empty); 193 210 } 194 211 #endregion
Note: See TracChangeset
for help on using the changeset viewer.