Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10615 for branches


Ignore:
Timestamp:
03/19/14 12:44:20 (11 years ago)
Author:
sbreuer
Message:
  • allow replace value with ... functions for date time
File:
1 edited

Legend:

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

    r10612 r10615  
    2828  public class ManipulationLogic : IManipulationLogic {
    2929    private ITransactionalPreprocessingData preprocessingData;
    30     private IStatisticsLogic statisticInfo;
     30    private IStatisticsLogic statisticsLogic;
    3131    private ISearchLogic searchLogic;
    3232
     
    3434      preprocessingData = _prepocessingData;
    3535      searchLogic = theSearchLogic;
    36       statisticInfo = theStatisticsLogic;
     36      statisticsLogic = theStatisticsLogic;
    3737    }
    3838
     
    4646      preprocessingData.InTransaction(() => {
    4747        foreach (var column in cells) {
    48           double average = statisticInfo.GetAverage(column.Key);
    49           ReplaceIndicesByValue<double>(column.Key, column.Value, average);
     48          if (preprocessingData.IsType<double>(column.Key)) {
     49            double average = statisticsLogic.GetAverage(column.Key);
     50            ReplaceIndicesByValue<double>(column.Key, column.Value, average);
     51          } else if (preprocessingData.IsType<DateTime>(column.Key)) {
     52            DateTime average = statisticsLogic.GetAverageDateTime(column.Key);
     53            ReplaceIndicesByValue<DateTime>(column.Key, column.Value, average);
     54          }
    5055        }
    5156      });
     
    5560      preprocessingData.InTransaction(() => {
    5661        foreach (var column in cells) {
    57           double median = statisticInfo.GetMedian(column.Key);
    58           ReplaceIndicesByValue<double>(column.Key, column.Value, median);
     62          if (preprocessingData.IsType<double>(column.Key)) {
     63            double median = statisticsLogic.GetMedian(column.Key);
     64            ReplaceIndicesByValue<double>(column.Key, column.Value, median);
     65          } else if (preprocessingData.IsType<DateTime>(column.Key)) {
     66            DateTime median = statisticsLogic.GetMedianDateTime(column.Key);
     67            ReplaceIndicesByValue<DateTime>(column.Key, column.Value, median);
     68          }
    5969        }
    6070      });
     
    6676
    6777        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);
     78          if (preprocessingData.IsType<double>(column.Key)) {
     79            double max = statisticsLogic.GetMax<double>(column.Key);
     80            double min = statisticsLogic.GetMin<double>(column.Key);
     81            double randMultiplier = (max - min);
     82            foreach (int index in column.Value) {
     83              double rand = r.NextDouble() * randMultiplier + min;
     84              preprocessingData.SetCell<double>(column.Key, index, rand);
     85            }
     86          } else if (preprocessingData.IsType<DateTime>(column.Key)) {
     87            DateTime min = statisticsLogic.GetMin<DateTime>(column.Key);
     88            DateTime max = statisticsLogic.GetMax<DateTime>(column.Key);
     89            double randMultiplier = (max - min).TotalSeconds;
     90            foreach (int index in column.Value) {
     91              double rand = r.NextDouble() * randMultiplier;
     92              preprocessingData.SetCell<DateTime>(column.Key, index, min.AddSeconds(rand));
     93            }
    7494          }
    7595        }
     
    80100      preprocessingData.InTransaction(() => {
    81101        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;
     102          if (preprocessingData.IsType<double>(column.Key)) {
     103            int countValues = preprocessingData.GetValues<double>(column.Key).Count();
     104            foreach (int index in column.Value) {
     105              // dont replace first or last values
     106              if (index > 0 && index < countValues) {
     107                int prevIndex = indexOfPrevPresentValue(column.Key, index);
     108                int nextIndex = indexOfNextPresentValue(column.Key, index);
     109
     110                // no neighbours found
     111                if (prevIndex < 0 && nextIndex >= countValues) {
     112                  continue;
     113                }
     114                double prev = preprocessingData.GetCell<double>(column.Key, prevIndex);
     115                double next = preprocessingData.GetCell<double>(column.Key, nextIndex);
     116
     117                int valuesToInterpolate = nextIndex - prevIndex;
     118
     119                double interpolationStep = (next - prev) / valuesToInterpolate;
     120
     121                for (int i = prevIndex; i < nextIndex; ++i) {
     122                  double interpolated = prev + (interpolationStep * (i - prevIndex));
     123                  preprocessingData.SetCell<double>(column.Key, i, interpolated);
     124                }
    92125              }
    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);
     126            }
     127          } else if (preprocessingData.IsType<DateTime>(column.Key)) {
     128            int countValues = preprocessingData.GetValues<DateTime>(column.Key).Count();
     129            foreach (int index in column.Value) {
     130              // dont replace first or last values
     131              if (index > 0 && index < countValues) {
     132                int prevIndex = indexOfPrevPresentValue(column.Key, index);
     133                int nextIndex = indexOfNextPresentValue(column.Key, index);
     134
     135                // no neighbours found
     136                if (prevIndex < 0 && nextIndex >= countValues) {
     137                  continue;
     138                }
     139                DateTime prev = preprocessingData.GetCell<DateTime>(column.Key, prevIndex);
     140                DateTime next = preprocessingData.GetCell<DateTime>(column.Key, nextIndex);
     141
     142                int valuesToInterpolate = nextIndex - prevIndex;
     143
     144                double interpolationStep = (next - prev).TotalSeconds / valuesToInterpolate;
     145
     146                for (int i = prevIndex; i < nextIndex; ++i) {
     147                  DateTime interpolated = prev.AddSeconds(interpolationStep * (i - prevIndex));
     148                  preprocessingData.SetCell<DateTime>(column.Key, i, interpolated);
     149                }
    103150              }
    104151            }
     
    130177        foreach (var column in cells) {
    131178          if (preprocessingData.IsType<double>(column.Key)) {
    132             ReplaceIndicesByValue<double>(column.Key, column.Value, statisticInfo.GetMostCommonValue<double>(column.Key));
     179            ReplaceIndicesByValue<double>(column.Key, column.Value, statisticsLogic.GetMostCommonValue<double>(column.Key));
    133180          } 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));
     181            ReplaceIndicesByValue<string>(column.Key, column.Value, statisticsLogic.GetMostCommonValue<string>(column.Key));
     182          } else if (preprocessingData.IsType<DateTime>(column.Key)) {
     183            ReplaceIndicesByValue<DateTime>(column.Key, column.Value, statisticsLogic.GetMostCommonValue<DateTime>(column.Key));
    137184          } else {
    138185            throw new ArgumentException("column with index: " + column.Key + " contains a non supported type.");
Note: See TracChangeset for help on using the changeset viewer.