- Timestamp:
- 01/22/14 16:13:42 (11 years ago)
- File:
-
- 1 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 }
Note: See TracChangeset
for help on using the changeset viewer.