Changeset 10661
- Timestamp:
- 03/26/14 13:34:18 (11 years ago)
- Location:
- branches/DataPreprocessing
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataPreprocessing/HeuristicLab 3.3.sln
r10542 r10661 1910 1910 HideSolutionNode = FALSE 1911 1911 EndGlobalSection 1912 GlobalSection(Performance) = preSolution 1913 HasPerformanceSessions = true 1914 EndGlobalSection 1912 1915 EndGlobal -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/SearchLogic.cs
r10586 r10661 21 21 22 22 using System; 23 using System.Collections; 23 24 using System.Collections.Generic; 24 25 using System.Linq; … … 28 29 private readonly ITransactionalPreprocessingData preprocessingData; 29 30 31 private Dictionary<int, IEnumerable<int>> MissingValueIndicies { get; set; } 32 private Dictionary<int, IEnumerable> ValuesWithoutNaN { get; set; } 33 30 34 public SearchLogic(ITransactionalPreprocessingData thePreprocessingData) { 31 35 preprocessingData = thePreprocessingData; 36 37 MissingValueIndicies = new Dictionary<int, IEnumerable<int>>(); 38 ValuesWithoutNaN = new Dictionary<int, IEnumerable>(); 39 40 preprocessingData.Changed += preprocessingData_Changed; 41 } 42 43 void preprocessingData_Changed(object sender, DataPreprocessingChangedEventArgs e) 44 { 45 MissingValueIndicies.Remove(e.Column); 46 ValuesWithoutNaN.Remove(e.Column); 32 47 } 33 48 … … 53 68 54 69 public IEnumerable<int> GetMissingValueIndices(int columnIndex) { 55 if (preprocessingData.IsType<double>(columnIndex)) { 56 return preprocessingData.GetValues<double>(columnIndex).Select((s, i) => new { i, s }).Where(t => double.IsNaN(t.s)).Select(t => t.i); 57 } else if (preprocessingData.IsType<string>(columnIndex)) { 58 return preprocessingData.GetValues<string>(columnIndex).Select((s, i) => new { i, s }).Where(t => string.IsNullOrEmpty(t.s)).Select(t => t.i); 59 } else if (preprocessingData.IsType<DateTime>(columnIndex)) { 60 return preprocessingData.GetValues<DateTime>(columnIndex).Select((s, i) => new { i, s }).Where(t => t.s.Equals(DateTime.MinValue)).Select(t => t.i); 61 } else { 62 throw new ArgumentException("column " + columnIndex + " contains a non supported type."); 70 if (!MissingValueIndicies.ContainsKey(columnIndex)){ 71 if (preprocessingData.IsType<double>(columnIndex)) { 72 MissingValueIndicies[columnIndex] = GetMissingValueIndices<double>(columnIndex); 73 } else if (preprocessingData.IsType<string>(columnIndex)) { 74 MissingValueIndicies[columnIndex] = GetMissingValueIndices<string>(columnIndex); 75 } else if (preprocessingData.IsType<DateTime>(columnIndex)) { 76 MissingValueIndicies[columnIndex] = GetMissingValueIndices<DateTime>(columnIndex); 77 } else { 78 throw new ArgumentException("column " + columnIndex + " contains a non supported type."); 79 } 80 } 81 82 return MissingValueIndicies[columnIndex]; 83 } 84 private IEnumerable<int> GetMissingValueIndices<T>(int columnIndex) { 85 List<int> missingIndices = new List<int>(); 86 87 for(int row = 0; row < preprocessingData.Rows; ++row) { 88 if (IsMissingValue(columnIndex, row)) { 89 missingIndices.Add(row); 90 } 63 91 } 92 93 return missingIndices; 64 94 } 65 95 96 public IEnumerable<T> GetValuesWithoutNaN<T>(int columnIndex) 97 { 98 if (!ValuesWithoutNaN.ContainsKey(columnIndex)) 99 { 100 List<T> values = new List<T>(); 101 102 for (int row = 0; row < preprocessingData.Rows; ++row) 103 { 104 if (!IsMissingValue(columnIndex, row)) 105 { 106 values.Add(preprocessingData.GetCell<T>(columnIndex, row)); 107 } 108 } 109 110 ValuesWithoutNaN[columnIndex] = values; 111 } 112 113 return (IEnumerable<T>)ValuesWithoutNaN[columnIndex]; 114 } 66 115 } 67 116 } -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/StatisticsLogic.cs
r10635 r10661 24 24 using System.Linq; 25 25 using HeuristicLab.Common; 26 using System.Collections; 26 27 27 28 namespace HeuristicLab.DataPreprocessing { … … 178 179 } 179 180 180 private List<T> GetValuesWithoutNaN<T>(int columnIndex) {181 IEnumerable<int> missing = searchLogic.GetMissingValueIndices(columnIndex);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 181 private IEnumerable<double> GetDateTimeAsSeconds(int columnIndex) { 188 182 return GetValuesWithoutNaN<DateTime>(columnIndex).Select(x => (double)x.Ticks / TimeSpan.TicksPerSecond); 183 } 184 185 private IEnumerable<T> GetValuesWithoutNaN<T>(int columnIndex) { 186 return searchLogic.GetValuesWithoutNaN<T>(columnIndex); 189 187 } 190 188 -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Interfaces/ISearchLogic.cs
r10539 r10661 38 38 39 39 bool IsMissingValue(int columnIndex, int rowIndex); 40 41 IEnumerable<T> GetValuesWithoutNaN<T>(int columnIndex); 40 42 } 41 43 }
Note: See TracChangeset
for help on using the changeset viewer.