Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/12/14 17:42:42 (11 years ago)
Author:
sbreuer
Message:
  • enhanced selection of cells
File:
1 edited

Legend:

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

    r10586 r10590  
    4343    }
    4444
    45     public void ReplaceIndicesByAverageValue(int columnIndex, IEnumerable<int> rowIndices) {
    46       double average = statisticInfo.GetAverage(columnIndex);
    47       ReplaceIndicesByValue<double>(columnIndex, rowIndices, average);
    48     }
    49 
    50     public void ReplaceIndicesByMedianValue(int columnIndex, IEnumerable<int> rowIndices) {
    51       double median = statisticInfo.GetMedian(columnIndex);
    52       ReplaceIndicesByValue<double>(columnIndex, rowIndices, median);
    53     }
    54 
    55     public void ReplaceIndicesByRandomValue(int columnIndex, IEnumerable<int> rowIndices) {
     45    public void ReplaceIndicesByAverageValue(Dictionary<int, List<int>> cells) {
     46      preprocessingData.BeginTransaction();
     47      foreach (var column in cells) {
     48        double average = statisticInfo.GetAverage(column.Key);
     49        ReplaceIndicesByValue<double>(column.Key, column.Value, average);
     50      }
     51      preprocessingData.EndTransaction();
     52    }
     53
     54    public void ReplaceIndicesByMedianValue(Dictionary<int, List<int>> cells) {
     55      preprocessingData.BeginTransaction();
     56      foreach (var column in cells) {
     57        double median = statisticInfo.GetMedian(column.Key);
     58        ReplaceIndicesByValue<double>(column.Key, column.Value, median);
     59      }
     60      preprocessingData.EndTransaction();
     61    }
     62
     63    public void ReplaceIndicesByRandomValue(Dictionary<int, List<int>> cells) {
     64      preprocessingData.BeginTransaction();
    5665      Random r = new Random();
    5766
    58       double max = statisticInfo.GetMax<double>(columnIndex);
    59       double min = statisticInfo.GetMin<double>(columnIndex);
    60       double randMultiplier = (max - min);
    61       foreach (int index in rowIndices) {
    62         double rand = r.NextDouble() * randMultiplier + min;
    63         preprocessingData.SetCell<double>(columnIndex, index, rand);
    64       }
    65     }
    66 
    67     public void ReplaceIndicesByLinearInterpolationOfNeighbours(int columnIndex, IEnumerable<int> rowIndices) {
    68       int countValues = preprocessingData.GetValues<double>(columnIndex).Count();
    69       foreach (int index in rowIndices) {
    70         // dont replace first or last values
    71         if (index > 0 && index < countValues) {
    72           int prevIndex = indexOfPrevPresentValue(columnIndex, index);
    73           int nextIndex = indexOfNextPresentValue(columnIndex, index);
    74 
    75           // no neighbours found
    76           if (prevIndex < 0 && nextIndex >= countValues) {
    77             continue;
     67      foreach (var column in cells) {
     68        double max = statisticInfo.GetMax<double>(column.Key);
     69        double min = statisticInfo.GetMin<double>(column.Key);
     70        double randMultiplier = (max - min);
     71        foreach (int index in column.Value) {
     72          double rand = r.NextDouble() * randMultiplier + min;
     73          preprocessingData.SetCell<double>(column.Key, index, rand);
     74        }
     75      }
     76      preprocessingData.EndTransaction();
     77    }
     78
     79    public void ReplaceIndicesByLinearInterpolationOfNeighbours(Dictionary<int, List<int>> cells) {
     80      preprocessingData.BeginTransaction();
     81      foreach (var column in cells) {
     82        int countValues = preprocessingData.GetValues<double>(column.Key).Count();
     83        foreach (int index in column.Value) {
     84          // dont replace first or last values
     85          if (index > 0 && index < countValues) {
     86            int prevIndex = indexOfPrevPresentValue(column.Key, index);
     87            int nextIndex = indexOfNextPresentValue(column.Key, index);
     88
     89            // no neighbours found
     90            if (prevIndex < 0 && nextIndex >= countValues) {
     91              continue;
     92            }
     93            double prev = preprocessingData.GetCell<double>(column.Key, prevIndex);
     94            double next = preprocessingData.GetCell<double>(column.Key, nextIndex);
     95
     96            int valuesToInterpolate = nextIndex - prevIndex;
     97
     98            double interpolationStep = (prev + next) / valuesToInterpolate;
     99
     100            for (int i = prevIndex; i < nextIndex; ++i) {
     101              double interpolated = prev + (interpolationStep * (i - prevIndex));
     102              preprocessingData.SetCell<double>(column.Key, i, interpolated);
     103            }
    78104          }
    79           double prev = preprocessingData.GetCell<double>(columnIndex, prevIndex);
    80           double next = preprocessingData.GetCell<double>(columnIndex, nextIndex);
    81 
    82           int valuesToInterpolate = nextIndex - prevIndex;
    83 
    84           double interpolationStep = (prev + next) / valuesToInterpolate;
    85 
    86           for (int i = prevIndex; i < nextIndex; ++i) {
    87             double interpolated = prev + (interpolationStep * (i - prevIndex));
    88             preprocessingData.SetCell<double>(columnIndex, i, interpolated);
    89           }
    90         }
    91       }
     105        }
     106      }
     107      preprocessingData.EndTransaction();
    92108    }
    93109
     
    110126    }
    111127
    112     public void ReplaceIndicesByMostCommonValue(int columnIndex, IEnumerable<int> rowIndices) {
    113       if (preprocessingData.IsType<double>(columnIndex)) {
    114         ReplaceIndicesByValue<double>(columnIndex, rowIndices, statisticInfo.GetMostCommonValue<double>(columnIndex));
    115       } else if (preprocessingData.IsType<string>(columnIndex)) {
    116         ReplaceIndicesByValue<string>(columnIndex, rowIndices, statisticInfo.GetMostCommonValue<string>(columnIndex));
    117       } else if (preprocessingData.IsType<DateTime>(columnIndex)) {
    118         ReplaceIndicesByValue<DateTime>(columnIndex, rowIndices, statisticInfo.GetMostCommonValue<DateTime>(columnIndex));
    119       } else {
    120         throw new ArgumentException("column with index: " + columnIndex + " contains a non supported type.");
    121       }
     128    public void ReplaceIndicesByMostCommonValue(Dictionary<int, List<int>> cells) {
     129      preprocessingData.BeginTransaction();
     130      foreach (var column in cells) {
     131        if (preprocessingData.IsType<double>(column.Key)) {
     132          ReplaceIndicesByValue<double>(column.Key, column.Value, statisticInfo.GetMostCommonValue<double>(column.Key));
     133        } else if (preprocessingData.IsType<string>(column.Key)) {
     134          ReplaceIndicesByValue<string>(column.Key, column.Value, statisticInfo.GetMostCommonValue<string>(column.Key));
     135        } else if (preprocessingData.IsType<DateTime>(column.Key)) {
     136          ReplaceIndicesByValue<DateTime>(column.Key, column.Value, statisticInfo.GetMostCommonValue<DateTime>(column.Key));
     137        } else {
     138          throw new ArgumentException("column with index: " + column.Key + " contains a non supported type.");
     139        }
     140      }
     141      preprocessingData.EndTransaction();
    122142    }
    123143
Note: See TracChangeset for help on using the changeset viewer.