- Timestamp:
- 12/18/13 12:24:53 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/PreprocessingDataManipulation.cs
r10218 r10234 59 59 if (index > 0 && index < countValues) 60 60 { 61 double prev = preprocessingData.GetCell<double>(variableName, index - 1);62 double next = preprocessingData.GetCell<double>(variableName, index + 1);61 int prevIndex = indexOfPrevPresentValue(variableName, index); 62 int nextIndex = indexOfNextPresentValue(variableName, index); 63 63 64 double interpolated = (prev + next) / 2; 64 // no neighbours found 65 if (prevIndex < 0 && nextIndex >= countValues) 66 { 67 continue; 68 } 69 double prev = preprocessingData.GetCell<double>(variableName, prevIndex); 70 double next = preprocessingData.GetCell<double>(variableName, nextIndex); 65 71 66 preprocessingData.SetCell<double>(variableName, index, interpolated); 72 int valuesToInterpolate = nextIndex - prevIndex; 73 74 double interpolationStep = (prev + next) / valuesToInterpolate; 75 76 for (int i = prevIndex; i < nextIndex; ++i) { 77 double interpolated = prev + (interpolationStep * (i-prevIndex)); 78 preprocessingData.SetCell<double>(variableName, i, interpolated); 79 } 67 80 } 68 81 } 82 } 83 84 private int indexOfPrevPresentValue(string variableName, int start) { 85 int offset = start - 1; 86 while(offset >= 0 && preprocessingData.IsMissingValue(variableName, offset)){ 87 offset--; 88 } 89 90 return offset; 91 } 92 93 private int indexOfNextPresentValue(string variableName, int start) 94 { 95 int offset = start + 1; 96 while (offset < preprocessingData.Rows && preprocessingData.IsMissingValue(variableName, offset)) 97 { 98 offset++; 99 } 100 101 return offset; 69 102 } 70 103 … … 96 129 // process all given ranges - e.g. TrainingPartition, Trainingpartition 97 130 foreach (IntRange range in ranges) { 98 List< int> shuffledIndices = new List<int>();131 List<Tuple<int, int>> shuffledIndices = new List<Tuple<int,int>>(); 99 132 100 133 // generate random indices used for shuffeling each column … … 102 135 { 103 136 int rand = random.Next(range.Start, i); 104 shuffledIndices [i] = rand;137 shuffledIndices.Add(new Tuple<int,int>(i,rand)); 105 138 } 106 139 … … 123 156 } 124 157 125 public void reOrderToIndices<T>(string variableName, List< int> indices) {158 public void reOrderToIndices<T>(string variableName, List<Tuple<int, int>> indices) { 126 159 // process all columns equally 127 for (int i = 0; i < preprocessingData.Rows; i++)160 foreach(Tuple<int, int> index in indices) 128 161 { 129 int replaceIndex = indices[i]; 162 int originalIndex = index.Item1; 163 int replaceIndex = index.Item2; 130 164 131 T tmp = preprocessingData.GetCell<T>(variableName, i);165 T tmp = preprocessingData.GetCell<T>(variableName, originalIndex); 132 166 T replaceValue = preprocessingData.GetCell<T>(variableName, replaceIndex); 133 167 134 preprocessingData.SetCell<T>(variableName, i, replaceValue);168 preprocessingData.SetCell<T>(variableName, originalIndex, replaceValue); 135 169 preprocessingData.SetCell<T>(variableName, replaceIndex, tmp); 136 170 }
Note: See TracChangeset
for help on using the changeset viewer.