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