Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.DataPreprocessing/3.4/Content/ManipulationContent.cs @ 17507

Last change on this file since 17507 was 17180, checked in by swagner, 5 years ago

#2875: Removed years in copyrights

File size: 4.3 KB
RevLine 
[10709]1#region License Information
2/* HeuristicLab
[17180]3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[10709]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
[15518]22using System;
23using System.Collections.Generic;
[10709]24using System.Drawing;
[15518]25using System.Linq;
[10709]26using HeuristicLab.Common;
27using HeuristicLab.Core;
[16565]28using HEAL.Attic;
[10709]29
30namespace HeuristicLab.DataPreprocessing {
31  [Item("Manipulation", "Represents the available manipulations on a data set.")]
[16565]32  [StorableType("42EE7A94-807F-482D-BE64-F98B05896B16")]
[15518]33  public class ManipulationContent : PreprocessingContent, IViewShortcut {
[10970]34    public static new Image StaticItemImage {
35      get { return HeuristicLab.Common.Resources.VSImageLibrary.Method; }
36    }
37
[15518]38    #region Constructor, Cloning & Persistence
39    public ManipulationContent(IFilteredPreprocessingData preprocessingData)
40      : base(preprocessingData) {
41    }
[15110]42
[15518]43    public ManipulationContent(ManipulationContent original, Cloner cloner) :
44      base(original, cloner) {
[10709]45    }
46    public override IDeepCloneable Clone(Cloner cloner) {
47      return new ManipulationContent(this, cloner);
48    }
[15518]49
50    [StorableConstructor]
[16565]51    protected ManipulationContent(StorableConstructorFlag _) : base(_) { }
[15518]52    #endregion
53
54    public List<int> RowsWithMissingValuesGreater(double percent) {
55      List<int> rows = new List<int>();
56
57      for (int i = 0; i < PreprocessingData.Rows; ++i) {
58        int missingCount = PreprocessingData.GetRowMissingValueCount(i);
59        if (100f / PreprocessingData.Columns * missingCount > percent) {
60          rows.Add(i);
61        }
62      }
63
64      return rows;
65    }
66
67    public List<int> ColumnsWithMissingValuesGreater(double percent) {
68      List<int> columns = new List<int>();
69      for (int i = 0; i < PreprocessingData.Columns; ++i) {
70        int missingCount = PreprocessingData.GetMissingValueCount(i);
71        if (100f / PreprocessingData.Rows * missingCount > percent) {
72          columns.Add(i);
73        }
74      }
75
76      return columns;
77    }
78
79    public List<int> ColumnsWithVarianceSmaller(double variance) {
80      List<int> columns = new List<int>();
81      for (int i = 0; i < PreprocessingData.Columns; ++i) {
82        if (PreprocessingData.VariableHasType<double>(i)) {
83          double columnVariance = PreprocessingData.GetVariance<double>(i);
84          if (columnVariance < variance) {
85            columns.Add(i);
86          }
87        } else if (PreprocessingData.VariableHasType<DateTime>(i)) {
88          double columnVariance = (double)PreprocessingData.GetVariance<DateTime>(i).Ticks / TimeSpan.TicksPerSecond;
89          if (columnVariance < variance) {
90            columns.Add(i);
91          }
92        }
93      }
94      return columns;
95    }
96
97    public void DeleteRowsWithMissingValuesGreater(double percent) {
98      DeleteRows(RowsWithMissingValuesGreater(percent));
99    }
100
101    public void DeleteColumnsWithMissingValuesGreater(double percent) {
102      DeleteColumns(ColumnsWithMissingValuesGreater(percent));
103    }
104
105    public void DeleteColumnsWithVarianceSmaller(double variance) {
106      DeleteColumns(ColumnsWithVarianceSmaller(variance));
107    }
108
109    private void DeleteRows(List<int> rows) {
110      PreprocessingData.InTransaction(() => {
111        foreach (int row in rows.OrderByDescending(x => x)) {
112          PreprocessingData.DeleteRow(row);
113        }
114      });
115    }
116
117    private void DeleteColumns(List<int> columns) {
118      PreprocessingData.InTransaction(() => {
119        foreach (int column in columns.OrderByDescending(x => x)) {
120          PreprocessingData.DeleteColumn(column);
121        }
122      });
123    }
[10709]124  }
125}
Note: See TracBrowser for help on using the repository browser.