- Timestamp:
- 06/30/15 12:30:04 (9 years ago)
- Location:
- branches/DataPreprocessingImprovements/HeuristicLab.DataPreprocessing/3.4/Implementations
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataPreprocessingImprovements/HeuristicLab.DataPreprocessing/3.4/Implementations/SearchLogic.cs
r12012 r12545 23 23 using System.Collections; 24 24 using System.Collections.Generic; 25 using System.Linq;26 25 27 26 namespace HeuristicLab.DataPreprocessing { 28 27 public class SearchLogic : ISearchLogic { 29 28 private readonly ITransactionalPreprocessingData preprocessingData; 29 private readonly IFilterLogic filterLogic; 30 30 31 31 private Dictionary<int, IList<int>> MissingValueIndicies { get; set; } … … 44 44 } 45 45 46 public SearchLogic(ITransactionalPreprocessingData thePreprocessingData ) {46 public SearchLogic(ITransactionalPreprocessingData thePreprocessingData, IFilterLogic theFilterLogic) { 47 47 preprocessingData = thePreprocessingData; 48 filterLogic = theFilterLogic; 48 49 49 50 MissingValueIndicies = new Dictionary<int, IList<int>>(); 50 51 ValuesWithoutNaN = new Dictionary<int, IList>(); 51 52 52 preprocessingData.Changed += preprocessingData_Changed; 53 preprocessingData.Changed += PreprocessingData_Changed; 54 filterLogic.FilterChanged += FilterLogic_FilterChanged; 53 55 } 54 56 55 void preprocessingData_Changed(object sender, DataPreprocessingChangedEventArgs e) 56 { 57 void FilterLogic_FilterChanged(object sender, EventArgs e) { 58 //recalculate 59 for (int i = 0; i < Columns; i++) { 60 MissingValueIndicies.Remove(i); 61 ValuesWithoutNaN.Remove(i); 62 } 63 } 64 65 void PreprocessingData_Changed(object sender, DataPreprocessingChangedEventArgs e) { 57 66 switch (e.Type) { 58 67 case DataPreprocessingChangedEventType.DeleteColumn: … … 73 82 ValuesWithoutNaN = new Dictionary<int, IList>(); 74 83 break; 75 } 84 } 76 85 } 77 86 … … 97 106 98 107 public IList<int> GetMissingValueIndices(int columnIndex) { 99 if (!MissingValueIndicies.ContainsKey(columnIndex)){ 100 if (preprocessingData.VariableHasType<double>(columnIndex)) { 101 MissingValueIndicies[columnIndex] = GetMissingValueIndices<double>(columnIndex); 102 } else if (preprocessingData.VariableHasType<string>(columnIndex)) { 103 MissingValueIndicies[columnIndex] = GetMissingValueIndices<string>(columnIndex); 104 } else if (preprocessingData.VariableHasType<DateTime>(columnIndex)) { 105 MissingValueIndicies[columnIndex] = GetMissingValueIndices<DateTime>(columnIndex); 106 } else { 107 throw new ArgumentException("column " + columnIndex + " contains a non supported type."); 108 } 109 } 108 if (!MissingValueIndicies.ContainsKey(columnIndex)) { 109 if (preprocessingData.VariableHasType<double>(columnIndex)) { 110 MissingValueIndicies[columnIndex] = GetMissingValueIndices<double>(columnIndex); 111 } else if (preprocessingData.VariableHasType<string>(columnIndex)) { 112 MissingValueIndicies[columnIndex] = GetMissingValueIndices<string>(columnIndex); 113 } else if (preprocessingData.VariableHasType<DateTime>(columnIndex)) { 114 MissingValueIndicies[columnIndex] = GetMissingValueIndices<DateTime>(columnIndex); 115 } else { 116 throw new ArgumentException("column " + columnIndex + " contains a non supported type."); 117 } 118 } 119 return MissingValueIndicies[columnIndex]; 120 } 110 121 111 return MissingValueIndicies[columnIndex];112 }113 122 private IList<int> GetMissingValueIndices<T>(int columnIndex) { 114 123 List<int> missingIndices = new List<int>(); 115 116 for (int row = 0; row < preprocessingData.Rows; ++row) {124 125 for (int row = 0; row < preprocessingData.Rows; ++row) { 117 126 if (IsMissingValue(columnIndex, row)) { 118 127 missingIndices.Add(row); … … 123 132 } 124 133 125 public IEnumerable<T> GetValuesWithoutNaN<T>(int columnIndex, bool considerSelection) 126 { 127 if (considerSelection) { 128 var selectedRows = preprocessingData.Selection[columnIndex]; 129 134 public IEnumerable<T> GetValuesWithoutNaN<T>(int columnIndex, bool considerSelection) { 135 if (considerSelection) { 136 var selectedRows = preprocessingData.Selection[columnIndex]; 137 130 138 List<T> values = new List<T>(); 131 139 foreach (var rowIdx in selectedRows) { -
branches/DataPreprocessingImprovements/HeuristicLab.DataPreprocessing/3.4/Implementations/StatisticsLogic.cs
r12012 r12545 38 38 39 39 public int GetColumnCount() { 40 return preprocessingData.Columns;40 return searchLogic.Columns; 41 41 } 42 42 43 43 public int GetRowCount() { 44 return preprocessingData.Rows;44 return searchLogic.Rows; 45 45 } 46 46 … … 48 48 int count = 0; 49 49 50 for (int i = 0; i < preprocessingData.Columns; ++i) {50 for (int i = 0; i < searchLogic.Columns; ++i) { 51 51 if (preprocessingData.VariableHasType<double>(i)) { 52 52 ++count; … … 57 57 58 58 public int GetNominalColumnCount() { 59 return preprocessingData.Columns - GetNumericColumnCount();59 return searchLogic.Columns - GetNumericColumnCount(); 60 60 } 61 61 62 62 public int GetMissingValueCount() { 63 63 int count = 0; 64 for (int i = 0; i < preprocessingData.Columns; ++i) {64 for (int i = 0; i < searchLogic.Columns; ++i) { 65 65 count += GetMissingValueCount(i); 66 66 } … … 73 73 74 74 public T GetMin<T>(int columnIndex, bool considerSelection) where T : IComparable<T> { 75 return preprocessingData.GetValues<T>(columnIndex, considerSelection).Min(); 75 var min = default(T); 76 if (preprocessingData.VariableHasType<T>(columnIndex)) { 77 var values = GetValuesWithoutNaN<T>(columnIndex, considerSelection); 78 if (values.Any()) { 79 min = values.Min(); 80 } 81 } 82 return min; 76 83 } 77 84 78 85 public T GetMax<T>(int columnIndex, bool considerSelection) where T : IComparable<T> { 79 return preprocessingData.GetValues<T>(columnIndex, considerSelection).Max(); 86 var max = default(T); 87 if (preprocessingData.VariableHasType<T>(columnIndex)) { 88 var values = GetValuesWithoutNaN<T>(columnIndex, considerSelection); 89 if (values.Any()) { 90 max = values.Max(); 91 } 92 } 93 return max; 80 94 } 81 95 … … 83 97 double median = double.NaN; 84 98 if (preprocessingData.VariableHasType<double>(columnIndex)) { 85 median = GetValuesWithoutNaN<double>(columnIndex, considerSelection).Median(); 99 var values = GetValuesWithoutNaN<double>(columnIndex, considerSelection); 100 if (values.Any()) { 101 median = values.Median(); 102 } 86 103 } 87 104 return median; … … 91 108 double avg = double.NaN; 92 109 if (preprocessingData.VariableHasType<double>(columnIndex)) { 93 avg = GetValuesWithoutNaN<double>(columnIndex, considerSelection).Average(); 110 var values = GetValuesWithoutNaN<double>(columnIndex, considerSelection); 111 if (values.Any()) { 112 avg = values.Average(); 113 } 94 114 } 95 115 return avg; … … 113 133 114 134 public T GetMostCommonValue<T>(int columnIndex, bool considerSelection) { 115 var t = preprocessingData.GetValues<T>(columnIndex, considerSelection); 116 var t2 = t.GroupBy(x => x); 117 var t3 = t2.Select(g => g.Key); 118 119 return preprocessingData.GetValues<T>(columnIndex, considerSelection) 120 .GroupBy(x => x) 135 var values = GetValuesWithoutNaN<T>(columnIndex, considerSelection); 136 if (!values.Any()) 137 return default(T); 138 return values.GroupBy(x => x) 121 139 .OrderByDescending(g => g.Count()) 122 140 .Select(g => g.Key)
Note: See TracChangeset
for help on using the changeset viewer.