Changeset 10615
- Timestamp:
- 03/19/14 12:44:20 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/ManipulationLogic.cs
r10612 r10615 28 28 public class ManipulationLogic : IManipulationLogic { 29 29 private ITransactionalPreprocessingData preprocessingData; 30 private IStatisticsLogic statistic Info;30 private IStatisticsLogic statisticsLogic; 31 31 private ISearchLogic searchLogic; 32 32 … … 34 34 preprocessingData = _prepocessingData; 35 35 searchLogic = theSearchLogic; 36 statistic Info= theStatisticsLogic;36 statisticsLogic = theStatisticsLogic; 37 37 } 38 38 … … 46 46 preprocessingData.InTransaction(() => { 47 47 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 } 50 55 } 51 56 }); … … 55 60 preprocessingData.InTransaction(() => { 56 61 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 } 59 69 } 60 70 }); … … 66 76 67 77 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 } 74 94 } 75 95 } … … 80 100 preprocessingData.InTransaction(() => { 81 101 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 } 92 125 } 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 } 103 150 } 104 151 } … … 130 177 foreach (var column in cells) { 131 178 if (preprocessingData.IsType<double>(column.Key)) { 132 ReplaceIndicesByValue<double>(column.Key, column.Value, statistic Info.GetMostCommonValue<double>(column.Key));179 ReplaceIndicesByValue<double>(column.Key, column.Value, statisticsLogic.GetMostCommonValue<double>(column.Key)); 133 180 } else if (preprocessingData.IsType<string>(column.Key)) { 134 ReplaceIndicesByValue<string>(column.Key, column.Value, statistic Info.GetMostCommonValue<string>(column.Key));135 } else if (preprocessingData.IsType<DateTime>(column.Key)) { 136 ReplaceIndicesByValue<DateTime>(column.Key, column.Value, statistic Info.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)); 137 184 } else { 138 185 throw new ArgumentException("column with index: " + column.Key + " contains a non supported type.");
Note: See TracChangeset
for help on using the changeset viewer.