[10709] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[11171] | 3 | * Copyright (C) 2002-2014 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 |
|
---|
| 22 | using System;
|
---|
[10905] | 23 | using System.Collections.Generic;
|
---|
[10709] | 24 | using System.Drawing;
|
---|
| 25 | using System.Windows.Forms;
|
---|
| 26 | using HeuristicLab.Core.Views;
|
---|
| 27 | using HeuristicLab.MainForm;
|
---|
| 28 |
|
---|
| 29 | namespace HeuristicLab.DataPreprocessing.Views {
|
---|
| 30 |
|
---|
| 31 | [View("Manipulation Chart View")]
|
---|
[10712] | 32 | [Content(typeof(ManipulationContent), true)]
|
---|
[10709] | 33 | public partial class ManipulationView : ItemView {
|
---|
| 34 |
|
---|
| 35 | private Action[] validators;
|
---|
| 36 | private Action[] manipulations;
|
---|
| 37 |
|
---|
| 38 | public ManipulationView() {
|
---|
| 39 | InitializeComponent();
|
---|
[10776] | 40 | cmbReplaceWith.SelectedIndex = 0;
|
---|
[10709] | 41 | tabsData.Appearance = TabAppearance.FlatButtons;
|
---|
| 42 | tabsData.ItemSize = new Size(0, 1);
|
---|
| 43 | tabsData.SizeMode = TabSizeMode.Fixed;
|
---|
| 44 | tabsPreview.Appearance = TabAppearance.FlatButtons;
|
---|
| 45 | tabsPreview.ItemSize = new Size(0, 1);
|
---|
| 46 | tabsPreview.SizeMode = TabSizeMode.Fixed;
|
---|
| 47 |
|
---|
| 48 | validators = new Action[] {
|
---|
[10737] | 49 | ()=>validateDeleteColumnsInfo(),
|
---|
| 50 | ()=>validateDeleteColumnsVariance(),
|
---|
| 51 | ()=>validateDeleteRowsInfo(),
|
---|
[10776] | 52 | ()=>validateReplaceWith(),
|
---|
[10737] | 53 | ()=>{btnApply.Enabled = true; lblPreviewShuffle.Text = "Data will be shuffled randomly - preview not possible";} //shuffle
|
---|
[10709] | 54 | };
|
---|
[10737] | 55 |
|
---|
[10709] | 56 | manipulations = new Action[] {
|
---|
[10737] | 57 | ()=>Content.ManipulationLogic.DeleteColumnsWithMissingValuesGreater(getDeleteColumnsInfo()),
|
---|
| 58 | ()=>Content.ManipulationLogic.DeleteColumnsWithVarianceSmaller(getDeleteColumnsVariance()),
|
---|
| 59 | ()=>Content.ManipulationLogic.DeleteRowsWithMissingValuesGreater(getRowsColumnsInfo()),
|
---|
[10776] | 60 | ()=>replaceMissingValues(),
|
---|
[10709] | 61 | ()=>Content.ManipulationLogic.ShuffleWithRanges()
|
---|
| 62 | };
|
---|
[10905] | 63 |
|
---|
[10709] | 64 | }
|
---|
| 65 |
|
---|
[10905] | 66 | protected override void OnContentChanged() {
|
---|
| 67 | base.OnContentChanged();
|
---|
| 68 | if (Content != null) {
|
---|
| 69 | cmbVariableNames.Items.Clear();
|
---|
[11002] | 70 | foreach (var name in Content.ManipulationLogic.VariableNames) {
|
---|
[10905] | 71 | cmbVariableNames.Items.Add(name);
|
---|
| 72 | }
|
---|
| 73 | cmbVariableNames.SelectedIndex = 0;
|
---|
[10977] | 74 | CheckFilters();
|
---|
[10905] | 75 | }
|
---|
| 76 | }
|
---|
| 77 |
|
---|
[10737] | 78 | protected override void RegisterContentEvents() {
|
---|
| 79 | base.RegisterContentEvents();
|
---|
[10970] | 80 | Content.FilterLogic.FilterChanged += FilterLogic_FilterChanged;
|
---|
[10737] | 81 | }
|
---|
| 82 |
|
---|
| 83 | protected override void DeregisterContentEvents() {
|
---|
[11070] | 84 | Content.FilterLogic.FilterChanged -= FilterLogic_FilterChanged;
|
---|
[10737] | 85 | base.DeregisterContentEvents();
|
---|
| 86 | }
|
---|
| 87 |
|
---|
[10970] | 88 | private void FilterLogic_FilterChanged(object sender, EventArgs e) {
|
---|
| 89 | if (Content != null) {
|
---|
[10977] | 90 | CheckFilters();
|
---|
[10970] | 91 | }
|
---|
| 92 | }
|
---|
| 93 |
|
---|
[10977] | 94 | private void CheckFilters() {
|
---|
[10970] | 95 | if (Content.FilterLogic.IsFiltered) {
|
---|
| 96 | tabsPreview.SelectedIndex = 0;
|
---|
| 97 | lstMethods.Enabled = false;
|
---|
| 98 | tabsData.Enabled = false;
|
---|
| 99 | tabsPreview.Enabled = false;
|
---|
| 100 | lblPreviewInActive.Visible = true;
|
---|
| 101 | btnApply.Enabled = false;
|
---|
| 102 | } else {
|
---|
| 103 | lblPreviewInActive.Visible = false;
|
---|
| 104 | tabsData.Enabled = true;
|
---|
| 105 | tabsPreview.Enabled = true;
|
---|
| 106 | lstMethods.Enabled = true;
|
---|
| 107 | lstMethods_SelectedIndexChanged(null, null);
|
---|
| 108 | }
|
---|
| 109 | }
|
---|
| 110 |
|
---|
[10737] | 111 | private double getDeleteColumnsInfo() {
|
---|
| 112 | return double.Parse(txtDeleteColumnsInfo.Text);
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | private double getDeleteColumnsVariance() {
|
---|
| 116 | return double.Parse(txtDeleteColumnsVariance.Text);
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | private double getRowsColumnsInfo() {
|
---|
| 120 | return double.Parse(txtDeleteRowsInfo.Text);
|
---|
| 121 | }
|
---|
| 122 |
|
---|
[10776] | 123 | private void replaceMissingValues() {
|
---|
[10905] | 124 | var allIndices = Content.SearchLogic.GetMissingValueIndices();
|
---|
| 125 | var columnIndex = cmbVariableNames.SelectedIndex;
|
---|
| 126 | var columnIndices = new Dictionary<int, IList<int>>{
|
---|
| 127 | {columnIndex, allIndices[columnIndex]}
|
---|
| 128 | };
|
---|
| 129 |
|
---|
| 130 | switch (cmbReplaceWith.SelectedIndex) {
|
---|
[10776] | 131 | case 0: //Value
|
---|
[10905] | 132 | Content.ManipulationLogic.ReplaceIndicesByValue(columnIndices, txtReplaceValue.Text);
|
---|
[10776] | 133 | break;
|
---|
| 134 | case 1: //Average
|
---|
[10905] | 135 | Content.ManipulationLogic.ReplaceIndicesByAverageValue(columnIndices);
|
---|
[10776] | 136 | break;
|
---|
| 137 | case 2: //Median
|
---|
[10905] | 138 | Content.ManipulationLogic.ReplaceIndicesByMedianValue(columnIndices);
|
---|
[10776] | 139 | break;
|
---|
| 140 | case 3: //Most Common
|
---|
[10905] | 141 | Content.ManipulationLogic.ReplaceIndicesByMostCommonValue(columnIndices);
|
---|
[10776] | 142 | break;
|
---|
| 143 | case 4: //Random
|
---|
[10905] | 144 | Content.ManipulationLogic.ReplaceIndicesByRandomValue(columnIndices);
|
---|
[10776] | 145 | break;
|
---|
| 146 | }
|
---|
| 147 | }
|
---|
| 148 |
|
---|
[10737] | 149 | private void validateDeleteColumnsInfo() {
|
---|
| 150 | validateDoubleTextBox(txtDeleteColumnsInfo.Text);
|
---|
| 151 | if (btnApply.Enabled) {
|
---|
| 152 | int count = Content.ManipulationLogic.ColumnsWithMissingValuesGreater(getDeleteColumnsInfo()).Count;
|
---|
[11045] | 153 | int rowCount = Content.FilterLogic.PreprocessingData.Rows;
|
---|
| 154 | lblPreviewColumnsInfo.Text = count + " column" + (count > 1 || count == 0 ? "s" : "") + " of " + rowCount + " (" + string.Format("{0:F2}%", 100d / rowCount * count) + ") were detected with more than " + txtDeleteColumnsInfo.Text + "% missing values.";
|
---|
[10737] | 155 | if (count > 0) {
|
---|
| 156 | lblPreviewColumnsInfo.Text += Environment.NewLine + Environment.NewLine + "Please press the button \"Apply Manipulation\" if you wish to delete those columns.";
|
---|
| 157 | } else {
|
---|
| 158 | btnApply.Enabled = false;
|
---|
| 159 | }
|
---|
| 160 | } else {
|
---|
| 161 | lblPreviewColumnsInfo.Text = "Preview not possible yet - please input the limit above.";
|
---|
| 162 | }
|
---|
| 163 | }
|
---|
| 164 |
|
---|
| 165 | private void validateDeleteColumnsVariance() {
|
---|
| 166 | validateDoubleTextBox(txtDeleteColumnsVariance.Text);
|
---|
| 167 | if (btnApply.Enabled) {
|
---|
| 168 | int count = Content.ManipulationLogic.ColumnsWithVarianceSmaller(getDeleteColumnsVariance()).Count;
|
---|
[11045] | 169 | int rowCount = Content.FilterLogic.PreprocessingData.Rows;
|
---|
| 170 | lblPreviewColumnsVariance.Text = count + " column" + (count > 1 || count == 0 ? "s" : "") + " of " + rowCount + " (" + string.Format("{0:F2}%", 100d / rowCount * count) + ") were detected with a variance smaller than " + txtDeleteColumnsVariance.Text + ".";
|
---|
[10737] | 171 | if (count > 0) {
|
---|
| 172 | lblPreviewColumnsVariance.Text += Environment.NewLine + Environment.NewLine + "Please press the button \"Apply Manipulation\" if you wish to delete those columns.";
|
---|
| 173 | } else {
|
---|
| 174 | btnApply.Enabled = false;
|
---|
| 175 | }
|
---|
| 176 | } else {
|
---|
| 177 | lblPreviewColumnsVariance.Text = "Preview not possible yet - please input the limit for the variance above.";
|
---|
| 178 | }
|
---|
| 179 | }
|
---|
| 180 |
|
---|
| 181 | private void validateDeleteRowsInfo() {
|
---|
| 182 | validateDoubleTextBox(txtDeleteRowsInfo.Text);
|
---|
| 183 | if (btnApply.Enabled) {
|
---|
| 184 | int count = Content.ManipulationLogic.RowsWithMissingValuesGreater(getRowsColumnsInfo()).Count;
|
---|
[11045] | 185 | int rowCount = Content.FilterLogic.PreprocessingData.Rows;
|
---|
| 186 | lblPreviewRowsInfo.Text = count + " row" + (count > 1 || count == 0 ? "s" : "") + " of " + rowCount + " (" + string.Format("{0:F2}%", 100d / rowCount * count) + ") were detected with more than " + txtDeleteRowsInfo.Text + "% missing values.";
|
---|
[10737] | 187 | if (count > 0) {
|
---|
| 188 | lblPreviewRowsInfo.Text += Environment.NewLine + Environment.NewLine + "Please press the button \"Apply Manipulation\" if you wish to delete those rows.";
|
---|
| 189 | } else {
|
---|
| 190 | btnApply.Enabled = false;
|
---|
| 191 | }
|
---|
| 192 | } else {
|
---|
| 193 | lblPreviewRowsInfo.Text = "Preview not possible yet - please input the limit above.";
|
---|
| 194 | }
|
---|
| 195 | }
|
---|
| 196 |
|
---|
[10776] | 197 | private void validateReplaceWith() {
|
---|
| 198 | btnApply.Enabled = false;
|
---|
[10905] | 199 | string replaceWith = (string)cmbReplaceWith.SelectedItem;
|
---|
| 200 | int columnIndex = cmbVariableNames.SelectedIndex;
|
---|
| 201 |
|
---|
[10776] | 202 | if (cmbReplaceWith.SelectedIndex == 0) {
|
---|
[10905] | 203 | string errorMessage;
|
---|
| 204 | string replaceValue = txtReplaceValue.Text;
|
---|
| 205 | if (string.IsNullOrEmpty(replaceValue)) {
|
---|
| 206 | lblPreviewReplaceMissingValues.Text = "Preview not possible yet - please input the text which will be used as replacement.";
|
---|
[11002] | 207 | } else if (!Content.ManipulationLogic.PreProcessingData.Validate(txtReplaceValue.Text, out errorMessage, columnIndex)) {
|
---|
[10905] | 208 | lblPreviewReplaceMissingValues.Text = "Preview not possible yet - " + errorMessage;
|
---|
| 209 | } else {
|
---|
| 210 | btnApply.Enabled = true;
|
---|
| 211 | }
|
---|
| 212 | replaceWith = "\"" + replaceValue + "\"";
|
---|
[10776] | 213 | } else {
|
---|
| 214 | btnApply.Enabled = true;
|
---|
| 215 | }
|
---|
| 216 | if (btnApply.Enabled) {
|
---|
[10905] | 217 | var allIndices = Content.SearchLogic.GetMissingValueIndices();
|
---|
| 218 | int count = allIndices[columnIndex].Count;
|
---|
[11070] | 219 | int cellCount = Content.FilterLogic.PreprocessingData.Rows * Content.FilterLogic.PreprocessingData.Columns;
|
---|
[10905] | 220 | lblPreviewReplaceMissingValues.Text = count + " cell" + (count > 1 || count == 0 ? "s" : "")
|
---|
[11045] | 221 | + " of " + cellCount + " (" + string.Format("{0:F2}%", 100d / cellCount * count) + ") were detected with missing values which would be replaced with " + replaceWith;
|
---|
[10776] | 222 | if (count > 0) {
|
---|
| 223 | lblPreviewReplaceMissingValues.Text += Environment.NewLine + Environment.NewLine + "Please press the button \"Apply Manipulation\" if you wish to perform the replacement.";
|
---|
| 224 | } else {
|
---|
| 225 | btnApply.Enabled = false;
|
---|
| 226 | }
|
---|
| 227 | }
|
---|
| 228 | }
|
---|
| 229 |
|
---|
[10709] | 230 | public new ManipulationContent Content {
|
---|
| 231 | get { return (ManipulationContent)base.Content; }
|
---|
| 232 | set { base.Content = value; }
|
---|
| 233 | }
|
---|
| 234 |
|
---|
| 235 | private void lstMethods_SelectedIndexChanged(object sender, System.EventArgs e) {
|
---|
| 236 | int index = lstMethods.SelectedIndex;
|
---|
| 237 | tabsData.SelectedIndex = index + 1;
|
---|
| 238 | tabsPreview.SelectedIndex = index + 1;
|
---|
| 239 | btnApply.Enabled = false;
|
---|
| 240 |
|
---|
[10737] | 241 | //in order that button is enabled if necessary input was already entered
|
---|
[10710] | 242 | if (index >= 0) {
|
---|
| 243 | validators[index]();
|
---|
| 244 | }
|
---|
[10709] | 245 | }
|
---|
| 246 |
|
---|
| 247 | private void btnApply_Click(object sender, System.EventArgs e) {
|
---|
| 248 | manipulations[lstMethods.SelectedIndex]();
|
---|
[10737] | 249 | switch (lstMethods.SelectedIndex) {
|
---|
| 250 | case 0:
|
---|
| 251 | lblPreviewColumnsInfo.Text = "columns successfully deleted.";
|
---|
| 252 | break;
|
---|
| 253 | case 1:
|
---|
| 254 | lblPreviewColumnsVariance.Text = "columns successfully deleted.";
|
---|
| 255 | break;
|
---|
| 256 | case 2:
|
---|
| 257 | lblPreviewRowsInfo.Text = "rows successfully deleted.";
|
---|
| 258 | break;
|
---|
| 259 | case 3:
|
---|
[10905] | 260 | lblPreviewReplaceMissingValues.Text = "missing values successfully replaced.";
|
---|
| 261 | btnApply.Enabled = false;
|
---|
| 262 | break;
|
---|
| 263 | case 4:
|
---|
[10737] | 264 | lblPreviewShuffle.Text = "dataset shuffled successfully.";
|
---|
| 265 | btnApply.Enabled = false;
|
---|
| 266 | break;
|
---|
| 267 | }
|
---|
[10709] | 268 | }
|
---|
| 269 |
|
---|
| 270 | private void validateDoubleTextBox(String text) {
|
---|
| 271 | btnApply.Enabled = false;
|
---|
| 272 | if (!string.IsNullOrEmpty(text)) {
|
---|
| 273 | double percent;
|
---|
| 274 | if (Double.TryParse(text, out percent)) {
|
---|
| 275 | btnApply.Enabled = true;
|
---|
| 276 | }
|
---|
| 277 | }
|
---|
| 278 | }
|
---|
| 279 |
|
---|
| 280 | private void txtDeleteColumnsInfo_TextChanged(object sender, EventArgs e) {
|
---|
[10737] | 281 | validateDeleteColumnsInfo();
|
---|
[10709] | 282 | }
|
---|
| 283 |
|
---|
| 284 | private void txtDeleteColumnsVariance_TextChanged(object sender, EventArgs e) {
|
---|
[10737] | 285 | validateDeleteColumnsVariance();
|
---|
[10709] | 286 | }
|
---|
| 287 |
|
---|
| 288 | private void txtDeleteRowsInfo_TextChanged(object sender, EventArgs e) {
|
---|
[10737] | 289 | validateDeleteRowsInfo();
|
---|
[10709] | 290 | }
|
---|
[10737] | 291 |
|
---|
[10776] | 292 | private void cmbReplaceWith_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
| 293 | bool isReplaceWithValueSelected = cmbReplaceWith.SelectedIndex == 0;
|
---|
| 294 | lblValueColon.Visible = isReplaceWithValueSelected;
|
---|
| 295 | txtReplaceValue.Visible = isReplaceWithValueSelected;
|
---|
| 296 | validateReplaceWith();
|
---|
| 297 | }
|
---|
| 298 |
|
---|
| 299 | private void txtReplaceValue_TextChanged(object sender, EventArgs e) {
|
---|
| 300 | validateReplaceWith();
|
---|
| 301 | }
|
---|
[10709] | 302 | }
|
---|
| 303 | }
|
---|