Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10381


Ignore:
Timestamp:
01/22/14 16:13:42 (11 years ago)
Author:
mleitner
Message:

Add Media, Average, Variance, and StdDeviation support for DateTime

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  
    22using System.Linq;
    33using HeuristicLab.Common;
     4using System.Collections.Generic;
    45
    56namespace HeuristicLab.DataPreprocessing {
     
    7475    }
    7576
     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
    7697    public T GetMostCommonValue<T>(int columnIndex) {
    7798      return preprocessingData.GetValues<T>(columnIndex)
     99
    78100                              .GroupBy(x => x)
    79101                              .OrderByDescending(g => g.Count())
     
    88110        stdDev = preprocessingData.GetValues<double>(columnIndex).StandardDeviation();
    89111      }
     112      else if (preprocessingData.IsType<DateTime>(variableName)) {
     113        stdDev = GetDateTimeAsSeconds(variableName).StandardDeviation();
     114      }
    90115      return stdDev;
    91116    }
    92117
    93118    public double GetVariance(int columnIndex) {
    94       double stdDev = double.NaN;
     119       double variance = double.NaN;
     120
    95121      if (preprocessingData.IsType<double>(columnIndex)) {
    96         stdDev = preprocessingData.GetValues<double>(columnIndex).Variance();
     122        variance = preprocessingData.GetValues<double>(columnIndex).Variance();
    97123      }
    98       return stdDev;
     124      else if (preprocessingData.IsType<DateTime>(variableName)) {
     125        variance = GetDateTimeAsSeconds(variableName).Variance();
     126      }
     127      return variance;
    99128    }
    100129
     
    112141      return count;
    113142    }
    114 
    115143
    116144    public string GetVariableName(int columnIndex) {
     
    133161    }
    134162
     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    }
    135173  }
    136174}
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Interfaces/IStatisticsLogic.cs

    r10374 r10381  
    1111    int GetMissingValueCount(int columnIndex);
    1212    int GetRowMissingValueCount(int rowIndex);
     13
    1314    T GetMin<T>(int columnIndex) where T : IComparable<T>;
    1415    T GetMax<T>(int columnIndex) where T : IComparable<T>;
     16   
    1517    double GetMedian(int columnIndex);
    1618    double GetAverage(int columnIndex);
     19    DateTime GetMedianDateTime(int columnIndex);
     20    DateTime GetAverageDateTime(int columnIndex);
     21
    1722    double GetStandardDeviation(int columnIndex);
    1823    double GetVariance(int columnIndex);
     
    2227    bool IsType<T>(int columnIndex);
    2328    string GetColumnTypeAsString(int columnIndex);
     29
    2430  }
    2531}
Note: See TracChangeset for help on using the changeset viewer.