1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System.Collections.Generic;
|
---|
23 | using System.Linq;
|
---|
24 | using System.Windows.Forms;
|
---|
25 | using HeuristicLab.DataImporter.Data;
|
---|
26 | using HeuristicLab.DataImporter.Data.CommandBase;
|
---|
27 | using HeuristicLab.DataImporter.Data.Model;
|
---|
28 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
29 | using HEAL.Attic;
|
---|
30 |
|
---|
31 | namespace HeuristicLab.DataImporter.Command {
|
---|
32 | [StorableType("87E0EA6E-EC45-492B-8F4B-B15B25A467E9")]
|
---|
33 | [ViewableCommandInfoAttribute("Mean", 1, ColumnGroupState.DoubleColumnSelected | ColumnGroupState.AnySelectedColumnContainsNull,
|
---|
34 | "Handle Missing Values", Position = 0)]
|
---|
35 | public class FillMissingValuesWithMeanCommand : FillMissingValueCommandBase {
|
---|
36 | [StorableConstructor]
|
---|
37 | protected FillMissingValuesWithMeanCommand(bool deserializing) : base(deserializing) { }
|
---|
38 | public FillMissingValuesWithMeanCommand(DataSet dataSet, string columnGroupName, int[] affectedColumns) :
|
---|
39 | base(dataSet, columnGroupName, affectedColumns) {
|
---|
40 | }
|
---|
41 |
|
---|
42 | public override void Execute() {
|
---|
43 | base.Execute();
|
---|
44 | DoubleColumn column;
|
---|
45 | double? mean;
|
---|
46 | oldSortOrder = ColumnGroup.SortOrdersForColumns.ToList();
|
---|
47 | oldSortedColumnIndexes = new List<int>(ColumnGroup.SortedColumnIndexes);
|
---|
48 | foreach (int col in AffectedColumns) {
|
---|
49 | if (ColumnGroup.GetColumn(col) is DoubleColumn && ColumnGroup.GetColumn(col).ContainsNullValues) {
|
---|
50 | column = (DoubleColumn)ColumnGroup.Columns.ElementAt(col);
|
---|
51 | if (column.SortOrder != SortOrder.None)
|
---|
52 | ColumnGroup.ResetSorting();
|
---|
53 | nullValues.Add(col, new List<int>());
|
---|
54 | mean = column.Mean;
|
---|
55 | for (int j = 0; j < column.TotalValuesCount; j++) {
|
---|
56 | if (column.GetValue(j) == null) {
|
---|
57 | column.ChangeValue(j, mean);
|
---|
58 | this.nullValues[col].Add(j);
|
---|
59 | }
|
---|
60 | }
|
---|
61 | }
|
---|
62 | }
|
---|
63 | ColumnGroup.FireChanged();
|
---|
64 | ColumnGroup = null;
|
---|
65 | }
|
---|
66 |
|
---|
67 | public override string Description {
|
---|
68 | get { return "Fill missing values with mean"; }
|
---|
69 | }
|
---|
70 | }
|
---|
71 | }
|
---|