Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10635


Ignore:
Timestamp:
03/19/14 16:04:36 (11 years ago)
Author:
rstoll
Message:

Fix for missing value filtering

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/StatisticsLogic.cs

    r10624 r10635  
    2525using HeuristicLab.Common;
    2626
    27 namespace HeuristicLab.DataPreprocessing
    28 {
    29 
    30   public class StatisticsLogic : IStatisticsLogic
    31   {
     27namespace HeuristicLab.DataPreprocessing {
     28
     29  public class StatisticsLogic : IStatisticsLogic {
    3230
    3331    private readonly ITransactionalPreprocessingData preprocessingData;
    3432    private readonly ISearchLogic searchLogic;
    3533
    36     public StatisticsLogic(ITransactionalPreprocessingData thePreprocessingData, ISearchLogic theSearchLogic)
    37     {
     34    public StatisticsLogic(ITransactionalPreprocessingData thePreprocessingData, ISearchLogic theSearchLogic) {
    3835      preprocessingData = thePreprocessingData;
    3936      searchLogic = theSearchLogic;
    4037    }
    4138
    42     public int GetColumnCount()
    43     {
     39    public int GetColumnCount() {
    4440      return preprocessingData.Columns;
    4541    }
    4642
    47     public int GetRowCount()
    48     {
     43    public int GetRowCount() {
    4944      return preprocessingData.Rows;
    5045    }
    5146
    52     public int GetNumericColumnCount()
    53     {
     47    public int GetNumericColumnCount() {
    5448      int count = 0;
    5549
    56       for (int i = 0; i < preprocessingData.Columns; ++i)
    57       {
    58         if (preprocessingData.IsType<double>(i))
    59         {
     50      for (int i = 0; i < preprocessingData.Columns; ++i) {
     51        if (preprocessingData.IsType<double>(i)) {
    6052          ++count;
    6153        }
     
    6456    }
    6557
    66     public int GetNominalColumnCount()
    67     {
     58    public int GetNominalColumnCount() {
    6859      return preprocessingData.Columns - GetNumericColumnCount();
    6960    }
    7061
    71     public int GetMissingValueCount()
    72     {
     62    public int GetMissingValueCount() {
    7363      int count = 0;
    74       for (int i = 0; i < preprocessingData.Columns; ++i)
    75       {
     64      for (int i = 0; i < preprocessingData.Columns; ++i) {
    7665        count += GetMissingValueCount(i);
    7766      }
     
    7968    }
    8069
    81     public int GetMissingValueCount(int columnIndex)
    82     {
     70    public int GetMissingValueCount(int columnIndex) {
    8371      return searchLogic.GetMissingValueIndices(columnIndex).Count();
    8472    }
    8573
    86     public T GetMin<T>(int columnIndex) where T : IComparable<T>
    87     {
     74    public T GetMin<T>(int columnIndex) where T : IComparable<T> {
    8875      return preprocessingData.GetValues<T>(columnIndex).Min();
    8976    }
    9077
    91     public T GetMax<T>(int columnIndex) where T : IComparable<T>
    92     {
     78    public T GetMax<T>(int columnIndex) where T : IComparable<T> {
    9379      return preprocessingData.GetValues<T>(columnIndex).Max();
    9480    }
    9581
    96     public double GetMedian(int columnIndex)
    97     {
     82    public double GetMedian(int columnIndex) {
    9883      double median = double.NaN;
    99       if (preprocessingData.IsType<double>(columnIndex))
    100       {
     84      if (preprocessingData.IsType<double>(columnIndex)) {
    10185        median = GetValuesWithoutNaN<double>(columnIndex).Median();
    10286      }
     
    10488    }
    10589
    106     public double GetAverage(int columnIndex)
    107     {
     90    public double GetAverage(int columnIndex) {
    10891      double avg = double.NaN;
    109       if (preprocessingData.IsType<double>(columnIndex))
    110       {
     92      if (preprocessingData.IsType<double>(columnIndex)) {
    11193        avg = GetValuesWithoutNaN<double>(columnIndex).Where(x => !double.IsNaN(x)).Average();
    11294      }
     
    11496    }
    11597
    116     public DateTime GetMedianDateTime(int columnIndex)
    117     {
     98    public DateTime GetMedianDateTime(int columnIndex) {
    11899      DateTime median = new DateTime();
    119       if (preprocessingData.IsType<DateTime>(columnIndex))
    120       {
     100      if (preprocessingData.IsType<DateTime>(columnIndex)) {
    121101        median = GetSecondsAsDateTime(GetDateTimeAsSeconds(columnIndex).Median());
    122102      }
     
    124104    }
    125105
    126     public DateTime GetAverageDateTime(int columnIndex)
    127     {
     106    public DateTime GetAverageDateTime(int columnIndex) {
    128107      DateTime avg = new DateTime();
    129       if (preprocessingData.IsType<DateTime>(columnIndex))
    130       {
     108      if (preprocessingData.IsType<DateTime>(columnIndex)) {
    131109        avg = GetSecondsAsDateTime(GetDateTimeAsSeconds(columnIndex).Average());
    132110      }
     
    134112    }
    135113
    136     public T GetMostCommonValue<T>(int columnIndex)
    137     {
     114    public T GetMostCommonValue<T>(int columnIndex) {
    138115      var t = preprocessingData.GetValues<T>(columnIndex);
    139116      var t2 = t.GroupBy(x => x);
     
    148125
    149126
    150     public double GetStandardDeviation(int columnIndex)
    151     {
     127    public double GetStandardDeviation(int columnIndex) {
    152128      double stdDev = double.NaN;
    153       if (preprocessingData.IsType<double>(columnIndex))
    154       {
     129      if (preprocessingData.IsType<double>(columnIndex)) {
    155130        stdDev = GetValuesWithoutNaN<double>(columnIndex).StandardDeviation();
    156       }
    157       else if (preprocessingData.IsType<DateTime>(columnIndex))
    158       {
     131      } else if (preprocessingData.IsType<DateTime>(columnIndex)) {
    159132        stdDev = GetDateTimeAsSeconds(columnIndex).StandardDeviation();
    160133      }
     
    162135    }
    163136
    164     public double GetVariance(int columnIndex)
    165     {
     137    public double GetVariance(int columnIndex) {
    166138      double variance = double.NaN;
    167       if (preprocessingData.IsType<double>(columnIndex))
    168       {
     139      if (preprocessingData.IsType<double>(columnIndex)) {
    169140        variance = preprocessingData.GetValues<double>(columnIndex).Variance();
    170       }
    171       else if (preprocessingData.IsType<DateTime>(columnIndex))
    172       {
     141      } else if (preprocessingData.IsType<DateTime>(columnIndex)) {
    173142        variance = GetDateTimeAsSeconds(columnIndex).Variance();
    174143      }
     
    176145    }
    177146
    178     public int GetDifferentValuesCount<T>(int columnIndex)
    179     {
     147    public int GetDifferentValuesCount<T>(int columnIndex) {
    180148      return preprocessingData.GetValues<T>(columnIndex).GroupBy(x => x).Count();
    181149    }
    182150
    183     public int GetRowMissingValueCount(int rowIndex)
    184     {
     151    public int GetRowMissingValueCount(int rowIndex) {
    185152      int count = 0;
    186       for (int i = 0; i < preprocessingData.Columns; ++i)
    187       {
    188         if (searchLogic.IsMissingValue(i, rowIndex))
    189         {
     153      for (int i = 0; i < preprocessingData.Columns; ++i) {
     154        if (searchLogic.IsMissingValue(i, rowIndex)) {
    190155          ++count;
    191156        }
     
    194159    }
    195160
    196     public string GetVariableName(int columnIndex)
    197     {
     161    public string GetVariableName(int columnIndex) {
    198162      return preprocessingData.GetVariableName(columnIndex);
    199163    }
    200164
    201     public bool IsType<T>(int columnIndex)
    202     {
     165    public bool IsType<T>(int columnIndex) {
    203166      return preprocessingData.IsType<T>(columnIndex);
    204167    }
    205168
    206     public string GetColumnTypeAsString(int columnIndex)
    207     {
    208       if (preprocessingData.IsType<double>(columnIndex))
    209       {
     169    public string GetColumnTypeAsString(int columnIndex) {
     170      if (preprocessingData.IsType<double>(columnIndex)) {
    210171        return "double";
    211       }
    212       else if (preprocessingData.IsType<string>(columnIndex))
    213       {
     172      } else if (preprocessingData.IsType<string>(columnIndex)) {
    214173        return "string";
    215       }
    216       else if (preprocessingData.IsType<DateTime>(columnIndex))
    217       {
     174      } else if (preprocessingData.IsType<DateTime>(columnIndex)) {
    218175        return "DateTime";
    219176      }
     
    221178    }
    222179
    223     private List<T> GetValuesWithoutNaN<T>(int columnIndex)
    224     {
     180    private List<T> GetValuesWithoutNaN<T>(int columnIndex) {
    225181      IEnumerable<int> missing = searchLogic.GetMissingValueIndices(columnIndex);
    226       return (List<T>)preprocessingData.GetValues<T>(columnIndex).Select((v, i) => new { i, v }).Where(x => !missing.Contains(x.i));
    227     }
    228     private IEnumerable<double> GetDateTimeAsSeconds(int columnIndex)
    229     {
     182      return preprocessingData.GetValues<T>(columnIndex)
     183        .Select((v, i) => new { i, v })
     184        .Where(x => !missing.Contains(x.i))
     185        .Select(x => x.v).ToList<T>();
     186    }
     187    private IEnumerable<double> GetDateTimeAsSeconds(int columnIndex) {
    230188      return GetValuesWithoutNaN<DateTime>(columnIndex).Select(x => (double)x.Ticks / TimeSpan.TicksPerSecond);
    231189    }
    232190
    233     private DateTime GetSecondsAsDateTime(double seconds)
    234     {
     191    private DateTime GetSecondsAsDateTime(double seconds) {
    235192      DateTime dateTime = new DateTime();
    236193      return dateTime.AddSeconds(seconds);
    237194    }
    238195
    239     public event DataPreprocessingChangedEventHandler Changed
    240     {
     196    public event DataPreprocessingChangedEventHandler Changed {
    241197      add { preprocessingData.Changed += value; }
    242198      remove { preprocessingData.Changed -= value; }
Note: See TracChangeset for help on using the changeset viewer.