- Timestamp:
- 01/22/14 16:13:42 (11 years ago)
- Location:
- branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/StatisticsLogic.cs
r10371 r10381 2 2 using System.Linq; 3 3 using HeuristicLab.Common; 4 using System.Collections.Generic; 4 5 5 6 namespace HeuristicLab.DataPreprocessing { … … 74 75 } 75 76 77 public DateTime GetMedianDateTime(int columnIndex) 78 { 79 DateTime median = new DateTime(); 80 if (preprocessingData.IsType<DateTime>(columnIndex)) 81 { 82 median = GetSecondsAsDateTime(GetDateTimeAsSeconds(columnIndex).Median()); 83 } 84 return median; 85 } 86 87 public DateTime GetAverageDateTime(int columnIndex) 88 { 89 DateTime avg = new DateTime(); 90 if (preprocessingData.IsType<DateTime>(columnIndex)) 91 { 92 avg = GetSecondsAsDateTime(GetDateTimeAsSeconds(columnIndex).Average()); 93 } 94 return avg; 95 } 96 76 97 public T GetMostCommonValue<T>(int columnIndex) { 77 98 return preprocessingData.GetValues<T>(columnIndex) 99 78 100 .GroupBy(x => x) 79 101 .OrderByDescending(g => g.Count()) … … 88 110 stdDev = preprocessingData.GetValues<double>(columnIndex).StandardDeviation(); 89 111 } 112 else if (preprocessingData.IsType<DateTime>(variableName)) { 113 stdDev = GetDateTimeAsSeconds(variableName).StandardDeviation(); 114 } 90 115 return stdDev; 91 116 } 92 117 93 118 public double GetVariance(int columnIndex) { 94 double stdDev = double.NaN; 119 double variance = double.NaN; 120 95 121 if (preprocessingData.IsType<double>(columnIndex)) { 96 stdDev= preprocessingData.GetValues<double>(columnIndex).Variance();122 variance = preprocessingData.GetValues<double>(columnIndex).Variance(); 97 123 } 98 return stdDev; 124 else if (preprocessingData.IsType<DateTime>(variableName)) { 125 variance = GetDateTimeAsSeconds(variableName).Variance(); 126 } 127 return variance; 99 128 } 100 129 … … 112 141 return count; 113 142 } 114 115 143 116 144 public string GetVariableName(int columnIndex) { … … 133 161 } 134 162 163 private IEnumerable<double> GetDateTimeAsSeconds(int columnIndex) 164 { 165 return preprocessingData.GetValues<DateTime>(columnIndex).Select(x => (double)x.Ticks / TimeSpan.TicksPerSecond); 166 } 167 168 private DateTime GetSecondsAsDateTime(double seconds) 169 { 170 DateTime dateTime = new DateTime(); 171 return dateTime.Add(new TimeSpan(0, 0, (int)seconds)); 172 } 135 173 } 136 174 } -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Interfaces/IStatisticsLogic.cs
r10374 r10381 11 11 int GetMissingValueCount(int columnIndex); 12 12 int GetRowMissingValueCount(int rowIndex); 13 13 14 T GetMin<T>(int columnIndex) where T : IComparable<T>; 14 15 T GetMax<T>(int columnIndex) where T : IComparable<T>; 16 15 17 double GetMedian(int columnIndex); 16 18 double GetAverage(int columnIndex); 19 DateTime GetMedianDateTime(int columnIndex); 20 DateTime GetAverageDateTime(int columnIndex); 21 17 22 double GetStandardDeviation(int columnIndex); 18 23 double GetVariance(int columnIndex); … … 22 27 bool IsType<T>(int columnIndex); 23 28 string GetColumnTypeAsString(int columnIndex); 29 24 30 } 25 31 }
Note: See TracChangeset
for help on using the changeset viewer.