Changeset 15535 for stable/HeuristicLab.DataPreprocessing/3.4/Content
- Timestamp:
- 12/18/17 16:17:39 (7 years ago)
- Location:
- stable
- Files:
-
- 16 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 15518,15534
- Property svn:mergeinfo changed
-
stable/HeuristicLab.DataPreprocessing
- Property svn:mergeinfo changed
-
stable/HeuristicLab.DataPreprocessing/3.4
- Property svn:mergeinfo changed
-
stable/HeuristicLab.DataPreprocessing/3.4/Content/CorrelationMatrixContent.cs
r15242 r15535 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Core; 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 25 26 using HeuristicLab.Problems.DataAnalysis; 26 27 27 28 namespace HeuristicLab.DataPreprocessing { 28 29 [Item("Feature Correlation Matrix", "Represents the feature correlation matrix.")] 29 public class CorrelationMatrixContent : Item, IViewShortcut { 30 [StorableClass] 31 public class CorrelationMatrixContent : PreprocessingContent, IViewShortcut { 30 32 public static new Image StaticItemImage { 31 33 get { return HeuristicLab.Common.Resources.VSImageLibrary.Gradient; } 32 34 } 33 35 36 [Storable] 34 37 public PreprocessingContext Context { get; private set; } 35 public ITransactionalPreprocessingData PreprocessingData { 36 get { return Context.Data; } 37 } 38 38 39 39 40 public DataAnalysisProblemData ProblemData { … … 47 48 } 48 49 49 public CorrelationMatrixContent(PreprocessingContext context) { 50 #region Constructor, Cloning & Persistence 51 public CorrelationMatrixContent(PreprocessingContext context) 52 : base(context.Data) { 50 53 Context = context; 51 54 } … … 55 58 Context = original.Context; 56 59 } 57 58 60 public override IDeepCloneable Clone(Cloner cloner) { 59 61 return new CorrelationMatrixContent(this, cloner); 60 62 } 63 64 [StorableConstructor] 65 protected CorrelationMatrixContent(bool deserializing) 66 : base(deserializing) { } 67 #endregion 61 68 62 69 public event DataPreprocessingChangedEventHandler Changed { -
stable/HeuristicLab.DataPreprocessing/3.4/Content/DataCompletenessChartContent.cs
r15242 r15535 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Core; 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 25 26 26 27 namespace HeuristicLab.DataPreprocessing { 27 28 [Item("Data Completeness Chart", "Represents a datacompleteness chart.")] 28 29 public class DataCompletenessChartContent : Item, IViewShortcut {29 [StorableClass] 30 public class DataCompletenessChartContent : PreprocessingContent, IViewShortcut { 30 31 public static new Image StaticItemImage { 31 32 get { return HeuristicLab.Common.Resources.VSImageLibrary.EditBrightnessContrast; } 32 33 } 33 34 34 public SearchLogic SearchLogic { get; private set; } 35 36 public DataCompletenessChartContent(SearchLogic searchLogic) { 37 SearchLogic = searchLogic; 35 #region Constructor, Cloning & Persistence 36 public DataCompletenessChartContent(IFilteredPreprocessingData preprocessingData) 37 : base(preprocessingData) { 38 38 } 39 39 40 40 public DataCompletenessChartContent(DataCompletenessChartContent content, Cloner cloner) 41 41 : base(content, cloner) { 42 SearchLogic = content.SearchLogic;43 42 } 44 45 43 public override IDeepCloneable Clone(Cloner cloner) { 46 44 return new DataCompletenessChartContent(this, cloner); 47 45 } 46 47 [StorableConstructor] 48 protected DataCompletenessChartContent(bool deserializing) 49 : base(deserializing) { } 50 #endregion 48 51 } 49 52 } -
stable/HeuristicLab.DataPreprocessing/3.4/Content/DataGridContent.cs
r15242 r15535 27 27 using HeuristicLab.Core; 28 28 using HeuristicLab.Data; 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 using HeuristicLab.Random; 29 31 30 32 namespace HeuristicLab.DataPreprocessing { 31 32 33 [Item("Data Grid", "Represents a data grid.")] 33 public class DataGridContent : Item, IStringConvertibleMatrix, IViewShortcut { 34 [StorableClass] 35 public class DataGridContent : PreprocessingContent, IStringConvertibleMatrix, IViewShortcut { 34 36 public static new Image StaticItemImage { 35 37 get { return HeuristicLab.Common.Resources.VSImageLibrary.Table; } 36 38 } 37 39 38 public ITransactionalPreprocessingData PreProcessingData { get; private set; }39 40 public ManipulationLogic ManipulationLogic { get; private set; }41 public FilterLogic FilterLogic { get; private set; }42 43 40 public int Rows { 44 get { return Pre ProcessingData.Rows; }41 get { return PreprocessingData.Rows; } 45 42 set { } 46 43 } 47 44 48 45 public int Columns { 49 get { return Pre ProcessingData.Columns; }46 get { return PreprocessingData.Columns; } 50 47 set { } 51 48 } 52 49 53 50 public IEnumerable<string> ColumnNames { 54 get { return Pre ProcessingData.VariableNames; }51 get { return PreprocessingData.VariableNames; } 55 52 set { } 56 53 } … … 71 68 72 69 public IDictionary<int, IList<int>> Selection { 73 get { return PreProcessingData.Selection; } 74 set { PreProcessingData.Selection = value; } 75 } 76 77 public DataGridContent(ITransactionalPreprocessingData preProcessingData, ManipulationLogic theManipulationLogic, FilterLogic theFilterLogic) { 78 ManipulationLogic = theManipulationLogic; 79 FilterLogic = theFilterLogic; 80 PreProcessingData = preProcessingData; 81 } 82 83 public DataGridContent(DataGridContent dataGridContent, Cloner cloner) 84 : base(dataGridContent, cloner) { 85 70 get { return PreprocessingData.Selection; } 71 set { PreprocessingData.Selection = value; } 72 } 73 74 #region Constructor, Cloning & Persistence 75 public DataGridContent(IFilteredPreprocessingData preprocessingData) 76 : base(preprocessingData) { 77 } 78 79 public DataGridContent(DataGridContent original, Cloner cloner) 80 : base(original, cloner) { 86 81 } 87 82 public override IDeepCloneable Clone(Cloner cloner) { … … 89 84 } 90 85 86 [StorableConstructor] 87 protected DataGridContent(bool deserializing) 88 : base(deserializing) { } 89 #endregion 90 91 91 public void DeleteRows(IEnumerable<int> rows) { 92 Pre ProcessingData.DeleteRowsWithIndices(rows);92 PreprocessingData.DeleteRowsWithIndices(rows); 93 93 } 94 94 95 95 public void DeleteColumn(int column) { 96 Pre ProcessingData.DeleteColumn(column);96 PreprocessingData.DeleteColumn(column); 97 97 } 98 98 99 99 public bool Validate(string value, out string errorMessage, int columnIndex) { 100 return Pre ProcessingData.Validate(value, out errorMessage, columnIndex);100 return PreprocessingData.Validate(value, out errorMessage, columnIndex); 101 101 } 102 102 103 103 public string GetValue(int rowIndex, int columnIndex) { 104 return Pre ProcessingData.GetCellAsString(columnIndex, rowIndex);104 return PreprocessingData.GetCellAsString(columnIndex, rowIndex); 105 105 } 106 106 107 107 public bool SetValue(string value, int rowIndex, int columnIndex) { 108 return Pre ProcessingData.SetValue(value, columnIndex, rowIndex);108 return PreprocessingData.SetValue(value, columnIndex, rowIndex); 109 109 } 110 110 111 111 public event DataPreprocessingChangedEventHandler Changed { 112 add { Pre ProcessingData.Changed += value; }113 remove { Pre ProcessingData.Changed -= value; }112 add { PreprocessingData.Changed += value; } 113 remove { PreprocessingData.Changed -= value; } 114 114 } 115 115 … … 132 132 #pragma warning restore 0067 133 133 #endregion 134 135 #region Manipulations 136 private void ReplaceIndicesByValue(IDictionary<int, IList<int>> cells, Func<int, double> doubleAggregator = null, 137 Func<int, DateTime> dateTimeAggregator = null, Func<int, string> stringAggregator = null) { 138 PreprocessingData.InTransaction(() => { 139 foreach (var column in cells) { 140 if (doubleAggregator != null && PreprocessingData.VariableHasType<double>(column.Key)) { 141 var value = doubleAggregator(column.Key); 142 foreach (int index in column.Value) 143 PreprocessingData.SetCell<double>(column.Key, index, value); 144 } else if (dateTimeAggregator != null && PreprocessingData.VariableHasType<DateTime>(column.Key)) { 145 var value = dateTimeAggregator(column.Key); 146 foreach (int index in column.Value) 147 PreprocessingData.SetCell<DateTime>(column.Key, index, value); 148 } else if (stringAggregator != null && PreprocessingData.VariableHasType<string>(column.Key)) { 149 var value = stringAggregator(column.Key); 150 foreach (int index in column.Value) 151 PreprocessingData.SetCell<string>(column.Key, index, value); 152 } 153 } 154 }); 155 } 156 157 private void ReplaceIndicesByValues(IDictionary<int, IList<int>> cells, Func<int, IEnumerable<double>> doubleAggregator = null, 158 Func<int, IEnumerable<DateTime>> dateTimeAggregator = null, Func<int, IEnumerable<string>> stringAggregator = null) { 159 PreprocessingData.InTransaction(() => { 160 foreach (var column in cells) { 161 if (doubleAggregator != null && PreprocessingData.VariableHasType<double>(column.Key)) { 162 var values = doubleAggregator(column.Key); 163 foreach (var pair in column.Value.Zip(values, (row, value) => new { row, value })) 164 PreprocessingData.SetCell<double>(column.Key, pair.row, pair.value); 165 } else if (dateTimeAggregator != null && PreprocessingData.VariableHasType<DateTime>(column.Key)) { 166 var values = dateTimeAggregator(column.Key); 167 foreach (var pair in column.Value.Zip(values, (row, value) => new { row, value })) 168 PreprocessingData.SetCell<DateTime>(column.Key, pair.row, pair.value); 169 } else if (stringAggregator != null && PreprocessingData.VariableHasType<string>(column.Key)) { 170 var values = stringAggregator(column.Key); 171 foreach (var pair in column.Value.Zip(values, (row, value) => new { row, value })) 172 PreprocessingData.SetCell<string>(column.Key, pair.row, pair.value); 173 } 174 } 175 }); 176 } 177 178 public void ReplaceIndicesByMean(IDictionary<int, IList<int>> cells, bool considerSelection = false) { 179 ReplaceIndicesByValue(cells, 180 col => PreprocessingData.GetMean<double>(col, considerSelection), 181 col => PreprocessingData.GetMean<DateTime>(col, considerSelection)); 182 } 183 184 public void ReplaceIndicesByMedianValue(IDictionary<int, IList<int>> cells, bool considerSelection = false) { 185 ReplaceIndicesByValue(cells, 186 col => PreprocessingData.GetMedian<double>(col, considerSelection), 187 col => PreprocessingData.GetMedian<DateTime>(col, considerSelection)); 188 } 189 190 public void ReplaceIndicesByMode(IDictionary<int, IList<int>> cells, bool considerSelection = false) { 191 ReplaceIndicesByValue(cells, 192 col => PreprocessingData.GetMode<double>(col, considerSelection), 193 col => PreprocessingData.GetMode<DateTime>(col, considerSelection), 194 col => PreprocessingData.GetMode<string>(col, considerSelection)); 195 } 196 197 public void ReplaceIndicesByRandomValue(IDictionary<int, IList<int>> cells, bool considerSelection = false) { 198 var rand = new FastRandom(); 199 ReplaceIndicesByValues(cells, 200 col => { 201 double min = PreprocessingData.GetMin<double>(col, considerSelection); 202 double max = PreprocessingData.GetMax<double>(col, considerSelection); 203 double range = max - min; 204 return cells[col].Select(_ => rand.NextDouble() * range + min); 205 }, 206 col => { 207 var min = PreprocessingData.GetMin<DateTime>(col, considerSelection); 208 var max = PreprocessingData.GetMax<DateTime>(col, considerSelection); 209 double range = (max - min).TotalSeconds; 210 return cells[col].Select(_ => min + TimeSpan.FromSeconds(rand.NextDouble() * range)); 211 }); 212 } 213 214 public void ReplaceIndicesByString(IDictionary<int, IList<int>> cells, string value) { 215 PreprocessingData.InTransaction(() => { 216 foreach (var column in cells) { 217 foreach (var rowIdx in column.Value) { 218 PreprocessingData.SetValue(value, column.Key, rowIdx); 219 } 220 } 221 }); 222 } 223 224 225 public void ReplaceIndicesByLinearInterpolationOfNeighbours(IDictionary<int, IList<int>> cells) { 226 PreprocessingData.InTransaction(() => { 227 foreach (var column in cells) { 228 IList<Tuple<int, int>> startEndings = GetStartAndEndingsForInterpolation(column); 229 foreach (var tuple in startEndings) { 230 Interpolate(column, tuple.Item1, tuple.Item2); 231 } 232 } 233 }); 234 } 235 236 private List<Tuple<int, int>> GetStartAndEndingsForInterpolation(KeyValuePair<int, IList<int>> column) { 237 var startEndings = new List<Tuple<int, int>>(); 238 var rowIndices = column.Value.OrderBy(x => x).ToList(); 239 var count = rowIndices.Count; 240 int start = int.MinValue; 241 for (int i = 0; i < count; ++i) { 242 if (start == int.MinValue) { 243 start = IndexOfPrevPresentValue(column.Key, rowIndices[i]); 244 } 245 if (i + 1 == count || (i + 1 < count && rowIndices[i + 1] - rowIndices[i] > 1)) { 246 int next = IndexOfNextPresentValue(column.Key, rowIndices[i]); 247 if (start > 0 && next < PreprocessingData.Rows) { 248 startEndings.Add(new Tuple<int, int>(start, next)); 249 } 250 start = int.MinValue; 251 } 252 } 253 return startEndings; 254 } 255 256 private void Interpolate(KeyValuePair<int, IList<int>> column, int prevIndex, int nextIndex) { 257 int valuesToInterpolate = nextIndex - prevIndex; 258 259 if (PreprocessingData.VariableHasType<double>(column.Key)) { 260 double prev = PreprocessingData.GetCell<double>(column.Key, prevIndex); 261 double next = PreprocessingData.GetCell<double>(column.Key, nextIndex); 262 double interpolationStep = (next - prev) / valuesToInterpolate; 263 264 for (int i = prevIndex; i < nextIndex; ++i) { 265 double interpolated = prev + (interpolationStep * (i - prevIndex)); 266 PreprocessingData.SetCell<double>(column.Key, i, interpolated); 267 } 268 } else if (PreprocessingData.VariableHasType<DateTime>(column.Key)) { 269 DateTime prev = PreprocessingData.GetCell<DateTime>(column.Key, prevIndex); 270 DateTime next = PreprocessingData.GetCell<DateTime>(column.Key, nextIndex); 271 double interpolationStep = (next - prev).TotalSeconds / valuesToInterpolate; 272 273 for (int i = prevIndex; i < nextIndex; ++i) { 274 DateTime interpolated = prev.AddSeconds(interpolationStep * (i - prevIndex)); 275 PreprocessingData.SetCell<DateTime>(column.Key, i, interpolated); 276 } 277 } 278 } 279 280 private int IndexOfPrevPresentValue(int columnIndex, int start) { 281 int offset = start - 1; 282 while (offset >= 0 && PreprocessingData.IsCellEmpty(columnIndex, offset)) { 283 offset--; 284 } 285 286 return offset; 287 } 288 289 private int IndexOfNextPresentValue(int columnIndex, int start) { 290 int offset = start + 1; 291 while (offset < PreprocessingData.Rows && PreprocessingData.IsCellEmpty(columnIndex, offset)) { 292 offset++; 293 } 294 295 return offset; 296 } 297 298 public void Shuffle(bool shuffleRangesSeparately) { 299 var random = new FastRandom(); 300 301 if (shuffleRangesSeparately) { 302 var ranges = new[] { PreprocessingData.TestPartition, PreprocessingData.TrainingPartition }; 303 PreprocessingData.InTransaction(() => { 304 // process all given ranges - e.g. TrainingPartition, TestPartition 305 foreach (IntRange range in ranges) { 306 var indices = Enumerable.Range(0, PreprocessingData.Rows).ToArray(); 307 var shuffledIndices = Enumerable.Range(range.Start, range.Size).Shuffle(random).ToArray(); 308 for (int i = range.Start, j = 0; i < range.End; i++, j++) 309 indices[i] = shuffledIndices[j]; 310 311 ReOrderToIndices(indices); 312 } 313 }); 314 315 } else { 316 PreprocessingData.InTransaction(() => { 317 var indices = Enumerable.Range(0, PreprocessingData.Rows).ToArray(); 318 indices.ShuffleInPlace(random); 319 ReOrderToIndices(indices); 320 }); 321 } 322 } 323 324 public void ReOrderToIndices(int[] indices) { 325 PreprocessingData.InTransaction(() => { 326 for (int i = 0; i < PreprocessingData.Columns; ++i) { 327 if (PreprocessingData.VariableHasType<double>(i)) 328 ReOrderToIndices<double>(i, indices); 329 else if (PreprocessingData.VariableHasType<string>(i)) 330 ReOrderToIndices<string>(i, indices); 331 else if (PreprocessingData.VariableHasType<DateTime>(i)) 332 ReOrderToIndices<DateTime>(i, indices); 333 } 334 }); 335 } 336 337 private void ReOrderToIndices<T>(int columnIndex, int[] indices) { 338 var originalData = new List<T>(PreprocessingData.GetValues<T>(columnIndex)); 339 if (indices.Length != originalData.Count) throw new InvalidOperationException("The number of provided indices does not match the values."); 340 341 for (int i = 0; i < indices.Length; i++) { 342 T newValue = originalData[indices[i]]; 343 PreprocessingData.SetCell<T>(columnIndex, i, newValue); 344 } 345 } 346 #endregion 134 347 } 135 348 } -
stable/HeuristicLab.DataPreprocessing/3.4/Content/FilterContent.cs
r15242 r15535 20 20 #endregion 21 21 22 using System.Collections.Generic; 22 23 using System.Drawing; 24 using System.Linq; 23 25 using HeuristicLab.Common; 24 26 using HeuristicLab.Core; 25 27 using HeuristicLab.DataPreprocessing.Filter; 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 29 27 30 namespace HeuristicLab.DataPreprocessing { 28 31 [Item("Filter", "Represents the filter grid.")] 29 public class FilterContent : Item, IViewShortcut { 32 [StorableClass] 33 public class FilterContent : PreprocessingContent, IViewShortcut { 30 34 public static new Image StaticItemImage { 31 35 get { return HeuristicLab.Common.Resources.VSImageLibrary.Filter; } 32 36 } 33 34 public FilterLogic FilterLogic { get; private set; } 35 37 [Storable] 36 38 public ICheckedItemCollection<IFilter> Filters { get; private set; } 37 39 40 [Storable] 38 41 public bool IsAndCombination { get; set; } 39 42 40 public FilterContent(FilterLogic filterLogic) { 43 public IEnumerable<IFilter> ActiveFilters { 44 get { return Filters.Where(f => f.Active && f.ConstraintData != null); } 45 } 46 47 public bool[] GetRemainingRows() { 48 var remainingRows = new bool[PreprocessingData.Rows]; 49 if (ActiveFilters.Any()) { 50 var filterResults = ActiveFilters.Select(f => f.Check()).ToList(); 51 var rowFilterResults = new bool[filterResults.Count]; 52 for (int row = 0; row < remainingRows.Length; row++) { 53 for (int i = 0; i < filterResults.Count; i++) 54 rowFilterResults[i] = filterResults[i][row]; 55 56 remainingRows[row] = IsAndCombination 57 ? rowFilterResults.All(x => x) 58 : rowFilterResults.Any(x => x); 59 } 60 } else { 61 // if not filters active => all rows are remaining 62 for (int i = 0; i < remainingRows.Length; i++) 63 remainingRows[i] = true; 64 } 65 return remainingRows; 66 } 67 68 #region Constructor, Cloning & Persistence 69 public FilterContent(IFilteredPreprocessingData preprocessingData) 70 : base(preprocessingData) { 41 71 Filters = new CheckedItemCollection<IFilter>(); 42 72 IsAndCombination = true; 43 FilterLogic = filterLogic;44 73 } 45 74 46 protected FilterContent(FilterContent content, Cloner cloner) 47 : base(content, cloner) { 75 protected FilterContent(FilterContent original, Cloner cloner) 76 : base(original, cloner) { 77 Filters = cloner.Clone(original.Filters); 78 IsAndCombination = original.IsAndCombination; 48 79 } 49 50 80 public override IDeepCloneable Clone(Cloner cloner) { 51 81 return new FilterContent(this, cloner); 52 82 } 83 84 [StorableConstructor] 85 protected FilterContent(bool deserializing) 86 : base(deserializing) { } 87 #endregion 53 88 } 54 89 } -
stable/HeuristicLab.DataPreprocessing/3.4/Content/HistogramContent.cs
r15242 r15535 26 26 using HeuristicLab.Common; 27 27 using HeuristicLab.Core; 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 29 29 30 namespace HeuristicLab.DataPreprocessing { 30 31 [Item("Histogram", "Represents the histogram grid.")] 32 [StorableClass] 31 33 public class HistogramContent : PreprocessingChartContent { 32 34 public static new Image StaticItemImage { … … 34 36 } 35 37 38 [Storable] 36 39 public string GroupingVariableName { get; set; } 37 40 41 [Storable] 38 42 public int Bins { get; set; } 43 [Storable] 39 44 public bool ExactBins { get; set; } 40 45 46 [Storable] 41 47 public LegendOrder Order { get; set; } 42 48 49 #region Constructor, Cloning & Persistence 43 50 public HistogramContent(IFilteredPreprocessingData preprocessingData) 44 51 : base(preprocessingData) { … … 47 54 } 48 55 49 public HistogramContent(HistogramContent content, Cloner cloner) 50 : base(content, cloner) { 56 public HistogramContent(HistogramContent original, Cloner cloner) 57 : base(original, cloner) { 58 GroupingVariableName = original.GroupingVariableName; 59 Bins = original.Bins; 60 ExactBins = original.ExactBins; 61 Order = original.Order; 51 62 } 52 63 public override IDeepCloneable Clone(Cloner cloner) { 53 64 return new HistogramContent(this, cloner); 54 65 } 66 67 [StorableConstructor] 68 protected HistogramContent(bool deserializing) 69 : base(deserializing) { } 70 #endregion 55 71 56 72 public static DataTable CreateHistogram(IFilteredPreprocessingData preprocessingData, string variableName, string groupingVariableName, DataTableVisualProperties.DataTableHistogramAggregation aggregation, LegendOrder legendOrder = LegendOrder.Alphabetically) { -
stable/HeuristicLab.DataPreprocessing/3.4/Content/LineChartContent.cs
r15242 r15535 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Core; 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 25 26 26 27 namespace HeuristicLab.DataPreprocessing { 27 28 28 [Item("Line Chart", "Represents the line chart grid.")] 29 [StorableClass] 29 30 public class LineChartContent : PreprocessingChartContent { 30 public bool AllInOneMode { get; set; }31 32 31 public static new Image StaticItemImage { 33 32 get { return HeuristicLab.Common.Resources.VSImageLibrary.Performance; } 34 33 } 35 34 35 [Storable] 36 public bool AllInOneMode { get; set; } 37 38 39 #region Constructor, Cloning & Persistence 36 40 public LineChartContent(IFilteredPreprocessingData preprocessingData) 37 41 : base(preprocessingData) { … … 39 43 } 40 44 41 public LineChartContent(LineChartContent content, Cloner cloner)42 : base( content, cloner) {43 this.AllInOneMode = content.AllInOneMode;45 public LineChartContent(LineChartContent original, Cloner cloner) 46 : base(original, cloner) { 47 AllInOneMode = original.AllInOneMode; 44 48 } 45 49 public override IDeepCloneable Clone(Cloner cloner) { 46 50 return new LineChartContent(this, cloner); 47 51 } 52 53 [StorableConstructor] 54 protected LineChartContent(bool deserializing) 55 : base(deserializing) { } 56 #endregion 48 57 } 49 58 } -
stable/HeuristicLab.DataPreprocessing/3.4/Content/ManipulationContent.cs
r15242 r15535 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 22 24 using System.Drawing; 25 using System.Linq; 23 26 using HeuristicLab.Common; 24 27 using HeuristicLab.Core; 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 25 29 26 30 namespace HeuristicLab.DataPreprocessing { 27 28 31 [Item("Manipulation", "Represents the available manipulations on a data set.")] 29 public class ManipulationContent : Item, IViewShortcut { 32 [StorableClass] 33 public class ManipulationContent : PreprocessingContent, IViewShortcut { 30 34 public static new Image StaticItemImage { 31 35 get { return HeuristicLab.Common.Resources.VSImageLibrary.Method; } 32 36 } 33 37 34 public ManipulationLogic ManipulationLogic { get; private set; } 35 public SearchLogic SearchLogic { get; private set; } 36 public FilterLogic FilterLogic { get; private set; } 37 38 public ManipulationContent(ManipulationLogic manipulationLogic, SearchLogic searchLogic, FilterLogic filterLogic) { 39 ManipulationLogic = manipulationLogic; 40 SearchLogic = searchLogic; 41 FilterLogic = filterLogic; 38 #region Constructor, Cloning & Persistence 39 public ManipulationContent(IFilteredPreprocessingData preprocessingData) 40 : base(preprocessingData) { 42 41 } 43 42 44 public ManipulationContent(ManipulationContent content, Cloner cloner) : base(content, cloner) { } 45 43 public ManipulationContent(ManipulationContent original, Cloner cloner) : 44 base(original, cloner) { 45 } 46 46 public override IDeepCloneable Clone(Cloner cloner) { 47 47 return new ManipulationContent(this, cloner); 48 48 } 49 50 [StorableConstructor] 51 protected ManipulationContent(bool deserializing) 52 : base(deserializing) { } 53 #endregion 54 55 public List<int> RowsWithMissingValuesGreater(double percent) { 56 List<int> rows = new List<int>(); 57 58 for (int i = 0; i < PreprocessingData.Rows; ++i) { 59 int missingCount = PreprocessingData.GetRowMissingValueCount(i); 60 if (100f / PreprocessingData.Columns * missingCount > percent) { 61 rows.Add(i); 62 } 63 } 64 65 return rows; 66 } 67 68 public List<int> ColumnsWithMissingValuesGreater(double percent) { 69 List<int> columns = new List<int>(); 70 for (int i = 0; i < PreprocessingData.Columns; ++i) { 71 int missingCount = PreprocessingData.GetMissingValueCount(i); 72 if (100f / PreprocessingData.Rows * missingCount > percent) { 73 columns.Add(i); 74 } 75 } 76 77 return columns; 78 } 79 80 public List<int> ColumnsWithVarianceSmaller(double variance) { 81 List<int> columns = new List<int>(); 82 for (int i = 0; i < PreprocessingData.Columns; ++i) { 83 if (PreprocessingData.VariableHasType<double>(i)) { 84 double columnVariance = PreprocessingData.GetVariance<double>(i); 85 if (columnVariance < variance) { 86 columns.Add(i); 87 } 88 } else if (PreprocessingData.VariableHasType<DateTime>(i)) { 89 double columnVariance = (double)PreprocessingData.GetVariance<DateTime>(i).Ticks / TimeSpan.TicksPerSecond; 90 if (columnVariance < variance) { 91 columns.Add(i); 92 } 93 } 94 } 95 return columns; 96 } 97 98 public void DeleteRowsWithMissingValuesGreater(double percent) { 99 DeleteRows(RowsWithMissingValuesGreater(percent)); 100 } 101 102 public void DeleteColumnsWithMissingValuesGreater(double percent) { 103 DeleteColumns(ColumnsWithMissingValuesGreater(percent)); 104 } 105 106 public void DeleteColumnsWithVarianceSmaller(double variance) { 107 DeleteColumns(ColumnsWithVarianceSmaller(variance)); 108 } 109 110 private void DeleteRows(List<int> rows) { 111 PreprocessingData.InTransaction(() => { 112 foreach (int row in rows.OrderByDescending(x => x)) { 113 PreprocessingData.DeleteRow(row); 114 } 115 }); 116 } 117 118 private void DeleteColumns(List<int> columns) { 119 PreprocessingData.InTransaction(() => { 120 foreach (int column in columns.OrderByDescending(x => x)) { 121 PreprocessingData.DeleteColumn(column); 122 } 123 }); 124 } 49 125 } 50 126 } -
stable/HeuristicLab.DataPreprocessing/3.4/Content/MultiScatterPlotContent.cs
r15242 r15535 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Core; 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 25 26 26 27 namespace HeuristicLab.DataPreprocessing { 27 28 28 [Item("Multi Scatter Plot", "Represents a multi scatter plot.")] 29 [StorableClass] 29 30 public class MultiScatterPlotContent : ScatterPlotContent { 30 31 public static new Image StaticItemImage { … … 32 33 } 33 34 35 #region Constructor, Cloning & Persistence 34 36 public MultiScatterPlotContent(IFilteredPreprocessingData preprocessingData) 35 37 : base(preprocessingData) { 36 38 } 37 39 38 public MultiScatterPlotContent(MultiScatterPlotContent content, Cloner cloner)39 : base( content, cloner) {40 public MultiScatterPlotContent(MultiScatterPlotContent original, Cloner cloner) 41 : base(original, cloner) { 40 42 } 41 42 43 public override IDeepCloneable Clone(Cloner cloner) { 43 44 return new MultiScatterPlotContent(this, cloner); 44 45 } 46 47 [StorableConstructor] 48 protected MultiScatterPlotContent(bool deserializing) 49 : base(deserializing) { } 50 #endregion 45 51 } 46 52 } -
stable/HeuristicLab.DataPreprocessing/3.4/Content/PreprocessingChartContent.cs
r15242 r15535 29 29 using HeuristicLab.Core; 30 30 using HeuristicLab.Data; 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 32 32 33 namespace HeuristicLab.DataPreprocessing { 33 34 [Item("PreprocessingChart", "Represents a preprocessing chart.")] 34 public class PreprocessingChartContent : Item, IViewShortcut { 35 [StorableClass] 36 public class PreprocessingChartContent : PreprocessingContent, IViewShortcut { 35 37 public enum LegendOrder { 36 38 Alphabetically, … … 42 44 } 43 45 44 private ICheckedItemList<StringValue> variableItemList = null; 46 [Storable] 47 private ICheckedItemList<StringValue> variableItemList; 45 48 public ICheckedItemList<StringValue> VariableItemList { 46 49 get { 47 50 if (variableItemList == null) 48 51 variableItemList = CreateVariableItemList(PreprocessingData); 49 return this.variableItemList;52 return variableItemList; 50 53 } 51 54 } 52 55 53 public IFilteredPreprocessingData PreprocessingData { get; private set; }54 56 public event DataPreprocessingChangedEventHandler Changed { 55 57 add { PreprocessingData.Changed += value; } … … 57 59 } 58 60 59 public PreprocessingChartContent(IFilteredPreprocessingData preprocessingData) { 60 PreprocessingData = preprocessingData; 61 #region Constructor, Cloning & Persistence 62 public PreprocessingChartContent(IFilteredPreprocessingData preprocessingData) 63 : base(preprocessingData) { 61 64 } 62 65 63 public PreprocessingChartContent(PreprocessingChartContent content, Cloner cloner) 64 : base(content, cloner) { 65 this.PreprocessingData = content.PreprocessingData; 66 this.variableItemList = cloner.Clone<ICheckedItemList<StringValue>>(variableItemList); 66 public PreprocessingChartContent(PreprocessingChartContent original, Cloner cloner) 67 : base(original, cloner) { 68 variableItemList = cloner.Clone(original.variableItemList); 67 69 } 68 70 public override IDeepCloneable Clone(Cloner cloner) { 69 71 return new PreprocessingChartContent(this, cloner); 70 72 } 73 74 [StorableConstructor] 75 protected PreprocessingChartContent(bool deserializing) 76 : base(deserializing) { } 77 #endregion 71 78 72 79 public DataRow CreateDataRow(string variableName, DataRowVisualProperties.DataRowChartType chartType) { … … 75 82 76 83 public static DataRow CreateDataRow(IFilteredPreprocessingData preprocessingData, string variableName, DataRowVisualProperties.DataRowChartType chartType) { 77 IList<double> values = preprocessingData.GetValues<double>(preprocessingData.GetColumnIndex(variableName)); 78 DataRow row = new DataRow(variableName, "", values); 79 row.VisualProperties.ChartType = chartType; 84 var values = preprocessingData.GetValues<double>(preprocessingData.GetColumnIndex(variableName)); 85 var row = new DataRow(variableName, "", values) { 86 VisualProperties = { 87 ChartType = chartType, 88 StartIndexZero = true 89 } 90 }; 80 91 return row; 81 92 } -
stable/HeuristicLab.DataPreprocessing/3.4/Content/ScatterPlotContent.cs
r15242 r15535 25 25 using HeuristicLab.Analysis; 26 26 using HeuristicLab.Common; 27 using HeuristicLab.Core; 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 29 using HeuristicLab.Visualization.ChartControlsExtensions; 28 30 29 31 namespace HeuristicLab.DataPreprocessing { 30 32 [Item("ScatterPlotContent", "")] 33 [StorableClass] 31 34 public abstract class ScatterPlotContent : PreprocessingChartContent { 35 [Storable] 32 36 public string GroupingVariable { get; set; } 33 37 38 #region Constructor, Cloning & Persistence 34 39 protected ScatterPlotContent(IFilteredPreprocessingData preprocessingData) 35 40 : base(preprocessingData) { 36 41 } 37 42 38 protected ScatterPlotContent(ScatterPlotContent content, Cloner cloner) 39 : base(content, cloner) { 43 protected ScatterPlotContent(ScatterPlotContent original, Cloner cloner) 44 : base(original, cloner) { 45 GroupingVariable = original.GroupingVariable; 40 46 } 47 48 [StorableConstructor] 49 protected ScatterPlotContent(bool deserializing) 50 : base(deserializing) { } 51 #endregion 41 52 42 53 public static ScatterPlot CreateScatterPlot(IFilteredPreprocessingData preprocessingData, string variableNameX, string variableNameY, string variableNameGroup = "-", LegendOrder legendOrder = LegendOrder.Alphabetically) { -
stable/HeuristicLab.DataPreprocessing/3.4/Content/SingleScatterPlotContent.cs
r15242 r15535 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Core; 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 25 26 26 27 namespace HeuristicLab.DataPreprocessing { 27 28 28 [Item("Scatter Plot", "Represents a scatter plot.")] 29 [StorableClass] 29 30 public class SingleScatterPlotContent : ScatterPlotContent { 30 31 public static new Image StaticItemImage { … … 32 33 } 33 34 35 [Storable] 34 36 public string SelectedXVariable { get; set; } 37 [Storable] 35 38 public string SelectedYVariable { get; set; } 36 39 40 #region Constructor, Cloning & Persistence 37 41 public SingleScatterPlotContent(IFilteredPreprocessingData preprocessingData) 38 42 : base(preprocessingData) { 39 43 } 40 44 41 public SingleScatterPlotContent(SingleScatterPlotContent content, Cloner cloner) 42 : base(content, cloner) { 43 this.SelectedXVariable = content.SelectedXVariable; 44 this.SelectedYVariable = content.SelectedYVariable; 45 this.GroupingVariable = content.GroupingVariable; 45 public SingleScatterPlotContent(SingleScatterPlotContent original, Cloner cloner) 46 : base(original, cloner) { 47 SelectedXVariable = original.SelectedXVariable; 48 SelectedYVariable = original.SelectedYVariable; 46 49 } 47 48 50 public override IDeepCloneable Clone(Cloner cloner) { 49 51 return new SingleScatterPlotContent(this, cloner); 50 52 } 53 54 [StorableConstructor] 55 protected SingleScatterPlotContent(bool deserializing) 56 : base(deserializing) { } 57 #endregion 51 58 } 52 59 } -
stable/HeuristicLab.DataPreprocessing/3.4/Content/StatisticsContent.cs
r15242 r15535 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Core; 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 25 26 26 27 namespace HeuristicLab.DataPreprocessing { 27 28 [Item("Statistics", "Represents the statistics grid.")] 28 public class StatisticsContent : Item, IViewShortcut { 29 [StorableClass] 30 public class StatisticsContent : PreprocessingContent, IViewShortcut { 29 31 public static new Image StaticItemImage { 30 32 get { return HeuristicLab.Common.Resources.VSImageLibrary.Object; } 31 33 } 32 34 33 public ITransactionalPreprocessingData PreprocessingData { get; private set; } 34 public StatisticsLogic StatisticsLogic { get; private set; } 35 36 public StatisticsContent(ITransactionalPreprocessingData preProcessingData, StatisticsLogic statisticsLogic) { 37 PreprocessingData = preProcessingData; 38 StatisticsLogic = statisticsLogic; 35 #region Constructor, Cloning & Persistence 36 public StatisticsContent(IFilteredPreprocessingData preprocessingData) 37 : base(preprocessingData) { 39 38 } 40 39 41 public StatisticsContent(StatisticsContent content, Cloner cloner)42 : base( content, cloner) {40 public StatisticsContent(StatisticsContent original, Cloner cloner) 41 : base(original, cloner) { 43 42 } 44 45 43 public override IDeepCloneable Clone(Cloner cloner) { 46 44 return new StatisticsContent(this, cloner); 47 45 } 48 46 47 [StorableConstructor] 48 protected StatisticsContent(bool deserializing) 49 : base(deserializing) { } 50 #endregion 51 49 52 public event DataPreprocessingChangedEventHandler Changed { 50 add { StatisticsLogic.Changed += value; }51 remove { StatisticsLogic.Changed -= value; }53 add { PreprocessingData.Changed += value; } 54 remove { PreprocessingData.Changed -= value; } 52 55 } 53 56 } -
stable/HeuristicLab.DataPreprocessing/3.4/Content/TransformationContent.cs
r15242 r15535 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Core; 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 25 26 using HeuristicLab.Problems.DataAnalysis; 26 27 27 28 namespace HeuristicLab.DataPreprocessing { 28 29 [Item("Transformation", "Represents the transformation grid.")] 29 public class TransformationContent : Item, IViewShortcut { 30 [StorableClass] 31 public class TransformationContent : PreprocessingContent, IViewShortcut { 30 32 public static new Image StaticItemImage { 31 33 get { return HeuristicLab.Common.Resources.VSImageLibrary.Method; } 32 34 } 33 35 34 public IPreprocessingData Data { get; private set; } 35 public FilterLogic FilterLogic { get; private set; } 36 36 [Storable] 37 37 public ICheckedItemList<ITransformation> CheckedTransformationList { get; private set; } 38 38 39 public TransformationContent(IPreprocessingData data, FilterLogic filterLogic) { 40 Data = data; 39 #region Constructor, Cloning & Persistence 40 public TransformationContent(IFilteredPreprocessingData preprocessingData) 41 : base(preprocessingData) { 41 42 CheckedTransformationList = new CheckedItemList<ITransformation>(); 42 FilterLogic = filterLogic;43 43 } 44 44 45 45 public TransformationContent(TransformationContent original, Cloner cloner) 46 46 : base(original, cloner) { 47 Data = original.Data; 48 CheckedTransformationList = new CheckedItemList<ITransformation>(original.CheckedTransformationList); 47 CheckedTransformationList = cloner.Clone(original.CheckedTransformationList); 49 48 } 50 51 49 public override IDeepCloneable Clone(Cloner cloner) { 52 50 return new TransformationContent(this, cloner); 53 51 } 52 53 [StorableConstructor] 54 protected TransformationContent(bool deserializing) 55 : base(deserializing) { } 56 #endregion 54 57 } 55 58 }
Note: See TracChangeset
for help on using the changeset viewer.