Free cookie consent management tool by TermsFeed Policy Generator

Changeset 15518 for trunk/sources


Ignore:
Timestamp:
12/12/17 16:32:35 (6 years ago)
Author:
pfleck
Message:

#2809: merged branch to trunk

Location:
trunk/sources
Files:
3 deleted
35 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.DataPreprocessing

  • trunk/sources/HeuristicLab.DataPreprocessing.Views

  • trunk/sources/HeuristicLab.DataPreprocessing.Views/3.4/CheckedTransformationListView.cs

    r15110 r15518  
    5151          // TODO: Avoid accessing parent view
    5252          var transformationView = (TransformationView)Parent;
    53           var columnNames = transformationView.Content.Data.VariableNames;
     53          var columnNames = transformationView.Content.PreprocessingData.VariableNames;
    5454
    5555          return (ITransformation)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType(new[] { columnNames });
  • trunk/sources/HeuristicLab.DataPreprocessing.Views/3.4/DataCompletenessView.cs

    r15110 r15518  
    5252
    5353    private void InitData() {
    54       IDictionary<int, IList<int>> missingValueIndices = Content.SearchLogic.GetMissingValueIndices();
    55 
    56       bool[,] valueMissing = new bool[Content.SearchLogic.Rows, Content.SearchLogic.Columns];
    57       foreach (var columnMissingValues in missingValueIndices) {
    58         var column = columnMissingValues.Key;
    59         foreach (var missingValueIndex in columnMissingValues.Value)
    60           valueMissing[missingValueIndex, column] = true;
     54      bool[,] valueMissing = new bool[Content.PreprocessingData.Rows, Content.PreprocessingData.Columns];
     55      for (int row = 0; row < Content.PreprocessingData.Rows; row++) {
     56        for (int column = 0; column < Content.PreprocessingData.Columns; column++)
     57          valueMissing[row, column] = Content.PreprocessingData.IsCellEmpty(column, row);
    6158      }
    6259
     
    7875      //custom x axis label
    7976      double from = 0.5;
    80       foreach (String columnName in Content.SearchLogic.VariableNames) {
     77      foreach (String columnName in Content.PreprocessingData.VariableNames) {
    8178        double to = from + 1;
    8279        chart.ChartAreas[0].AxisX.CustomLabels.Add(from, to, columnName);
  • trunk/sources/HeuristicLab.DataPreprocessing.Views/3.4/DataGridContentView.Designer.cs

    r15210 r15518  
    5454      this.mostCommonToolStripMenuItem_Column = new System.Windows.Forms.ToolStripMenuItem();
    5555      this.interpolationToolStripMenuItem_Column = new System.Windows.Forms.ToolStripMenuItem();
    56       this.smoothingToolStripMenuItem_Column = new System.Windows.Forms.ToolStripMenuItem();
    5756      this.replaceValueOverSelectionToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
    5857      this.averageToolStripMenuItem_Selection = new System.Windows.Forms.ToolStripMenuItem();
     
    6362      this.btnReplace = new System.Windows.Forms.Button();
    6463      this.toolTip = new System.Windows.Forms.ToolTip(this.components);
    65       this.checkInputsTargetButton = new System.Windows.Forms.Button();
    66       this.uncheckAllButton = new System.Windows.Forms.Button();
    67       this.checkAllButton = new System.Windows.Forms.Button();
     64      this.shuffleWithinPartitionsCheckBox = new System.Windows.Forms.CheckBox();
    6865      this.addRowButton = new System.Windows.Forms.Button();
    6966      this.addColumnButton = new System.Windows.Forms.Button();
    7067      this.renameColumnsButton = new System.Windows.Forms.Button();
    7168      this.showVariablesGroupBox = new System.Windows.Forms.GroupBox();
     69      this.shuffleAllButton = new System.Windows.Forms.Button();
     70      this.checkInputsTargetButton = new System.Windows.Forms.Button();
     71      this.uncheckAllButton = new System.Windows.Forms.Button();
     72      this.checkAllButton = new System.Windows.Forms.Button();
    7273      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
    7374      this.contextMenuCell.SuspendLayout();
     
    127128            this.randomToolStripMenuItem_Column,
    128129            this.mostCommonToolStripMenuItem_Column,
    129             this.interpolationToolStripMenuItem_Column,
    130             this.smoothingToolStripMenuItem_Column});
     130            this.interpolationToolStripMenuItem_Column});
    131131      this.replaceValueOverColumnToolStripMenuItem.Name = "replaceValueOverColumnToolStripMenuItem";
    132132      this.replaceValueOverColumnToolStripMenuItem.Size = new System.Drawing.Size(223, 22);
     
    167167      this.interpolationToolStripMenuItem_Column.Text = "Interpolation";
    168168      this.interpolationToolStripMenuItem_Column.Click += new System.EventHandler(this.ReplaceWithInterpolation_Column_Click);
    169       //
    170       // smoothingToolStripMenuItem_Column
    171       //
    172       this.smoothingToolStripMenuItem_Column.Name = "smoothingToolStripMenuItem_Column";
    173       this.smoothingToolStripMenuItem_Column.Size = new System.Drawing.Size(155, 22);
    174       this.smoothingToolStripMenuItem_Column.Text = "Smoothing";
    175       this.smoothingToolStripMenuItem_Column.Click += new System.EventHandler(this.ReplaceWithSmoothing_Selection_Click);
    176169      //
    177170      // replaceValueOverSelectionToolStripMenuItem
     
    236229      this.btnReplace.Click += new System.EventHandler(this.btnReplace_Click);
    237230      //
     231      // shuffleWithinPartitionsCheckBox
     232      //
     233      this.shuffleWithinPartitionsCheckBox.AutoSize = true;
     234      this.shuffleWithinPartitionsCheckBox.Location = new System.Drawing.Point(444, 30);
     235      this.shuffleWithinPartitionsCheckBox.Name = "shuffleWithinPartitionsCheckBox";
     236      this.shuffleWithinPartitionsCheckBox.Size = new System.Drawing.Size(102, 17);
     237      this.shuffleWithinPartitionsCheckBox.TabIndex = 20;
     238      this.shuffleWithinPartitionsCheckBox.Text = "Within Partitions";
     239      this.toolTip.SetToolTip(this.shuffleWithinPartitionsCheckBox, "If checked, the Training and Test partitions are shuffled separately. Otherwise a" +
     240        "ll data is shuffled.");
     241      this.shuffleWithinPartitionsCheckBox.UseVisualStyleBackColor = true;
     242      //
     243      // addRowButton
     244      //
     245      this.addRowButton.Location = new System.Drawing.Point(338, 26);
     246      this.addRowButton.Name = "addRowButton";
     247      this.addRowButton.Size = new System.Drawing.Size(83, 23);
     248      this.addRowButton.TabIndex = 10;
     249      this.addRowButton.Text = "Add Datarow";
     250      this.addRowButton.UseVisualStyleBackColor = true;
     251      this.addRowButton.Click += new System.EventHandler(this.addRowButton_Click);
     252      //
     253      // addColumnButton
     254      //
     255      this.addColumnButton.Location = new System.Drawing.Point(338, 0);
     256      this.addColumnButton.Name = "addColumnButton";
     257      this.addColumnButton.Size = new System.Drawing.Size(83, 23);
     258      this.addColumnButton.TabIndex = 10;
     259      this.addColumnButton.Text = "Add Variable";
     260      this.addColumnButton.UseVisualStyleBackColor = true;
     261      this.addColumnButton.Click += new System.EventHandler(this.addColumnButton_Click);
     262      //
     263      // renameColumnsButton
     264      //
     265      this.renameColumnsButton.Location = new System.Drawing.Point(228, 26);
     266      this.renameColumnsButton.Name = "renameColumnsButton";
     267      this.renameColumnsButton.Size = new System.Drawing.Size(104, 23);
     268      this.renameColumnsButton.TabIndex = 11;
     269      this.renameColumnsButton.Text = "Rename Variables";
     270      this.renameColumnsButton.UseVisualStyleBackColor = true;
     271      this.renameColumnsButton.Click += new System.EventHandler(this.renameColumnsButton_Click);
     272      //
     273      // showVariablesGroupBox
     274      //
     275      this.showVariablesGroupBox.Controls.Add(this.checkInputsTargetButton);
     276      this.showVariablesGroupBox.Controls.Add(this.uncheckAllButton);
     277      this.showVariablesGroupBox.Controls.Add(this.checkAllButton);
     278      this.showVariablesGroupBox.Location = new System.Drawing.Point(564, 0);
     279      this.showVariablesGroupBox.Name = "showVariablesGroupBox";
     280      this.showVariablesGroupBox.Size = new System.Drawing.Size(97, 49);
     281      this.showVariablesGroupBox.TabIndex = 17;
     282      this.showVariablesGroupBox.TabStop = false;
     283      this.showVariablesGroupBox.Text = "Show Variables";
     284      //
     285      // shuffleAllButton
     286      //
     287      this.shuffleAllButton.Location = new System.Drawing.Point(444, 0);
     288      this.shuffleAllButton.Name = "shuffleAllButton";
     289      this.shuffleAllButton.Size = new System.Drawing.Size(102, 23);
     290      this.shuffleAllButton.TabIndex = 19;
     291      this.shuffleAllButton.Text = "Shuffle";
     292      this.shuffleAllButton.UseVisualStyleBackColor = true;
     293      this.shuffleAllButton.Click += new System.EventHandler(this.shuffleAllButton_Click);
     294      //
    238295      // checkInputsTargetButton
    239296      //
     
    269326      this.checkAllButton.Click += new System.EventHandler(this.checkAllButton_Click);
    270327      //
    271       // addRowButton
    272       //
    273       this.addRowButton.Location = new System.Drawing.Point(338, 26);
    274       this.addRowButton.Name = "addRowButton";
    275       this.addRowButton.Size = new System.Drawing.Size(83, 23);
    276       this.addRowButton.TabIndex = 10;
    277       this.addRowButton.Text = "Add Datarow";
    278       this.addRowButton.UseVisualStyleBackColor = true;
    279       this.addRowButton.Click += new System.EventHandler(this.addRowButton_Click);
    280       //
    281       // addColumnButton
    282       //
    283       this.addColumnButton.Location = new System.Drawing.Point(338, 0);
    284       this.addColumnButton.Name = "addColumnButton";
    285       this.addColumnButton.Size = new System.Drawing.Size(83, 23);
    286       this.addColumnButton.TabIndex = 10;
    287       this.addColumnButton.Text = "Add Variable";
    288       this.addColumnButton.UseVisualStyleBackColor = true;
    289       this.addColumnButton.Click += new System.EventHandler(this.addColumnButton_Click);
    290       //
    291       // renameColumnsButton
    292       //
    293       this.renameColumnsButton.Location = new System.Drawing.Point(228, 26);
    294       this.renameColumnsButton.Name = "renameColumnsButton";
    295       this.renameColumnsButton.Size = new System.Drawing.Size(104, 23);
    296       this.renameColumnsButton.TabIndex = 11;
    297       this.renameColumnsButton.Text = "Rename Variables";
    298       this.renameColumnsButton.UseVisualStyleBackColor = true;
    299       this.renameColumnsButton.Click += new System.EventHandler(this.renameColumnsButton_Click);
    300       //
    301       // showVariablesGroupBox
    302       //
    303       this.showVariablesGroupBox.Controls.Add(this.checkInputsTargetButton);
    304       this.showVariablesGroupBox.Controls.Add(this.uncheckAllButton);
    305       this.showVariablesGroupBox.Controls.Add(this.checkAllButton);
    306       this.showVariablesGroupBox.Location = new System.Drawing.Point(448, 0);
    307       this.showVariablesGroupBox.Name = "showVariablesGroupBox";
    308       this.showVariablesGroupBox.Size = new System.Drawing.Size(97, 49);
    309       this.showVariablesGroupBox.TabIndex = 17;
    310       this.showVariablesGroupBox.TabStop = false;
    311       this.showVariablesGroupBox.Text = "Show Variables";
    312       //
    313328      // DataGridContentView
    314329      //
    315330      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    316331      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
     332      this.Controls.Add(this.shuffleWithinPartitionsCheckBox);
     333      this.Controls.Add(this.shuffleAllButton);
    317334      this.Controls.Add(this.showVariablesGroupBox);
    318335      this.Controls.Add(this.renameColumnsButton);
     
    335352      this.Controls.SetChildIndex(this.columnsTextBox, 0);
    336353      this.Controls.SetChildIndex(this.showVariablesGroupBox, 0);
     354      this.Controls.SetChildIndex(this.shuffleAllButton, 0);
     355      this.Controls.SetChildIndex(this.shuffleWithinPartitionsCheckBox, 0);
    337356      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit();
    338357      this.contextMenuCell.ResumeLayout(false);
     
    361380    private System.Windows.Forms.Button btnReplace;
    362381    private System.Windows.Forms.ToolTip toolTip;
    363     private System.Windows.Forms.ToolStripMenuItem smoothingToolStripMenuItem_Column;
    364382    private System.Windows.Forms.Button addRowButton;
    365383    private System.Windows.Forms.Button addColumnButton;
     
    369387    private System.Windows.Forms.Button uncheckAllButton;
    370388    private System.Windows.Forms.Button checkAllButton;
     389    private System.Windows.Forms.Button shuffleAllButton;
     390    private System.Windows.Forms.CheckBox shuffleWithinPartitionsCheckBox;
    371391  }
    372392}
  • trunk/sources/HeuristicLab.DataPreprocessing.Views/3.4/DataGridContentView.cs

    r15110 r15518  
    8585      base.RegisterContentEvents();
    8686      Content.Changed += Content_Changed;
    87       Content.FilterLogic.FilterChanged += FilterLogic_FilterChanged;
     87      Content.PreprocessingData.FilterChanged += FilterLogic_FilterChanged;
    8888    }
    8989
     
    9191      base.DeregisterContentEvents();
    9292      Content.Changed -= Content_Changed;
    93       Content.FilterLogic.FilterChanged -= FilterLogic_FilterChanged;
     93      Content.PreprocessingData.FilterChanged -= FilterLogic_FilterChanged;
    9494    }
    9595
     
    9898      searchIterator = null;
    9999      if (findAndReplaceDialog != null && !findAndReplaceDialog.IsDisposed) {
    100         if (Content.FilterLogic.IsFiltered) {
     100        if (Content.PreprocessingData.IsFiltered) {
    101101          findAndReplaceDialog.DisableReplace();
    102102        } else {
     
    104104        }
    105105      }
    106       btnReplace.Enabled = !Content.FilterLogic.IsFiltered;
     106      btnReplace.Enabled = !Content.PreprocessingData.IsFiltered;
    107107    }
    108108
     
    126126      string errorMessage;
    127127      if (!String.IsNullOrEmpty(e.FormattedValue.ToString())) {
    128         if (dataGridView.IsCurrentCellInEditMode && Content.FilterLogic.IsFiltered) {
     128        if (dataGridView.IsCurrentCellInEditMode && Content.PreprocessingData.IsFiltered) {
    129129          errorMessage = "A filter is active, you cannot modify data. Press ESC to exit edit mode.";
    130130        } else {
     
    167167
    168168      ReplaceTransaction(() => {
    169         Content.PreProcessingData.InTransaction(() => {
     169        Content.PreprocessingData.InTransaction(() => {
    170170          for (int row = containsHeader ? 1 : 0; row < values.GetLength(1); row++) {
    171171            for (int col = 0; col < values.GetLength(0); col++) {
     
    177177              if (string.IsNullOrWhiteSpace(firstRow[i]))
    178178                firstRow[i] = string.Format("<{0}>", i);
    179             Content.PreProcessingData.RenameColumns(firstRow);
     179            Content.PreprocessingData.RenameColumns(firstRow);
    180180          }
    181181        });
     
    224224      if (e.Button == MouseButtons.Middle) {
    225225        int newIndex = e.ColumnIndex >= 0 ? e.ColumnIndex : 0;
    226         Content.PreProcessingData.InsertColumn<double>(newIndex.ToString(), newIndex);
     226        Content.PreprocessingData.InsertColumn<double>(newIndex.ToString(), newIndex);
    227227      } else if (e.Button == MouseButtons.Right && Content.SortableView) {
    228228        SortColumn(e.ColumnIndex);
     
    235235        if (e.Button == MouseButtons.Middle) {
    236236          int newIndex = e.RowIndex >= 0 ? e.RowIndex : 0;
    237           Content.PreProcessingData.InsertRow(newIndex);
     237          Content.PreprocessingData.InsertRow(newIndex);
    238238        }
    239239      }
     
    248248    }
    249249
    250     private void btnApplySort_Click(object sender, System.EventArgs e) {
    251       Content.ManipulationLogic.ReOrderToIndices(virtualRowIndices);
     250    private void btnApplySort_Click(object sender, EventArgs e) {
     251      Content.ReOrderToIndices(virtualRowIndices);
    252252      OnContentChanged();
    253253    }
     
    271271        searchIterator = null;
    272272        DataGridView.SelectionChanged += DataGridView_SelectionChanged_FindAndReplace;
    273         if (Content.FilterLogic.IsFiltered) {
     273        if (Content.PreprocessingData.IsFiltered) {
    274274          findAndReplaceDialog.DisableReplace();
    275275        }
     
    405405      ComparisonOperation comparisonOperation = findAndReplaceDialog.GetComparisonOperation();
    406406      var foundCells = new Dictionary<int, IList<int>>();
    407       for (int i = 0; i < Content.FilterLogic.PreprocessingData.Columns; i++) {
     407      for (int i = 0; i < Content.PreprocessingData.Columns; i++) {
    408408        var filters = CreateFilters(match, comparisonOperation, i);
    409409
    410         bool[] filteredRows = Content.FilterLogic.GetFilterResult(filters, true);
     410        bool[] filteredRows = GetFilterResult(filters, true);
    411411        var foundIndices = new List<int>();
    412412        for (int idx = 0; idx < filteredRows.Length; ++idx) {
     
    427427    }
    428428
     429    private bool[] GetFilterResult(IList<IFilter> filters, bool isAndCombination) {
     430      IList<IFilter> activeFilters = filters.Where(f => f.Active && f.ConstraintData != null).ToList();
     431
     432      if (activeFilters.Count == 0) {
     433        return Enumerable.Repeat(false, Content.PreprocessingData.Rows).ToArray(); ;
     434      }
     435
     436      var result = Enumerable.Repeat(!isAndCombination, Content.PreprocessingData.Rows).ToArray();
     437      foreach (IFilter filter in activeFilters) {
     438        bool[] filterResult = filter.Check();
     439        for (int row = 0; row < result.Length; ++row) {
     440          result[row] = isAndCombination ? result[row] || filterResult[row] : result[row] && filterResult[row];
     441        }
     442      }
     443      return result;
     444    }
     445
    429446    private List<IFilter> CreateFilters(string match, ComparisonOperation comparisonOperation, int columnIndex) {
    430       IPreprocessingData preprocessingData = Content.FilterLogic.PreprocessingData;
     447      IPreprocessingData preprocessingData = Content.PreprocessingData;
    431448      IStringConvertibleValue value;
    432449      if (preprocessingData.VariableHasType<double>(columnIndex)) {
     
    473490          switch (findAndReplaceDialog.GetReplaceAction()) {
    474491            case ReplaceAction.Value:
    475               Content.ManipulationLogic.ReplaceIndicesByValue(cells, findAndReplaceDialog.GetReplaceText());
     492              Content.ReplaceIndicesByString(cells, findAndReplaceDialog.GetReplaceText());
    476493              break;
    477494            case ReplaceAction.Average:
    478               Content.ManipulationLogic.ReplaceIndicesByAverageValue(cells, false);
     495              Content.ReplaceIndicesByMean(cells, false);
    479496              break;
    480497            case ReplaceAction.Median:
    481               Content.ManipulationLogic.ReplaceIndicesByMedianValue(cells, false);
     498              Content.ReplaceIndicesByMedianValue(cells, false);
    482499              break;
    483500            case ReplaceAction.Random:
    484               Content.ManipulationLogic.ReplaceIndicesByRandomValue(cells, false);
     501              Content.ReplaceIndicesByRandomValue(cells, false);
    485502              break;
    486503            case ReplaceAction.MostCommon:
    487               Content.ManipulationLogic.ReplaceIndicesByMostCommonValue(cells, false);
     504              Content.ReplaceIndicesByMode(cells, false);
    488505              break;
    489506            case ReplaceAction.Interpolation:
    490               Content.ManipulationLogic.ReplaceIndicesByLinearInterpolationOfNeighbours(cells);
     507              Content.ReplaceIndicesByLinearInterpolationOfNeighbours(cells);
    491508              break;
    492509          }
     
    506523
    507524    #endregion FindAndReplaceDialog
    508 
    509525    private void dataGridView_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e) {
    510526      if (Content == null) return;
     
    531547            medianToolStripMenuItem_Selection.Enabled =
    532548            randomToolStripMenuItem_Column.Enabled =
    533             randomToolStripMenuItem_Selection.Enabled = !Content.PreProcessingData.AreAllStringColumns(columnIndices);
    534 
    535           smoothingToolStripMenuItem_Column.Enabled =
    536             interpolationToolStripMenuItem_Column.Enabled = !dataGridView.SelectedCells.Contains(dataGridView[e.ColumnIndex, 0])
    537             && !dataGridView.SelectedCells.Contains(dataGridView[e.ColumnIndex, Content.Rows - 1])
    538             && !Content.PreProcessingData.AreAllStringColumns(columnIndices);
     549            randomToolStripMenuItem_Selection.Enabled = !Content.PreprocessingData.AreAllStringColumns(columnIndices);
    539550
    540551          replaceValueOverColumnToolStripMenuItem.Visible = true;
     
    547558      base.dataGridView_KeyDown(sender, e);
    548559      //data is in read only mode....
    549       if (Content.FilterLogic.IsFiltered) return;
     560      if (Content.PreprocessingData.IsFiltered) return;
    550561
    551562      if (e.KeyCode == Keys.Delete) {
     
    581592      }
    582593
    583       foreach (var selectedCell in dataGridView.SelectedCells) {
    584         var cell = (DataGridViewCell)selectedCell;
     594      foreach (DataGridViewCell cell in dataGridView.SelectedCells) {
    585595        if (!selectedCells.ContainsKey(cell.ColumnIndex))
    586           selectedCells.Add(cell.ColumnIndex, new List<int>(1024));
     596          selectedCells.Add(cell.ColumnIndex, new List<int>());
    587597        selectedCells[cell.ColumnIndex].Add(cell.RowIndex);
    588598      }
     
    591601    }
    592602
    593     private void StartReplacing() {
     603    private void ReplaceTransaction(Action action) {
    594604      SuspendRepaint();
    595     }
    596 
    597     private void StopReplacing() {
     605      action();
    598606      ResumeRepaint(true);
    599     }
    600 
    601     private void ReplaceTransaction(Action action) {
    602       StartReplacing();
    603       action();
    604       StopReplacing();
    605607    }
    606608
     
    616618
    617619    #region ContextMenu Events
    618 
    619620    private void ReplaceWithAverage_Column_Click(object sender, EventArgs e) {
    620621      ReplaceTransaction(() => {
    621         Content.ManipulationLogic.ReplaceIndicesByAverageValue(GetSelectedCells(), false);
     622        Content.ReplaceIndicesByMean(GetSelectedCells(), false);
    622623      });
    623624    }
    624625    private void ReplaceWithAverage_Selection_Click(object sender, EventArgs e) {
    625626      ReplaceTransaction(() => {
    626         Content.ManipulationLogic.ReplaceIndicesByAverageValue(GetSelectedCells(), true);
     627        Content.ReplaceIndicesByMean(GetSelectedCells(), true);
    627628      });
    628629    }
     
    630631    private void ReplaceWithMedian_Column_Click(object sender, EventArgs e) {
    631632      ReplaceTransaction(() => {
    632         Content.ManipulationLogic.ReplaceIndicesByMedianValue(GetSelectedCells(), false);
     633        Content.ReplaceIndicesByMedianValue(GetSelectedCells(), false);
    633634      });
    634635    }
    635636    private void ReplaceWithMedian_Selection_Click(object sender, EventArgs e) {
    636637      ReplaceTransaction(() => {
    637         Content.ManipulationLogic.ReplaceIndicesByMedianValue(GetSelectedCells(), true);
     638        Content.ReplaceIndicesByMedianValue(GetSelectedCells(), true);
    638639      });
    639640    }
     
    641642    private void ReplaceWithRandom_Column_Click(object sender, EventArgs e) {
    642643      ReplaceTransaction(() => {
    643         Content.ManipulationLogic.ReplaceIndicesByRandomValue(GetSelectedCells(), false);
     644        Content.ReplaceIndicesByRandomValue(GetSelectedCells(), false);
    644645      });
    645646    }
    646647    private void ReplaceWithRandom_Selection_Click(object sender, EventArgs e) {
    647648      ReplaceTransaction(() => {
    648         Content.ManipulationLogic.ReplaceIndicesByRandomValue(GetSelectedCells(), true);
     649        Content.ReplaceIndicesByRandomValue(GetSelectedCells(), true);
    649650      });
    650651    }
     
    652653    private void ReplaceWithMostCommon_Column_Click(object sender, EventArgs e) {
    653654      ReplaceTransaction(() => {
    654         Content.ManipulationLogic.ReplaceIndicesByMostCommonValue(GetSelectedCells(), false);
     655        Content.ReplaceIndicesByMode(GetSelectedCells(), false);
    655656      });
    656657    }
    657658    private void ReplaceWithMostCommon_Selection_Click(object sender, EventArgs e) {
    658659      ReplaceTransaction(() => {
    659         Content.ManipulationLogic.ReplaceIndicesByMostCommonValue(GetSelectedCells(), true);
     660        Content.ReplaceIndicesByMode(GetSelectedCells(), true);
    660661      });
    661662    }
     
    663664    private void ReplaceWithInterpolation_Column_Click(object sender, EventArgs e) {
    664665      ReplaceTransaction(() => {
    665         Content.ManipulationLogic.ReplaceIndicesByLinearInterpolationOfNeighbours(GetSelectedCells());
    666       });
    667     }
    668 
    669     private void ReplaceWithSmoothing_Selection_Click(object sender, EventArgs e) {
    670       ReplaceTransaction(() => {
    671         Content.ManipulationLogic.ReplaceIndicesBySmoothing(GetSelectedCells());
     666        Content.ReplaceIndicesByLinearInterpolationOfNeighbours(GetSelectedCells());
    672667      });
    673668    }
     
    675670
    676671    private void addRowButton_Click(object sender, EventArgs e) {
    677       Content.PreProcessingData.InsertRow(Content.Rows);
     672      Content.PreprocessingData.InsertRow(Content.Rows);
    678673    }
    679674
    680675    private void addColumnButton_Click(object sender, EventArgs e) {
    681       Content.PreProcessingData.InsertColumn<double>(Content.Columns.ToString(), Content.Columns);
     676      Content.PreprocessingData.InsertColumn<double>(Content.Columns.ToString(), Content.Columns);
    682677    }
    683678
     
    686681
    687682      if (renameDialog.ShowDialog(this) == DialogResult.OK) {
    688         Content.PreProcessingData.RenameColumns(renameDialog.ColumnNames);
     683        Content.PreprocessingData.RenameColumns(renameDialog.ColumnNames);
    689684      }
    690685    }
     
    693688      foreach (DataGridViewColumn column in DataGridView.Columns) {
    694689        var variable = column.HeaderText;
    695         bool isInputTarget = Content.PreProcessingData.InputVariables.Contains(variable)
    696           || Content.PreProcessingData.TargetVariable == variable;
     690        bool isInputTarget = Content.PreprocessingData.InputVariables.Contains(variable)
     691          || Content.PreprocessingData.TargetVariable == variable;
    697692        column.Visible = isInputTarget;
    698693      }
     
    710705      }
    711706    }
     707
     708    private void shuffleAllButton_Click(object sender, EventArgs e) {
     709      Content.Shuffle(shuffleWithinPartitionsCheckBox.Checked);
     710    }
    712711  }
    713712}
  • trunk/sources/HeuristicLab.DataPreprocessing.Views/3.4/DataPreprocessingView.cs

    r15370 r15518  
    4949      if (Content != null) {
    5050        var data = Content.Data;
    51         var filterLogic = new FilterLogic(data);
    52         var searchLogic = new SearchLogic(data, filterLogic);
    53         var statisticsLogic = new StatisticsLogic(data, searchLogic);
    54         var manipulationLogic = new ManipulationLogic(data, searchLogic, statisticsLogic);
    5551
    5652        var viewShortcuts = new ItemList<IViewShortcut> {
    57           new DataGridContent(data, manipulationLogic, filterLogic),
    58           new StatisticsContent(data, statisticsLogic),
     53          new DataGridContent(data),
     54          new StatisticsContent(data),
    5955
    6056          new LineChartContent(data),
     
    6359          new MultiScatterPlotContent(data),
    6460          new CorrelationMatrixContent(Content),
    65           new DataCompletenessChartContent(searchLogic),
    66 
    67           new FilterContent(filterLogic),
    68           new ManipulationContent(manipulationLogic, searchLogic, filterLogic),
    69           new TransformationContent(data, filterLogic)
     61          new DataCompletenessChartContent(data),
     62
     63          new FilterContent(data),
     64          new ManipulationContent(data),
     65          new TransformationContent(data)
    7066        };
    7167
  • trunk/sources/HeuristicLab.DataPreprocessing.Views/3.4/FilterView.Designer.cs

    r15210 r15518  
    4646    private void InitializeComponent() {
    4747      this.groupBoxFilter = new System.Windows.Forms.GroupBox();
    48       this.checkedFilterView = new HeuristicLab.DataPreprocessing.Views.CheckedFilterCollectionView();
    4948      this.groupBoxFilterInfo = new System.Windows.Forms.GroupBox();
    5049      this.lblPercentage = new System.Windows.Forms.Label();
     
    6362      this.label3 = new System.Windows.Forms.Label();
    6463      this.bottomPanel = new System.Windows.Forms.Panel();
     64      this.checkedFilterView = new HeuristicLab.DataPreprocessing.Views.CheckedFilterCollectionView();
    6565      this.groupBoxFilter.SuspendLayout();
    6666      this.groupBoxFilterInfo.SuspendLayout();
     
    8080      this.groupBoxFilter.TabStop = false;
    8181      this.groupBoxFilter.Text = "Filter";
    82       //
    83       // checkedFilterView
    84       //
    85       this.checkedFilterView.Caption = "filterView";
    86       this.checkedFilterView.Content = null;
    87       this.checkedFilterView.Dock = System.Windows.Forms.DockStyle.Fill;
    88       this.checkedFilterView.Location = new System.Drawing.Point(3, 16);
    89       this.checkedFilterView.Name = "checkedFilterView";
    90       this.checkedFilterView.ReadOnly = false;
    91       this.checkedFilterView.ShowDetails = true;
    92       this.checkedFilterView.Size = new System.Drawing.Size(652, 308);
    93       this.checkedFilterView.TabIndex = 0;
    9482      //
    9583      // groupBoxFilterInfo
     
    185173      this.rBtnOr.AutoSize = true;
    186174      this.rBtnOr.Cursor = System.Windows.Forms.Cursors.Default;
    187       this.rBtnOr.Enabled = false;
    188175      this.rBtnOr.Location = new System.Drawing.Point(53, 6);
    189176      this.rBtnOr.Name = "rBtnOr";
     
    199186      this.rBtnAnd.Checked = true;
    200187      this.rBtnAnd.Cursor = System.Windows.Forms.Cursors.Default;
    201       this.rBtnAnd.Enabled = false;
    202188      this.rBtnAnd.Location = new System.Drawing.Point(3, 6);
    203189      this.rBtnAnd.Name = "rBtnAnd";
     
    273259      this.bottomPanel.Size = new System.Drawing.Size(670, 30);
    274260      this.bottomPanel.TabIndex = 13;
     261      //
     262      // checkedFilterView
     263      //
     264      this.checkedFilterView.Caption = "filterView";
     265      this.checkedFilterView.Content = null;
     266      this.checkedFilterView.Dock = System.Windows.Forms.DockStyle.Fill;
     267      this.checkedFilterView.Location = new System.Drawing.Point(3, 16);
     268      this.checkedFilterView.Name = "checkedFilterView";
     269      this.checkedFilterView.ReadOnly = false;
     270      this.checkedFilterView.ShowDetails = true;
     271      this.checkedFilterView.Size = new System.Drawing.Size(652, 308);
     272      this.checkedFilterView.TabIndex = 0;
    275273      //
    276274      // FilterView
  • trunk/sources/HeuristicLab.DataPreprocessing.Views/3.4/FilterView.cs

    r15110 r15518  
    2121
    2222using System;
    23 using System.Collections.Generic;
    2423using System.Linq;
    2524using HeuristicLab.Collections;
     
    4443    }
    4544
    46     private void InitData() {
    47       checkedFilterView.Content = Content.Filters;
    48       checkedFilterView.Content.ItemsAdded += Content_ItemsAdded;
    49       checkedFilterView.Content.ItemsRemoved += Content_ItemsRemoved;
    50       checkedFilterView.Content.CheckedItemsChanged += Content_CheckedItemsChanged;
    51     }
    52 
    5345    protected override void OnContentChanged() {
    5446      base.OnContentChanged();
    5547      if (Content != null) {
    56         InitData();
    57         UpdateFilterInfo();
     48        checkedFilterView.Content = Content.Filters;
     49        rBtnAnd.Checked = Content.IsAndCombination;
     50        rBtnOr.Checked = !Content.IsAndCombination;
     51        UpdateFilter();
     52      } else {
     53        checkedFilterView.Content = null;
    5854      }
    5955    }
     56    protected override void RegisterContentEvents() {
     57      base.RegisterContentEvents();
     58      Content.Filters.ItemsAdded += Content_ItemsAdded;
     59      Content.Filters.ItemsRemoved += Content_ItemsRemoved;
     60      Content.Filters.CheckedItemsChanged += Content_CheckedItemsChanged;
     61    }
     62    protected override void DeregisterContentEvents() {
     63      Content.Filters.ItemsAdded -= Content_ItemsAdded;
     64      Content.Filters.ItemsRemoved -= Content_ItemsRemoved;
     65      Content.Filters.CheckedItemsChanged -= Content_CheckedItemsChanged;
     66      base.DeregisterContentEvents();
     67    }
    6068
     69    private void UpdateFilter() {
     70      bool activeFilters = Content.ActiveFilters.Any();
     71      applyFilterButton.Enabled = activeFilters;
     72
     73      Content.PreprocessingData.ResetFilter();
     74
     75      int numTotal = Content.PreprocessingData.Rows;
     76      int numRemaining = numTotal;
     77
     78      if (activeFilters) {
     79        var remainingRows = Content.GetRemainingRows();
     80        numRemaining = remainingRows.Count(x => x);
     81
     82        if (numRemaining < numTotal) {
     83          Content.PreprocessingData.SetFilter(remainingRows);
     84        }
     85      }
     86
     87      tbRemaining.Text = numRemaining.ToString();
     88      double ratio = numTotal > 0 ? numRemaining / (double)numTotal : 0.0;
     89      tbPercentage.Text = ratio.ToString("P4");
     90      tbTotal.Text = numTotal.ToString();
     91    }
     92
     93
     94    #region Content Events
     95    //whenever a new filter is added the preprocessing data is set to the filter
     96    private void Content_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs<IFilter> e) {
     97      if (Content != null) {
     98        foreach (IFilter filter in e.Items) {
     99          filter.ConstrainedValue = Content.PreprocessingData;
     100        }
     101      }
     102    }
     103    private void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IFilter> e) {
     104      if (Content != null) {
     105        UpdateFilter();
     106      }
     107    }
    61108    private void Content_CheckedItemsChanged(object sender, Collections.CollectionItemsChangedEventArgs<IFilter> e) {
    62109      if (Content != null) {
     
    64111          filter.Active = checkedFilterView.Content.ItemChecked(filter);
    65112        }
    66         UpdateFilterInfo();
     113        UpdateFilter();
    67114      }
    68115    }
     116    #endregion
    69117
    70     private void UpdateFilterInfo() {
    71       List<IFilter> filters = Content.Filters.ToList();
    72       int activeFilters = filters.Count(c => c.Active);
    73       applyFilterButton.Enabled = (activeFilters > 0);
    74       rBtnAnd.Enabled = (activeFilters > 0);
    75       rBtnOr.Enabled = (activeFilters > 0);
    76       Content.FilterLogic.Reset();
    77       bool[] result = Content.FilterLogic.Preview(filters, rBtnAnd.Checked);
    78 
    79       int filteredCnt = result.Count(c => !c);
    80 
    81       tbRemaining.Text = filteredCnt.ToString();
    82       double percentage = result.Length == 0 ? 0.0 : filteredCnt * 100 / (double)result.Length;
    83       tbPercentage.Text = String.Format("{0:0.0000}%", percentage);
    84       tbTotal.Text = result.Length.ToString();
     118    #region Controls Events
     119    private void rBtnAnd_CheckedChanged(object sender, EventArgs e) {
     120      if (Content != null) {
     121        Content.IsAndCombination = rBtnAnd.Checked;
     122        UpdateFilter();
     123      }
    85124    }
    86 
    87125    private void applyFilterButton_Click(object sender, EventArgs e) {
    88126      if (Content != null) {
    89         List<IFilter> filters = Content.Filters.ToList();
    90127        //apply filters
    91         Content.FilterLogic.Apply(filters, rBtnAnd.Checked);
     128        Content.PreprocessingData.PersistFilter();
     129        Content.PreprocessingData.ResetFilter();
    92130        //deactivate checked filters
    93         filters = checkedFilterView.Content.CheckedItems.ToList();
    94         foreach (IFilter filter in filters) {
     131        foreach (var filter in Content.Filters.CheckedItems) {
    95132          checkedFilterView.Content.SetItemCheckedState(filter, false);
    96133          filter.Active = false;
    97134        }
    98         UpdateFilterInfo();
     135        UpdateFilter();
    99136      }
    100137    }
    101 
    102     //whenever a new filter is added the preprocessing data is set to the filter
    103     private void Content_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs<IFilter> e) {
    104       if (Content != null) {
    105         foreach (IFilter filter in e.Items) {
    106           filter.ConstrainedValue = Content.FilterLogic.PreprocessingData;
    107         }
    108       }
    109     }
    110 
    111     private void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IFilter> e) {
    112       if (Content != null) {
    113         UpdateFilterInfo();
    114       }
    115     }
    116 
    117     private void rBtnAnd_CheckedChanged(object sender, EventArgs e) {
    118       if (Content != null) {
    119         UpdateFilterInfo();
    120         Content.IsAndCombination = rBtnAnd.Checked;
    121       }
    122     }
     138    #endregion
    123139  }
    124140}
  • trunk/sources/HeuristicLab.DataPreprocessing.Views/3.4/ManipulationView.Designer.cs

    r14185 r15518  
    6262      this.txtDeleteRowsInfo = new System.Windows.Forms.TextBox();
    6363      this.label5 = new System.Windows.Forms.Label();
    64       this.tabReplaceMissingValues = new System.Windows.Forms.TabPage();
    65       this.txtReplaceValue = new System.Windows.Forms.TextBox();
    66       this.cmbVariableNames = new System.Windows.Forms.ComboBox();
    67       this.cmbReplaceWith = new System.Windows.Forms.ComboBox();
    68       this.lblValueColon = new System.Windows.Forms.Label();
    69       this.label8 = new System.Windows.Forms.Label();
    70       this.label10 = new System.Windows.Forms.Label();
    71       this.tabDataShuffle = new System.Windows.Forms.TabPage();
    72       this.shuffleSeparatelyCheckbox = new System.Windows.Forms.CheckBox();
    73       this.lblShuffleProperties = new System.Windows.Forms.Label();
    7464      this.grpBoxPreview = new System.Windows.Forms.GroupBox();
    7565      this.tabsPreview = new System.Windows.Forms.TabControl();
     
    7767      this.lblPreviewInActive = new System.Windows.Forms.Label();
    7868      this.tabPreviewDeleteColumnsInfo = new System.Windows.Forms.TabPage();
     69      this.panel1 = new System.Windows.Forms.Panel();
    7970      this.lblPreviewColumnsInfo = new System.Windows.Forms.Label();
    8071      this.tabPreviewDeleteColumnsVariance = new System.Windows.Forms.TabPage();
     72      this.panel2 = new System.Windows.Forms.Panel();
     73      this.lblPreviewColumnsVariance = new System.Windows.Forms.Label();
    8174      this.label12 = new System.Windows.Forms.Label();
    82       this.lblPreviewColumnsVariance = new System.Windows.Forms.Label();
    8375      this.tabPreviewDeleteRowsInfo = new System.Windows.Forms.TabPage();
    8476      this.lblPreviewRowsInfo = new System.Windows.Forms.Label();
    85       this.tabPreviewReplaceMissingValues = new System.Windows.Forms.TabPage();
    86       this.lblPreviewReplaceMissingValues = new System.Windows.Forms.Label();
    87       this.tabPreviewShuffle = new System.Windows.Forms.TabPage();
    88       this.lblPreviewShuffle = new System.Windows.Forms.Label();
    8977      this.label9 = new System.Windows.Forms.Label();
    90       this.panel1 = new System.Windows.Forms.Panel();
    91       this.panel2 = new System.Windows.Forms.Panel();
    9278      this.grpBoxData.SuspendLayout();
    9379      this.tabsData.SuspendLayout();
     
    9682      this.tabDataDeleteColumnsVariance.SuspendLayout();
    9783      this.tabDataDeleteRowsInfo.SuspendLayout();
    98       this.tabReplaceMissingValues.SuspendLayout();
    99       this.tabDataShuffle.SuspendLayout();
    10084      this.grpBoxPreview.SuspendLayout();
    10185      this.tabsPreview.SuspendLayout();
    10286      this.tabPreviewInactive.SuspendLayout();
    10387      this.tabPreviewDeleteColumnsInfo.SuspendLayout();
     88      this.panel1.SuspendLayout();
    10489      this.tabPreviewDeleteColumnsVariance.SuspendLayout();
     90      this.panel2.SuspendLayout();
    10591      this.tabPreviewDeleteRowsInfo.SuspendLayout();
    106       this.tabPreviewReplaceMissingValues.SuspendLayout();
    107       this.tabPreviewShuffle.SuspendLayout();
    108       this.panel1.SuspendLayout();
    109       this.panel2.SuspendLayout();
    11092      this.SuspendLayout();
    11193      //
    11294      // lstMethods
    11395      //
    114       this.lstMethods.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
     96      this.lstMethods.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
    11597            | System.Windows.Forms.AnchorStyles.Right)));
    11698      this.lstMethods.FormattingEnabled = true;
    117       this.lstMethods.ItemHeight = 16;
    11899      this.lstMethods.Items.AddRange(new object[] {
    119100            "Delete Columns with insufficient Information",
    120101            "Delete Columns with insufficient Variance",
    121             "Delete Rows with insufficient Information",
    122             "Replace Missing Values",
    123             "Shuffle Data"});
    124       this.lstMethods.Location = new System.Drawing.Point(4, 4);
    125       this.lstMethods.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
     102            "Delete Rows with insufficient Information"});
     103      this.lstMethods.Location = new System.Drawing.Point(3, 3);
    126104      this.lstMethods.Name = "lstMethods";
    127       this.lstMethods.Size = new System.Drawing.Size(976, 116);
     105      this.lstMethods.Size = new System.Drawing.Size(733, 95);
    128106      this.lstMethods.Sorted = true;
    129107      this.lstMethods.TabIndex = 0;
     
    134112      this.btnApply.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
    135113      this.btnApply.Enabled = false;
    136       this.btnApply.Location = new System.Drawing.Point(804, 615);
    137       this.btnApply.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
     114      this.btnApply.Location = new System.Drawing.Point(603, 500);
    138115      this.btnApply.Name = "btnApply";
    139       this.btnApply.Size = new System.Drawing.Size(172, 28);
     116      this.btnApply.Size = new System.Drawing.Size(129, 23);
    140117      this.btnApply.TabIndex = 2;
    141118      this.btnApply.Text = "Apply Manipulation";
     
    145122      // grpBoxData
    146123      //
    147       this.grpBoxData.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
     124      this.grpBoxData.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
    148125            | System.Windows.Forms.AnchorStyles.Right)));
    149126      this.grpBoxData.Controls.Add(this.tabsData);
    150       this.grpBoxData.Location = new System.Drawing.Point(5, 129);
    151       this.grpBoxData.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
     127      this.grpBoxData.Location = new System.Drawing.Point(4, 105);
    152128      this.grpBoxData.Name = "grpBoxData";
    153       this.grpBoxData.Padding = new System.Windows.Forms.Padding(4, 4, 4, 4);
    154       this.grpBoxData.Size = new System.Drawing.Size(976, 233);
     129      this.grpBoxData.Size = new System.Drawing.Size(732, 189);
    155130      this.grpBoxData.TabIndex = 3;
    156131      this.grpBoxData.TabStop = false;
     
    159134      // tabsData
    160135      //
    161       this.tabsData.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
     136      this.tabsData.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
    162137            | System.Windows.Forms.AnchorStyles.Right)));
    163138      this.tabsData.Controls.Add(this.tabPage1);
     
    165140      this.tabsData.Controls.Add(this.tabDataDeleteColumnsVariance);
    166141      this.tabsData.Controls.Add(this.tabDataDeleteRowsInfo);
    167       this.tabsData.Controls.Add(this.tabReplaceMissingValues);
    168       this.tabsData.Controls.Add(this.tabDataShuffle);
    169142      this.tabsData.ItemSize = new System.Drawing.Size(58, 18);
    170       this.tabsData.Location = new System.Drawing.Point(8, 23);
    171       this.tabsData.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
     143      this.tabsData.Location = new System.Drawing.Point(6, 19);
    172144      this.tabsData.Name = "tabsData";
    173145      this.tabsData.SelectedIndex = 0;
    174       this.tabsData.Size = new System.Drawing.Size(959, 202);
     146      this.tabsData.Size = new System.Drawing.Size(719, 164);
    175147      this.tabsData.TabIndex = 3;
    176148      //
     
    179151      this.tabPage1.Controls.Add(this.label7);
    180152      this.tabPage1.Location = new System.Drawing.Point(4, 22);
    181       this.tabPage1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
    182153      this.tabPage1.Name = "tabPage1";
    183       this.tabPage1.Padding = new System.Windows.Forms.Padding(4, 4, 4, 4);
    184       this.tabPage1.Size = new System.Drawing.Size(951, 176);
     154      this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
     155      this.tabPage1.Size = new System.Drawing.Size(711, 138);
    185156      this.tabPage1.TabIndex = 5;
    186157      this.tabPage1.Text = "tabDataInactive";
     
    191162      this.label7.AutoSize = true;
    192163      this.label7.Enabled = false;
    193       this.label7.Location = new System.Drawing.Point(4, 4);
    194       this.label7.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
     164      this.label7.Location = new System.Drawing.Point(3, 3);
    195165      this.label7.Name = "label7";
    196       this.label7.Size = new System.Drawing.Size(345, 17);
     166      this.label7.Size = new System.Drawing.Size(259, 13);
    197167      this.label7.TabIndex = 1;
    198168      this.label7.Text = "Please select one of the manipulation methods above";
     
    204174      this.tabDataDeleteColumnsInformation.Controls.Add(this.label1);
    205175      this.tabDataDeleteColumnsInformation.Location = new System.Drawing.Point(4, 22);
    206       this.tabDataDeleteColumnsInformation.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
    207176      this.tabDataDeleteColumnsInformation.Name = "tabDataDeleteColumnsInformation";
    208       this.tabDataDeleteColumnsInformation.Padding = new System.Windows.Forms.Padding(4, 4, 4, 4);
    209       this.tabDataDeleteColumnsInformation.Size = new System.Drawing.Size(951, 176);
     177      this.tabDataDeleteColumnsInformation.Padding = new System.Windows.Forms.Padding(3);
     178      this.tabDataDeleteColumnsInformation.Size = new System.Drawing.Size(711, 138);
    210179      this.tabDataDeleteColumnsInformation.TabIndex = 0;
    211180      this.tabDataDeleteColumnsInformation.Text = "del columns info";
     
    215184      //
    216185      this.label2.AutoSize = true;
    217       this.label2.Location = new System.Drawing.Point(272, 4);
    218       this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
     186      this.label2.Location = new System.Drawing.Point(204, 3);
    219187      this.label2.Name = "label2";
    220       this.label2.Size = new System.Drawing.Size(120, 17);
     188      this.label2.Size = new System.Drawing.Size(89, 13);
    221189      this.label2.TabIndex = 5;
    222190      this.label2.Text = "% missing values.";
     
    224192      // txtDeleteColumnsInfo
    225193      //
    226       this.txtDeleteColumnsInfo.Location = new System.Drawing.Point(219, 0);
    227       this.txtDeleteColumnsInfo.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
     194      this.txtDeleteColumnsInfo.Location = new System.Drawing.Point(164, 0);
    228195      this.txtDeleteColumnsInfo.Name = "txtDeleteColumnsInfo";
    229       this.txtDeleteColumnsInfo.Size = new System.Drawing.Size(44, 22);
     196      this.txtDeleteColumnsInfo.Size = new System.Drawing.Size(34, 20);
    230197      this.txtDeleteColumnsInfo.TabIndex = 4;
    231198      this.txtDeleteColumnsInfo.TextChanged += new System.EventHandler(this.txtDeleteColumnsInfo_TextChanged);
     
    234201      //
    235202      this.label1.AutoSize = true;
    236       this.label1.Location = new System.Drawing.Point(4, 4);
    237       this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
     203      this.label1.Location = new System.Drawing.Point(3, 3);
    238204      this.label1.Name = "label1";
    239       this.label1.Size = new System.Drawing.Size(205, 17);
     205      this.label1.Size = new System.Drawing.Size(155, 13);
    240206      this.label1.TabIndex = 3;
    241207      this.label1.Text = "Delete columns with more than ";
     
    246212      this.tabDataDeleteColumnsVariance.Controls.Add(this.label4);
    247213      this.tabDataDeleteColumnsVariance.Location = new System.Drawing.Point(4, 22);
    248       this.tabDataDeleteColumnsVariance.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
    249214      this.tabDataDeleteColumnsVariance.Name = "tabDataDeleteColumnsVariance";
    250       this.tabDataDeleteColumnsVariance.Padding = new System.Windows.Forms.Padding(4, 4, 4, 4);
    251       this.tabDataDeleteColumnsVariance.Size = new System.Drawing.Size(951, 176);
     215      this.tabDataDeleteColumnsVariance.Padding = new System.Windows.Forms.Padding(3);
     216      this.tabDataDeleteColumnsVariance.Size = new System.Drawing.Size(711, 138);
    252217      this.tabDataDeleteColumnsVariance.TabIndex = 1;
    253218      this.tabDataDeleteColumnsVariance.Text = "del columns variance";
     
    256221      // txtDeleteColumnsVariance
    257222      //
    258       this.txtDeleteColumnsVariance.Location = new System.Drawing.Point(305, 0);
    259       this.txtDeleteColumnsVariance.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
     223      this.txtDeleteColumnsVariance.Location = new System.Drawing.Point(229, 0);
    260224      this.txtDeleteColumnsVariance.Name = "txtDeleteColumnsVariance";
    261       this.txtDeleteColumnsVariance.Size = new System.Drawing.Size(179, 22);
     225      this.txtDeleteColumnsVariance.Size = new System.Drawing.Size(135, 20);
    262226      this.txtDeleteColumnsVariance.TabIndex = 4;
    263227      this.txtDeleteColumnsVariance.TextChanged += new System.EventHandler(this.txtDeleteColumnsVariance_TextChanged);
     
    266230      //
    267231      this.label4.AutoSize = true;
    268       this.label4.Location = new System.Drawing.Point(4, 4);
    269       this.label4.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
     232      this.label4.Location = new System.Drawing.Point(3, 3);
    270233      this.label4.Name = "label4";
    271       this.label4.Size = new System.Drawing.Size(292, 17);
     234      this.label4.Size = new System.Drawing.Size(220, 13);
    272235      this.label4.TabIndex = 3;
    273236      this.label4.Text = "Delete columns with a variance smaller than  ";
     
    279242      this.tabDataDeleteRowsInfo.Controls.Add(this.label5);
    280243      this.tabDataDeleteRowsInfo.Location = new System.Drawing.Point(4, 22);
    281       this.tabDataDeleteRowsInfo.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
    282244      this.tabDataDeleteRowsInfo.Name = "tabDataDeleteRowsInfo";
    283       this.tabDataDeleteRowsInfo.Padding = new System.Windows.Forms.Padding(4, 4, 4, 4);
    284       this.tabDataDeleteRowsInfo.Size = new System.Drawing.Size(951, 176);
     245      this.tabDataDeleteRowsInfo.Padding = new System.Windows.Forms.Padding(3);
     246      this.tabDataDeleteRowsInfo.Size = new System.Drawing.Size(711, 138);
    285247      this.tabDataDeleteRowsInfo.TabIndex = 2;
    286248      this.tabDataDeleteRowsInfo.Text = "del rows info";
     
    290252      //
    291253      this.label3.AutoSize = true;
    292       this.label3.Location = new System.Drawing.Point(252, 4);
    293       this.label3.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
     254      this.label3.Location = new System.Drawing.Point(189, 3);
    294255      this.label3.Name = "label3";
    295       this.label3.Size = new System.Drawing.Size(120, 17);
     256      this.label3.Size = new System.Drawing.Size(89, 13);
    296257      this.label3.TabIndex = 8;
    297258      this.label3.Text = "% missing values.";
     
    299260      // txtDeleteRowsInfo
    300261      //
    301       this.txtDeleteRowsInfo.Location = new System.Drawing.Point(196, 0);
    302       this.txtDeleteRowsInfo.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
     262      this.txtDeleteRowsInfo.Location = new System.Drawing.Point(147, 0);
    303263      this.txtDeleteRowsInfo.Name = "txtDeleteRowsInfo";
    304       this.txtDeleteRowsInfo.Size = new System.Drawing.Size(44, 22);
     264      this.txtDeleteRowsInfo.Size = new System.Drawing.Size(34, 20);
    305265      this.txtDeleteRowsInfo.TabIndex = 7;
    306266      this.txtDeleteRowsInfo.TextChanged += new System.EventHandler(this.txtDeleteRowsInfo_TextChanged);
     
    309269      //
    310270      this.label5.AutoSize = true;
    311       this.label5.Location = new System.Drawing.Point(4, 4);
    312       this.label5.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
     271      this.label5.Location = new System.Drawing.Point(3, 3);
    313272      this.label5.Name = "label5";
    314       this.label5.Size = new System.Drawing.Size(182, 17);
     273      this.label5.Size = new System.Drawing.Size(138, 13);
    315274      this.label5.TabIndex = 6;
    316275      this.label5.Text = "Delete rows with more than ";
    317276      //
    318       // tabReplaceMissingValues
    319       //
    320       this.tabReplaceMissingValues.Controls.Add(this.txtReplaceValue);
    321       this.tabReplaceMissingValues.Controls.Add(this.cmbVariableNames);
    322       this.tabReplaceMissingValues.Controls.Add(this.cmbReplaceWith);
    323       this.tabReplaceMissingValues.Controls.Add(this.lblValueColon);
    324       this.tabReplaceMissingValues.Controls.Add(this.label8);
    325       this.tabReplaceMissingValues.Controls.Add(this.label10);
    326       this.tabReplaceMissingValues.Location = new System.Drawing.Point(4, 22);
    327       this.tabReplaceMissingValues.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
    328       this.tabReplaceMissingValues.Name = "tabReplaceMissingValues";
    329       this.tabReplaceMissingValues.Padding = new System.Windows.Forms.Padding(4, 4, 4, 4);
    330       this.tabReplaceMissingValues.Size = new System.Drawing.Size(951, 176);
    331       this.tabReplaceMissingValues.TabIndex = 6;
    332       this.tabReplaceMissingValues.Text = "repl missing vals";
    333       this.tabReplaceMissingValues.UseVisualStyleBackColor = true;
    334       //
    335       // txtReplaceValue
    336       //
    337       this.txtReplaceValue.Location = new System.Drawing.Point(231, 33);
    338       this.txtReplaceValue.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
    339       this.txtReplaceValue.Name = "txtReplaceValue";
    340       this.txtReplaceValue.Size = new System.Drawing.Size(132, 22);
    341       this.txtReplaceValue.TabIndex = 2;
    342       this.txtReplaceValue.TextChanged += new System.EventHandler(this.txtReplaceValue_TextChanged);
    343       //
    344       // cmbVariableNames
    345       //
    346       this.cmbVariableNames.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
    347       this.cmbVariableNames.FormattingEnabled = true;
    348       this.cmbVariableNames.Location = new System.Drawing.Point(189, 0);
    349       this.cmbVariableNames.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
    350       this.cmbVariableNames.Name = "cmbVariableNames";
    351       this.cmbVariableNames.Size = new System.Drawing.Size(160, 24);
    352       this.cmbVariableNames.TabIndex = 1;
    353       this.cmbVariableNames.SelectedIndexChanged += new System.EventHandler(this.cmbReplaceWith_SelectedIndexChanged);
    354       //
    355       // cmbReplaceWith
    356       //
    357       this.cmbReplaceWith.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
    358       this.cmbReplaceWith.FormattingEnabled = true;
    359       this.cmbReplaceWith.Items.AddRange(new object[] {
    360             "Value",
    361             "Average",
    362             "Median",
    363             "Most Common",
    364             "Random"});
    365       this.cmbReplaceWith.Location = new System.Drawing.Point(47, 33);
    366       this.cmbReplaceWith.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
    367       this.cmbReplaceWith.Name = "cmbReplaceWith";
    368       this.cmbReplaceWith.Size = new System.Drawing.Size(160, 24);
    369       this.cmbReplaceWith.TabIndex = 1;
    370       this.cmbReplaceWith.SelectedIndexChanged += new System.EventHandler(this.cmbReplaceWith_SelectedIndexChanged);
    371       //
    372       // lblValueColon
    373       //
    374       this.lblValueColon.AutoSize = true;
    375       this.lblValueColon.Location = new System.Drawing.Point(209, 37);
    376       this.lblValueColon.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
    377       this.lblValueColon.Name = "lblValueColon";
    378       this.lblValueColon.Size = new System.Drawing.Size(12, 17);
    379       this.lblValueColon.TabIndex = 0;
    380       this.lblValueColon.Text = ":";
    381       //
    382       // label8
    383       //
    384       this.label8.AutoSize = true;
    385       this.label8.Location = new System.Drawing.Point(4, 37);
    386       this.label8.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
    387       this.label8.Name = "label8";
    388       this.label8.Size = new System.Drawing.Size(32, 17);
    389       this.label8.TabIndex = 0;
    390       this.label8.Text = "with";
    391       //
    392       // label10
    393       //
    394       this.label10.AutoSize = true;
    395       this.label10.Location = new System.Drawing.Point(4, 4);
    396       this.label10.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
    397       this.label10.Name = "label10";
    398       this.label10.Size = new System.Drawing.Size(177, 17);
    399       this.label10.TabIndex = 0;
    400       this.label10.Text = "Replace missing values for";
    401       //
    402       // tabDataShuffle
    403       //
    404       this.tabDataShuffle.Controls.Add(this.shuffleSeparatelyCheckbox);
    405       this.tabDataShuffle.Controls.Add(this.lblShuffleProperties);
    406       this.tabDataShuffle.Location = new System.Drawing.Point(4, 22);
    407       this.tabDataShuffle.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
    408       this.tabDataShuffle.Name = "tabDataShuffle";
    409       this.tabDataShuffle.Padding = new System.Windows.Forms.Padding(4, 4, 4, 4);
    410       this.tabDataShuffle.Size = new System.Drawing.Size(951, 176);
    411       this.tabDataShuffle.TabIndex = 4;
    412       this.tabDataShuffle.Text = "shuffle";
    413       this.tabDataShuffle.UseVisualStyleBackColor = true;
    414       //
    415       // shuffleSeparatelyCheckbox
    416       //
    417       this.shuffleSeparatelyCheckbox.AutoSize = true;
    418       this.shuffleSeparatelyCheckbox.Location = new System.Drawing.Point(8, 2);
    419       this.shuffleSeparatelyCheckbox.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
    420       this.shuffleSeparatelyCheckbox.Name = "shuffleSeparatelyCheckbox";
    421       this.shuffleSeparatelyCheckbox.Size = new System.Drawing.Size(312, 21);
    422       this.shuffleSeparatelyCheckbox.TabIndex = 1;
    423       this.shuffleSeparatelyCheckbox.Text = "Shuffle training and test partitions separately";
    424       this.shuffleSeparatelyCheckbox.UseVisualStyleBackColor = true;
    425       //
    426       // lblShuffleProperties
    427       //
    428       this.lblShuffleProperties.AutoSize = true;
    429       this.lblShuffleProperties.Enabled = false;
    430       this.lblShuffleProperties.Location = new System.Drawing.Point(4, 4);
    431       this.lblShuffleProperties.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
    432       this.lblShuffleProperties.Name = "lblShuffleProperties";
    433       this.lblShuffleProperties.Size = new System.Drawing.Size(154, 17);
    434       this.lblShuffleProperties.TabIndex = 0;
    435       this.lblShuffleProperties.Text = "No properties available";
    436       //
    437277      // grpBoxPreview
    438278      //
    439       this.grpBoxPreview.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    440             | System.Windows.Forms.AnchorStyles.Left)
     279      this.grpBoxPreview.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
     280            | System.Windows.Forms.AnchorStyles.Left) 
    441281            | System.Windows.Forms.AnchorStyles.Right)));
    442282      this.grpBoxPreview.Controls.Add(this.tabsPreview);
    443       this.grpBoxPreview.Location = new System.Drawing.Point(5, 370);
    444       this.grpBoxPreview.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
     283      this.grpBoxPreview.Location = new System.Drawing.Point(4, 301);
    445284      this.grpBoxPreview.Name = "grpBoxPreview";
    446       this.grpBoxPreview.Padding = new System.Windows.Forms.Padding(4, 4, 4, 4);
    447       this.grpBoxPreview.Size = new System.Drawing.Size(976, 238);
     285      this.grpBoxPreview.Size = new System.Drawing.Size(732, 193);
    448286      this.grpBoxPreview.TabIndex = 4;
    449287      this.grpBoxPreview.TabStop = false;
     
    452290      // tabsPreview
    453291      //
    454       this.tabsPreview.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
     292      this.tabsPreview.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
    455293            | System.Windows.Forms.AnchorStyles.Right)));
    456294      this.tabsPreview.Controls.Add(this.tabPreviewInactive);
     
    458296      this.tabsPreview.Controls.Add(this.tabPreviewDeleteColumnsVariance);
    459297      this.tabsPreview.Controls.Add(this.tabPreviewDeleteRowsInfo);
    460       this.tabsPreview.Controls.Add(this.tabPreviewReplaceMissingValues);
    461       this.tabsPreview.Controls.Add(this.tabPreviewShuffle);
    462298      this.tabsPreview.ItemSize = new System.Drawing.Size(58, 18);
    463       this.tabsPreview.Location = new System.Drawing.Point(8, 23);
    464       this.tabsPreview.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
     299      this.tabsPreview.Location = new System.Drawing.Point(6, 19);
    465300      this.tabsPreview.Name = "tabsPreview";
    466301      this.tabsPreview.SelectedIndex = 0;
    467       this.tabsPreview.Size = new System.Drawing.Size(959, 207);
     302      this.tabsPreview.Size = new System.Drawing.Size(719, 168);
    468303      this.tabsPreview.TabIndex = 3;
    469304      //
     
    472307      this.tabPreviewInactive.Controls.Add(this.lblPreviewInActive);
    473308      this.tabPreviewInactive.Location = new System.Drawing.Point(4, 22);
    474       this.tabPreviewInactive.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
    475309      this.tabPreviewInactive.Name = "tabPreviewInactive";
    476       this.tabPreviewInactive.Padding = new System.Windows.Forms.Padding(4, 4, 4, 4);
    477       this.tabPreviewInactive.Size = new System.Drawing.Size(951, 181);
     310      this.tabPreviewInactive.Padding = new System.Windows.Forms.Padding(3);
     311      this.tabPreviewInactive.Size = new System.Drawing.Size(711, 142);
    478312      this.tabPreviewInactive.TabIndex = 5;
    479313      this.tabPreviewInactive.Text = "inactive";
     
    483317      //
    484318      this.lblPreviewInActive.AutoSize = true;
    485       this.lblPreviewInActive.Location = new System.Drawing.Point(4, 4);
    486       this.lblPreviewInActive.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
     319      this.lblPreviewInActive.Location = new System.Drawing.Point(3, 3);
    487320      this.lblPreviewInActive.Name = "lblPreviewInActive";
    488       this.lblPreviewInActive.Size = new System.Drawing.Size(491, 51);
     321      this.lblPreviewInActive.Size = new System.Drawing.Size(361, 39);
    489322      this.lblPreviewInActive.TabIndex = 2;
    490323      this.lblPreviewInActive.Text = "Filters are active and thus manipulations cannot be applied!\r\n\r\nPlease deactive t" +
     
    496329      this.tabPreviewDeleteColumnsInfo.Controls.Add(this.panel1);
    497330      this.tabPreviewDeleteColumnsInfo.Location = new System.Drawing.Point(4, 22);
    498       this.tabPreviewDeleteColumnsInfo.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
    499331      this.tabPreviewDeleteColumnsInfo.Name = "tabPreviewDeleteColumnsInfo";
    500       this.tabPreviewDeleteColumnsInfo.Padding = new System.Windows.Forms.Padding(4, 4, 4, 4);
    501       this.tabPreviewDeleteColumnsInfo.Size = new System.Drawing.Size(951, 181);
     332      this.tabPreviewDeleteColumnsInfo.Padding = new System.Windows.Forms.Padding(3);
     333      this.tabPreviewDeleteColumnsInfo.Size = new System.Drawing.Size(711, 142);
    502334      this.tabPreviewDeleteColumnsInfo.TabIndex = 0;
    503335      this.tabPreviewDeleteColumnsInfo.Text = "del columns info";
    504336      this.tabPreviewDeleteColumnsInfo.UseVisualStyleBackColor = true;
    505337      //
     338      // panel1
     339      //
     340      this.panel1.AutoScroll = true;
     341      this.panel1.Controls.Add(this.lblPreviewColumnsInfo);
     342      this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
     343      this.panel1.Location = new System.Drawing.Point(3, 3);
     344      this.panel1.Margin = new System.Windows.Forms.Padding(2);
     345      this.panel1.Name = "panel1";
     346      this.panel1.Size = new System.Drawing.Size(705, 136);
     347      this.panel1.TabIndex = 2;
     348      //
    506349      // lblPreviewColumnsInfo
    507350      //
     
    509352      this.lblPreviewColumnsInfo.Dock = System.Windows.Forms.DockStyle.Left;
    510353      this.lblPreviewColumnsInfo.Location = new System.Drawing.Point(0, 0);
    511       this.lblPreviewColumnsInfo.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
    512354      this.lblPreviewColumnsInfo.Name = "lblPreviewColumnsInfo";
    513       this.lblPreviewColumnsInfo.Size = new System.Drawing.Size(423, 17);
     355      this.lblPreviewColumnsInfo.Size = new System.Drawing.Size(318, 13);
    514356      this.lblPreviewColumnsInfo.TabIndex = 1;
    515357      this.lblPreviewColumnsInfo.Text = "{0} columns with more than {1} % missing values would be deleted";
     
    520362      this.tabPreviewDeleteColumnsVariance.Controls.Add(this.label12);
    521363      this.tabPreviewDeleteColumnsVariance.Location = new System.Drawing.Point(4, 22);
    522       this.tabPreviewDeleteColumnsVariance.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
    523364      this.tabPreviewDeleteColumnsVariance.Name = "tabPreviewDeleteColumnsVariance";
    524       this.tabPreviewDeleteColumnsVariance.Padding = new System.Windows.Forms.Padding(4, 4, 4, 4);
    525       this.tabPreviewDeleteColumnsVariance.Size = new System.Drawing.Size(951, 181);
     365      this.tabPreviewDeleteColumnsVariance.Padding = new System.Windows.Forms.Padding(3);
     366      this.tabPreviewDeleteColumnsVariance.Size = new System.Drawing.Size(711, 142);
    526367      this.tabPreviewDeleteColumnsVariance.TabIndex = 1;
    527368      this.tabPreviewDeleteColumnsVariance.Text = "del columns variance";
    528369      this.tabPreviewDeleteColumnsVariance.UseVisualStyleBackColor = true;
    529370      //
    530       // label12
    531       //
    532       this.label12.AutoSize = true;
    533       this.label12.Location = new System.Drawing.Point(8, 27);
    534       this.label12.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
    535       this.label12.Name = "label12";
    536       this.label12.Size = new System.Drawing.Size(0, 17);
    537       this.label12.TabIndex = 2;
     371      // panel2
     372      //
     373      this.panel2.AutoScroll = true;
     374      this.panel2.Controls.Add(this.lblPreviewColumnsVariance);
     375      this.panel2.Dock = System.Windows.Forms.DockStyle.Fill;
     376      this.panel2.Location = new System.Drawing.Point(3, 3);
     377      this.panel2.Margin = new System.Windows.Forms.Padding(2);
     378      this.panel2.Name = "panel2";
     379      this.panel2.Size = new System.Drawing.Size(705, 136);
     380      this.panel2.TabIndex = 3;
    538381      //
    539382      // lblPreviewColumnsVariance
     
    542385      this.lblPreviewColumnsVariance.Dock = System.Windows.Forms.DockStyle.Left;
    543386      this.lblPreviewColumnsVariance.Location = new System.Drawing.Point(0, 0);
    544       this.lblPreviewColumnsVariance.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
    545387      this.lblPreviewColumnsVariance.Name = "lblPreviewColumnsVariance";
    546       this.lblPreviewColumnsVariance.Size = new System.Drawing.Size(398, 17);
     388      this.lblPreviewColumnsVariance.Size = new System.Drawing.Size(301, 13);
    547389      this.lblPreviewColumnsVariance.TabIndex = 2;
    548390      this.lblPreviewColumnsVariance.Text = "{0} columns with a variance smaller than {1} would be deleted.";
    549391      //
     392      // label12
     393      //
     394      this.label12.AutoSize = true;
     395      this.label12.Location = new System.Drawing.Point(6, 22);
     396      this.label12.Name = "label12";
     397      this.label12.Size = new System.Drawing.Size(0, 13);
     398      this.label12.TabIndex = 2;
     399      //
    550400      // tabPreviewDeleteRowsInfo
    551401      //
    552402      this.tabPreviewDeleteRowsInfo.Controls.Add(this.lblPreviewRowsInfo);
    553403      this.tabPreviewDeleteRowsInfo.Location = new System.Drawing.Point(4, 22);
    554       this.tabPreviewDeleteRowsInfo.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
    555404      this.tabPreviewDeleteRowsInfo.Name = "tabPreviewDeleteRowsInfo";
    556       this.tabPreviewDeleteRowsInfo.Padding = new System.Windows.Forms.Padding(4, 4, 4, 4);
    557       this.tabPreviewDeleteRowsInfo.Size = new System.Drawing.Size(951, 181);
     405      this.tabPreviewDeleteRowsInfo.Padding = new System.Windows.Forms.Padding(3);
     406      this.tabPreviewDeleteRowsInfo.Size = new System.Drawing.Size(711, 142);
    558407      this.tabPreviewDeleteRowsInfo.TabIndex = 2;
    559408      this.tabPreviewDeleteRowsInfo.Text = "del rows info";
     
    563412      //
    564413      this.lblPreviewRowsInfo.AutoSize = true;
    565       this.lblPreviewRowsInfo.Location = new System.Drawing.Point(4, 4);
    566       this.lblPreviewRowsInfo.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
     414      this.lblPreviewRowsInfo.Location = new System.Drawing.Point(3, 3);
    567415      this.lblPreviewRowsInfo.Name = "lblPreviewRowsInfo";
    568       this.lblPreviewRowsInfo.Size = new System.Drawing.Size(400, 17);
     416      this.lblPreviewRowsInfo.Size = new System.Drawing.Size(301, 13);
    569417      this.lblPreviewRowsInfo.TabIndex = 2;
    570418      this.lblPreviewRowsInfo.Text = "{0} rows with more than {1} % missing values would be deleted";
    571       //
    572       // tabPreviewReplaceMissingValues
    573       //
    574       this.tabPreviewReplaceMissingValues.Controls.Add(this.lblPreviewReplaceMissingValues);
    575       this.tabPreviewReplaceMissingValues.Location = new System.Drawing.Point(4, 22);
    576       this.tabPreviewReplaceMissingValues.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
    577       this.tabPreviewReplaceMissingValues.Name = "tabPreviewReplaceMissingValues";
    578       this.tabPreviewReplaceMissingValues.Padding = new System.Windows.Forms.Padding(4, 4, 4, 4);
    579       this.tabPreviewReplaceMissingValues.Size = new System.Drawing.Size(951, 181);
    580       this.tabPreviewReplaceMissingValues.TabIndex = 6;
    581       this.tabPreviewReplaceMissingValues.Text = "repl missing vals";
    582       this.tabPreviewReplaceMissingValues.UseVisualStyleBackColor = true;
    583       //
    584       // lblPreviewReplaceMissingValues
    585       //
    586       this.lblPreviewReplaceMissingValues.AutoSize = true;
    587       this.lblPreviewReplaceMissingValues.Location = new System.Drawing.Point(4, 4);
    588       this.lblPreviewReplaceMissingValues.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
    589       this.lblPreviewReplaceMissingValues.Name = "lblPreviewReplaceMissingValues";
    590       this.lblPreviewReplaceMissingValues.Size = new System.Drawing.Size(449, 17);
    591       this.lblPreviewReplaceMissingValues.TabIndex = 3;
    592       this.lblPreviewReplaceMissingValues.Text = "{0} cells detected with missing values which would be replaced with {1}";
    593       //
    594       // tabPreviewShuffle
    595       //
    596       this.tabPreviewShuffle.Controls.Add(this.lblPreviewShuffle);
    597       this.tabPreviewShuffle.Location = new System.Drawing.Point(4, 22);
    598       this.tabPreviewShuffle.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
    599       this.tabPreviewShuffle.Name = "tabPreviewShuffle";
    600       this.tabPreviewShuffle.Padding = new System.Windows.Forms.Padding(4, 4, 4, 4);
    601       this.tabPreviewShuffle.Size = new System.Drawing.Size(951, 181);
    602       this.tabPreviewShuffle.TabIndex = 4;
    603       this.tabPreviewShuffle.Text = "shuffle";
    604       this.tabPreviewShuffle.UseVisualStyleBackColor = true;
    605       //
    606       // lblPreviewShuffle
    607       //
    608       this.lblPreviewShuffle.AutoSize = true;
    609       this.lblPreviewShuffle.Location = new System.Drawing.Point(4, 4);
    610       this.lblPreviewShuffle.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
    611       this.lblPreviewShuffle.Name = "lblPreviewShuffle";
    612       this.lblPreviewShuffle.Size = new System.Drawing.Size(337, 17);
    613       this.lblPreviewShuffle.TabIndex = 0;
    614       this.lblPreviewShuffle.Text = "Data will be shuffled randomly - preview not possible";
    615419      //
    616420      // label9
     
    621425      this.label9.TabIndex = 0;
    622426      //
    623       // panel1
    624       //
    625       this.panel1.AutoScroll = true;
    626       this.panel1.Controls.Add(this.lblPreviewColumnsInfo);
    627       this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
    628       this.panel1.Location = new System.Drawing.Point(4, 4);
    629       this.panel1.Name = "panel1";
    630       this.panel1.Size = new System.Drawing.Size(943, 173);
    631       this.panel1.TabIndex = 2;
    632       //
    633       // panel2
    634       //
    635       this.panel2.AutoScroll = true;
    636       this.panel2.Controls.Add(this.lblPreviewColumnsVariance);
    637       this.panel2.Dock = System.Windows.Forms.DockStyle.Fill;
    638       this.panel2.Location = new System.Drawing.Point(4, 4);
    639       this.panel2.Name = "panel2";
    640       this.panel2.Size = new System.Drawing.Size(943, 173);
    641       this.panel2.TabIndex = 3;
    642       //
    643427      // ManipulationView
    644428      //
    645       this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
     429      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    646430      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    647431      this.Controls.Add(this.btnApply);
     
    649433      this.Controls.Add(this.grpBoxData);
    650434      this.Controls.Add(this.lstMethods);
    651       this.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
    652435      this.Name = "ManipulationView";
    653       this.Size = new System.Drawing.Size(985, 651);
     436      this.Size = new System.Drawing.Size(739, 529);
    654437      this.grpBoxData.ResumeLayout(false);
    655438      this.tabsData.ResumeLayout(false);
     
    662445      this.tabDataDeleteRowsInfo.ResumeLayout(false);
    663446      this.tabDataDeleteRowsInfo.PerformLayout();
    664       this.tabReplaceMissingValues.ResumeLayout(false);
    665       this.tabReplaceMissingValues.PerformLayout();
    666       this.tabDataShuffle.ResumeLayout(false);
    667       this.tabDataShuffle.PerformLayout();
    668447      this.grpBoxPreview.ResumeLayout(false);
    669448      this.tabsPreview.ResumeLayout(false);
     
    671450      this.tabPreviewInactive.PerformLayout();
    672451      this.tabPreviewDeleteColumnsInfo.ResumeLayout(false);
     452      this.panel1.ResumeLayout(false);
     453      this.panel1.PerformLayout();
    673454      this.tabPreviewDeleteColumnsVariance.ResumeLayout(false);
    674455      this.tabPreviewDeleteColumnsVariance.PerformLayout();
     456      this.panel2.ResumeLayout(false);
     457      this.panel2.PerformLayout();
    675458      this.tabPreviewDeleteRowsInfo.ResumeLayout(false);
    676459      this.tabPreviewDeleteRowsInfo.PerformLayout();
    677       this.tabPreviewReplaceMissingValues.ResumeLayout(false);
    678       this.tabPreviewReplaceMissingValues.PerformLayout();
    679       this.tabPreviewShuffle.ResumeLayout(false);
    680       this.tabPreviewShuffle.PerformLayout();
    681       this.panel1.ResumeLayout(false);
    682       this.panel1.PerformLayout();
    683       this.panel2.ResumeLayout(false);
    684       this.panel2.PerformLayout();
    685460      this.ResumeLayout(false);
    686461
     
    697472    private System.Windows.Forms.TabPage tabPreviewDeleteColumnsVariance;
    698473    private System.Windows.Forms.TabPage tabPreviewDeleteRowsInfo;
    699     private System.Windows.Forms.TabPage tabPreviewShuffle;
    700     private System.Windows.Forms.Label lblPreviewShuffle;
    701474    private System.Windows.Forms.TabPage tabPreviewInactive;
    702475    private System.Windows.Forms.Label lblPreviewColumnsInfo;
     
    704477    private System.Windows.Forms.Label lblPreviewColumnsVariance;
    705478    private System.Windows.Forms.Label lblPreviewRowsInfo;
    706     private System.Windows.Forms.TabPage tabPreviewReplaceMissingValues;
    707     private System.Windows.Forms.Label lblPreviewReplaceMissingValues;
    708479    private System.Windows.Forms.Label label9;
    709480    private System.Windows.Forms.TabControl tabsData;
     
    721492    private System.Windows.Forms.TextBox txtDeleteRowsInfo;
    722493    private System.Windows.Forms.Label label5;
    723     private System.Windows.Forms.TabPage tabReplaceMissingValues;
    724     private System.Windows.Forms.TextBox txtReplaceValue;
    725     private System.Windows.Forms.ComboBox cmbReplaceWith;
    726     private System.Windows.Forms.Label lblValueColon;
    727     private System.Windows.Forms.Label label10;
    728     private System.Windows.Forms.TabPage tabDataShuffle;
    729     private System.Windows.Forms.Label lblShuffleProperties;
    730     private System.Windows.Forms.ComboBox cmbVariableNames;
    731     private System.Windows.Forms.Label label8;
    732494    private System.Windows.Forms.Label lblPreviewInActive;
    733     private System.Windows.Forms.CheckBox shuffleSeparatelyCheckbox;
    734495    private System.Windows.Forms.Panel panel1;
    735496    private System.Windows.Forms.Panel panel2;
  • trunk/sources/HeuristicLab.DataPreprocessing.Views/3.4/ManipulationView.cs

    r15110 r15518  
    2121
    2222using System;
    23 using System.Collections.Generic;
    2423using System.Drawing;
    2524using System.Globalization;
     
    4443    public ManipulationView() {
    4544      InitializeComponent();
    46       cmbReplaceWith.SelectedIndex = 0;
    4745      tabsData.Appearance = TabAppearance.FlatButtons;
    4846      tabsData.ItemSize = new Size(0, 1);
     
    5654        () => ValidateDeleteColumnsVariance(),
    5755        () => ValidateDeleteRowsInfo(),
    58         () => ValidateReplaceWith(),
    59         () => ValidateShuffle()
    6056      };
    6157
    6258      manipulations = new Action[] {
    63         () => Content.ManipulationLogic.DeleteColumnsWithMissingValuesGreater(GetDeleteColumnsInfo()),
    64         () => Content.ManipulationLogic.DeleteColumnsWithVarianceSmaller(GetDeleteColumnsVariance()),
    65         () => Content.ManipulationLogic.DeleteRowsWithMissingValuesGreater(GetRowsColumnsInfo()),
    66         () => ReplaceMissingValues(),
    67         () => Content.ManipulationLogic.Shuffle(shuffleSeparatelyCheckbox.Checked)
     59        () => Content.DeleteColumnsWithMissingValuesGreater(GetDeleteColumnsInfo()),
     60        () => Content.DeleteColumnsWithVarianceSmaller(GetDeleteColumnsVariance()),
     61        () => Content.DeleteRowsWithMissingValuesGreater(GetRowsColumnsInfo()),
    6862      };
    6963    }
     
    7266      base.OnContentChanged();
    7367      if (Content != null) {
    74         cmbVariableNames.Items.Clear();
    75         foreach (var name in Content.ManipulationLogic.VariableNames) {
    76           cmbVariableNames.Items.Add(name);
    77         }
    78         cmbVariableNames.SelectedIndex = 0;
    7968        CheckFilters();
    8069      }
     
    8372    protected override void RegisterContentEvents() {
    8473      base.RegisterContentEvents();
    85       Content.FilterLogic.FilterChanged += FilterLogic_FilterChanged;
     74      Content.PreprocessingData.FilterChanged += FilterLogic_FilterChanged;
    8675    }
    8776
    8877    protected override void DeregisterContentEvents() {
    89       Content.FilterLogic.FilterChanged -= FilterLogic_FilterChanged;
     78      Content.PreprocessingData.FilterChanged -= FilterLogic_FilterChanged;
    9079      base.DeregisterContentEvents();
    9180    }
     
    9887
    9988    private void CheckFilters() {
    100       if (Content.FilterLogic.IsFiltered) {
     89      if (Content.PreprocessingData.IsFiltered) {
    10190        tabsPreview.SelectedIndex = 0;
    10291        lstMethods.Enabled = false;
     
    126115    }
    127116
    128     private void ReplaceMissingValues() {
    129       var allIndices = Content.SearchLogic.GetMissingValueIndices();
    130       var columnIndex = cmbVariableNames.SelectedIndex;
    131       var columnIndices = new Dictionary<int, IList<int>>{
    132           {columnIndex,   allIndices[columnIndex]}
    133       };
    134 
    135       switch (cmbReplaceWith.SelectedIndex) {
    136         case 0: //Value
    137           Content.ManipulationLogic.ReplaceIndicesByValue(columnIndices, txtReplaceValue.Text);
    138           break;
    139         case 1: //Average
    140           Content.ManipulationLogic.ReplaceIndicesByAverageValue(columnIndices);
    141           break;
    142         case 2: //Median
    143           Content.ManipulationLogic.ReplaceIndicesByMedianValue(columnIndices);
    144           break;
    145         case 3: //Most Common
    146           Content.ManipulationLogic.ReplaceIndicesByMostCommonValue(columnIndices);
    147           break;
    148         case 4: //Random
    149           Content.ManipulationLogic.ReplaceIndicesByRandomValue(columnIndices);
    150           break;
    151       }
    152     }
    153 
    154117    private void ValidateDeleteColumnsInfo() {
    155118      ValidateDoubleTextBox(txtDeleteColumnsInfo.Text);
    156119      if (btnApply.Enabled) {
    157         var filteredColumns = Content.ManipulationLogic.ColumnsWithMissingValuesGreater(GetDeleteColumnsInfo());
     120        var filteredColumns = Content.ColumnsWithMissingValuesGreater(GetDeleteColumnsInfo());
    158121        int count = filteredColumns.Count;
    159         int columnCount = Content.FilterLogic.PreprocessingData.Columns;
     122        int columnCount = Content.PreprocessingData.Columns;
    160123        lblPreviewColumnsInfo.Text = string.Format("{0} column{1} of {2} ({3}) were detected with more than {4}% missing values.", count, (count > 1 || count == 0 ? "s" : ""), columnCount, string.Format("{0:F2}%", 100d / columnCount * count), txtDeleteColumnsInfo.Text);
    161124
     
    165128          sb.Append(Environment.NewLine);
    166129          sb.Append("Columns: ");
    167           sb.Append(Content.SearchLogic.VariableNames.ElementAt(filteredColumns.ElementAt(0)));
     130          sb.Append(Content.PreprocessingData.VariableNames.ElementAt(filteredColumns.ElementAt(0)));
    168131          for (int i = 1; i < filteredColumns.Count; i++) {
    169             string columnName = Content.SearchLogic.VariableNames.ElementAt(filteredColumns.ElementAt(i));
     132            string columnName = Content.PreprocessingData.VariableNames.ElementAt(filteredColumns.ElementAt(i));
    170133            sb.Append(", ");
    171134            sb.Append(columnName);
     
    186149      ValidateDoubleTextBox(txtDeleteColumnsVariance.Text);
    187150      if (btnApply.Enabled) {
    188         var filteredColumns = Content.ManipulationLogic.ColumnsWithVarianceSmaller(GetDeleteColumnsVariance());
     151        var filteredColumns = Content.ColumnsWithVarianceSmaller(GetDeleteColumnsVariance());
    189152        int count = filteredColumns.Count;
    190         int columnCount = Content.FilterLogic.PreprocessingData.Columns;
     153        int columnCount = Content.PreprocessingData.Columns;
    191154        lblPreviewColumnsVariance.Text = string.Format("{0} column{1} of {2} ({3}) were detected with a variance smaller than {4}.", count, (count > 1 || count == 0 ? "s" : ""), columnCount, string.Format("{0:F2}%", 100d / columnCount * count), txtDeleteColumnsVariance.Text);
    192155
     
    196159          sb.Append(Environment.NewLine);
    197160          sb.Append("Columns: ");
    198           sb.Append(Content.SearchLogic.VariableNames.ElementAt(filteredColumns.ElementAt(0)));
     161          sb.Append(Content.PreprocessingData.VariableNames.ElementAt(filteredColumns.ElementAt(0)));
    199162          for (int i = 1; i < filteredColumns.Count; i++) {
    200             string columnName = Content.SearchLogic.VariableNames.ElementAt(filteredColumns.ElementAt(i));
     163            string columnName = Content.PreprocessingData.VariableNames.ElementAt(filteredColumns.ElementAt(i));
    201164            sb.Append(", ");
    202165            sb.Append(columnName);
     
    217180      ValidateDoubleTextBox(txtDeleteRowsInfo.Text);
    218181      if (btnApply.Enabled) {
    219         int count = Content.ManipulationLogic.RowsWithMissingValuesGreater(GetRowsColumnsInfo()).Count;
    220         int rowCount = Content.FilterLogic.PreprocessingData.Rows;
     182        int count = Content.RowsWithMissingValuesGreater(GetRowsColumnsInfo()).Count;
     183        int rowCount = Content.PreprocessingData.Rows;
    221184        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.";
    222185        if (count > 0) {
     
    228191        lblPreviewRowsInfo.Text = "Preview not possible yet - please input the limit above.";
    229192      }
    230     }
    231 
    232     private void ValidateReplaceWith() {
    233       btnApply.Enabled = false;
    234       string replaceWith = (string)cmbReplaceWith.SelectedItem;
    235       int columnIndex = cmbVariableNames.SelectedIndex;
    236 
    237       if (cmbReplaceWith.SelectedIndex == 0) {
    238         string errorMessage;
    239         string replaceValue = txtReplaceValue.Text;
    240         if (string.IsNullOrEmpty(replaceValue)) {
    241           lblPreviewReplaceMissingValues.Text = "Preview not possible yet - please input the text which will be used as replacement.";
    242         } else if (!Content.ManipulationLogic.PreProcessingData.Validate(txtReplaceValue.Text, out errorMessage, columnIndex)) {
    243           lblPreviewReplaceMissingValues.Text = "Preview not possible yet - " + errorMessage;
    244         } else {
    245           btnApply.Enabled = true;
    246         }
    247         replaceWith = "\"" + replaceValue + "\"";
    248       } else {
    249         btnApply.Enabled = true;
    250       }
    251       if (btnApply.Enabled) {
    252         var allIndices = Content.SearchLogic.GetMissingValueIndices();
    253         int count = allIndices[columnIndex].Count;
    254         int cellCount = Content.FilterLogic.PreprocessingData.Rows * Content.FilterLogic.PreprocessingData.Columns;
    255         lblPreviewReplaceMissingValues.Text = count + " cell" + (count > 1 || count == 0 ? "s" : "")
    256           + " of " + cellCount + " (" + string.Format("{0:F2}%", 100d / cellCount * count) + ") were detected with missing values which would be replaced with " + replaceWith;
    257         if (count > 0) {
    258           lblPreviewReplaceMissingValues.Text += Environment.NewLine + Environment.NewLine + "Please press the button \"Apply Manipulation\" if you wish to perform the replacement.";
    259         } else {
    260           btnApply.Enabled = false;
    261         }
    262       }
    263     }
    264 
    265     private void ValidateShuffle() {
    266       btnApply.Enabled = true;
    267       lblShuffleProperties.Enabled = false;
    268       lblShuffleProperties.Visible = false;
    269       shuffleSeparatelyCheckbox.Enabled = true;
    270       shuffleSeparatelyCheckbox.Visible = true;
    271193    }
    272194
     
    295217          lblPreviewRowsInfo.Text = "rows successfully deleted.";
    296218          break;
    297         case 3:
    298           lblPreviewReplaceMissingValues.Text = "missing values successfully replaced.";
    299           btnApply.Enabled = false;
    300           break;
    301         case 4:
    302           lblPreviewShuffle.Text = "dataset shuffled successfully.";
    303           btnApply.Enabled = false;
    304           break;
    305219      }
    306220    }
     
    327241      ValidateDeleteRowsInfo();
    328242    }
    329 
    330     private void cmbReplaceWith_SelectedIndexChanged(object sender, EventArgs e) {
    331       bool isReplaceWithValueSelected = cmbReplaceWith.SelectedIndex == 0;
    332       lblValueColon.Visible = isReplaceWithValueSelected;
    333       txtReplaceValue.Visible = isReplaceWithValueSelected;
    334       ValidateReplaceWith();
    335     }
    336 
    337     private void txtReplaceValue_TextChanged(object sender, EventArgs e) {
    338       ValidateReplaceWith();
    339     }
    340243  }
    341244}
  • trunk/sources/HeuristicLab.DataPreprocessing.Views/3.4/StatisticsView.cs

    r15210 r15518  
    8787
    8888    private void UpdateData(Dictionary<string, bool> oldVisibility = null) {
    89       var logic = Content.StatisticsLogic;
    90       rowsTextBox.Text = logic.GetRowCount().ToString();
    91       columnsTextBox.Text = logic.GetColumnCount().ToString();
    92       numericColumnsTextBox.Text = logic.GetNumericColumnCount().ToString();
    93       nominalColumnsTextBox5.Text = logic.GetNominalColumnCount().ToString();
    94       missingValuesTextBox.Text = logic.GetMissingValueCount().ToString();
    95       totalValuesTextBox.Text = (logic.GetColumnCount() * logic.GetRowCount() - logic.GetMissingValueCount()).ToString();
     89      var data = Content.PreprocessingData;
     90      rowsTextBox.Text = data.Rows.ToString();
     91      columnsTextBox.Text = data.Rows.ToString();
     92      numericColumnsTextBox.Text = GetColumnCount<double>().ToString();
     93      nominalColumnsTextBox5.Text = GetColumnCount<string>().ToString();
     94      missingValuesTextBox.Text = data.GetMissingValueCount().ToString();
     95      totalValuesTextBox.Text = (data.Rows * data.Rows - data.GetMissingValueCount()).ToString();
    9696
    9797      var variableNames = Content.PreprocessingData.VariableNames.ToList();
     
    107107        };
    108108
    109       for (int i = 0; i < logic.GetColumnCount(); i++) {
    110         var data = GetStatistics(i);
    111         for (int j = 0; j < data.Count; j++) {
     109      for (int i = 0; i < data.Columns; i++) {
     110        var statistics = GetStatistics(i);
     111        for (int j = 0; j < statistics.Count; j++) {
    112112          if (horizontal)
    113             statisticsMatrix[j, i] = data[j];
     113            statisticsMatrix[j, i] = statistics[j];
    114114          else
    115             statisticsMatrix[i, j] = data[j];
     115            statisticsMatrix[i, j] = statistics[j];
    116116        }
    117117      }
     
    138138    }
    139139
     140    public int GetColumnCount<T>() {
     141      int count = 0;
     142      for (int i = 0; i < Content.PreprocessingData.Columns; ++i) {
     143        if (Content.PreprocessingData.VariableHasType<T>(i)) {
     144          ++count;
     145        }
     146      }
     147      return count;
     148    }
     149
    140150    private List<string> GetStatistics(int varIdx) {
    141151      List<string> list;
    142       var logic = Content.StatisticsLogic;
    143       if (logic.VariableHasType<double>(varIdx)) {
     152      var data = Content.PreprocessingData;
     153      if (data.VariableHasType<double>(varIdx)) {
    144154        list = GetDoubleColumns(varIdx);
    145       } else if (logic.VariableHasType<string>(varIdx)) {
     155      } else if (data.VariableHasType<string>(varIdx)) {
    146156        list = GetStringColumns(varIdx);
    147       } else if (logic.VariableHasType<DateTime>(varIdx)) {
     157      } else if (data.VariableHasType<DateTime>(varIdx)) {
    148158        list = GetDateTimeColumns(varIdx);
    149159      } else {
     
    157167
    158168    private List<string> GetDoubleColumns(int statIdx) {
    159       var logic = Content.StatisticsLogic;
     169      var data = Content.PreprocessingData;
    160170      return new List<string> {
    161         logic.GetColumnTypeAsString(statIdx),
    162         logic.GetMissingValueCount(statIdx).ToString(),
    163         logic.GetMin<double>(statIdx, double.NaN).ToString(),
    164         logic.GetMax<double>(statIdx, double.NaN).ToString(),
    165         logic.GetMedian(statIdx).ToString(),
    166         logic.GetAverage(statIdx).ToString(),
    167         logic.GetStandardDeviation(statIdx).ToString(),
    168         logic.GetVariance(statIdx).ToString(),
    169         logic.GetOneQuarterPercentile(statIdx).ToString(),
    170         logic.GetThreeQuarterPercentile(statIdx).ToString(),
    171         logic.GetMostCommonValue<double>(statIdx, double.NaN).ToString(),
    172         logic.GetDifferentValuesCount<double>(statIdx).ToString()
     171        data.GetVariableType(statIdx).Name,
     172        data.GetMissingValueCount(statIdx).ToString(),
     173        data.GetMin<double>(statIdx, emptyValue: double.NaN).ToString(),
     174        data.GetMax<double>(statIdx, emptyValue: double.NaN).ToString(),
     175        data.GetMedian<double>(statIdx, emptyValue: double.NaN).ToString(),
     176        data.GetMean<double>(statIdx, emptyValue: double.NaN).ToString(),
     177        data.GetStandardDeviation<double>(statIdx, emptyValue: double.NaN).ToString(),
     178        data.GetVariance<double>(statIdx, emptyValue: double.NaN).ToString(),
     179        data.GetQuantile<double>(0.25, statIdx, emptyValue: double.NaN).ToString(),
     180        data.GetQuantile<double>(0.75, statIdx, emptyValue: double.NaN).ToString(),
     181        data.GetMode<double>(statIdx, emptyValue: double.NaN).ToString(),
     182        data.GetDistinctValues<double>(statIdx).ToString()
    173183      };
    174184    }
    175185
    176186    private List<string> GetStringColumns(int statIdx) {
    177       var logic = Content.StatisticsLogic;
     187      var data = Content.PreprocessingData;
    178188      return new List<string> {
    179         logic.GetColumnTypeAsString(statIdx),
    180         logic.GetMissingValueCount(statIdx).ToString(),
    181         "", //min
    182         "", //max
    183         "", //median
     189        data.GetVariableType(statIdx).Name,
     190        data.GetMissingValueCount(statIdx).ToString(),
     191        "", // data.GetMin<string>(statIdx, emptyValue: string.Empty), //min
     192        "", // data.GetMax<string>(statIdx, emptyValue: string.Empty), //max
     193        "", // data.GetMedian<string>(statIdx, emptyValue: string.Empty), //median
    184194        "", //average
    185195        "", //standard deviation
    186196        "", //variance
    187         "", //quarter percentile
    188         "", //three quarter percentile
    189         logic.GetMostCommonValue<string>(statIdx,string.Empty) ?? "",
    190         logic.GetDifferentValuesCount<string>(statIdx).ToString()
     197        "", // data.GetQuantile<string>(0.25, statIdx, emptyValue: string.Empty), //quarter percentile
     198        "", // data.GetQuantile<string>(0.75, statIdx, emptyValue: string.Empty), //three quarter percentile
     199        data.GetMode<string>(statIdx, emptyValue: string.Empty),
     200        data.GetDistinctValues<string>(statIdx).ToString()
    191201      };
    192202    }
    193203
    194204    private List<string> GetDateTimeColumns(int statIdx) {
    195       var logic = Content.StatisticsLogic;
     205      var data = Content.PreprocessingData;
    196206      return new List<string> {
    197         logic.GetColumnTypeAsString(statIdx),
    198         logic.GetMissingValueCount(statIdx).ToString(),
    199         logic.GetMin<DateTime>(statIdx, DateTime.MinValue).ToString(),
    200         logic.GetMax<DateTime>(statIdx, DateTime.MinValue).ToString(),
    201         logic.GetMedianDateTime(statIdx).ToString(),
    202         logic.GetAverageDateTime(statIdx).ToString(),
    203         logic.GetStandardDeviation(statIdx).ToString(),
    204         logic.GetVariance(statIdx).ToString(),
    205         logic.GetOneQuarterPercentile(statIdx).ToString(),
    206         logic.GetThreeQuarterPercentile(statIdx).ToString(),
    207         logic.GetMostCommonValue<DateTime>(statIdx, DateTime.MinValue).ToString(),
    208         logic.GetDifferentValuesCount<DateTime>(statIdx).ToString()
     207        data.GetVariableType(statIdx).Name,
     208        data.GetMissingValueCount(statIdx).ToString(),
     209        data.GetMin<DateTime>(statIdx).ToString(),
     210        data.GetMax<DateTime>(statIdx).ToString(),
     211        data.GetMedian<DateTime>(statIdx).ToString(),
     212        data.GetMean<DateTime>(statIdx).ToString(),
     213        "", // should be of type TimeSpan //data.GetStandardDeviation<DateTime>(statIdx).ToString(),
     214        "", // should be of type TimeSpan //data.GetVariance<DateTime>(statIdx).ToString(),
     215        data.GetQuantile<DateTime>(0.25, statIdx).ToString(),
     216        data.GetQuantile<DateTime>(0.75, statIdx).ToString(),
     217        data.GetMode<DateTime>(statIdx).ToString(),
     218        data.GetDistinctValues<DateTime>(statIdx).ToString()
    209219      };
    210220    }
  • trunk/sources/HeuristicLab.DataPreprocessing.Views/3.4/TransformationView.cs

    r15110 r15518  
    5151
    5252    protected override void RegisterContentEvents() {
    53       Content.FilterLogic.FilterChanged += FilterLogic_FilterChanged;
     53      Content.PreprocessingData.FilterChanged += FilterLogic_FilterChanged;
    5454    }
    5555
    5656    protected override void DeregisterContentEvents() {
    57       Content.FilterLogic.FilterChanged -= FilterLogic_FilterChanged;
     57      Content.PreprocessingData.FilterChanged -= FilterLogic_FilterChanged;
    5858    }
    5959
     
    6565
    6666    private void CheckFilters() {
    67       if (Content.FilterLogic.IsFiltered) {
     67      if (Content.PreprocessingData.IsFiltered) {
    6868        applyButton.Enabled = false;
    6969        lblFilterNotice.Visible = true;
     
    8282      }
    8383
    84       var transformator = new PreprocessingTransformator(Content.Data);
     84      var transformator = new PreprocessingTransformator(Content.PreprocessingData);
    8585      bool preserve = preserveColumnsCheckbox.CheckState == CheckState.Checked;
    8686      string errorMsg;
  • trunk/sources/HeuristicLab.DataPreprocessing.Views/3.4/ViewShortcutListView.cs

    r15110 r15518  
    4242    //Clone chart items
    4343    protected override void itemsListView_DoubleClick(object sender, EventArgs e) {
    44       if (itemsListView.SelectedItems.Count == 1) {
    45         IViewShortcut item = itemsListView.SelectedItems[0].Tag as IViewShortcut;
    46         if (item != null) {
    47           try {
    48             item = (IViewShortcut)item.Clone();
    49             var view = MainFormManager.MainForm.ShowContent(item);
    50             if (view != null) {
    51               view.ReadOnly = ReadOnly;
    52               view.Locked = Locked;
    53             }
    54           } catch (NullReferenceException) {
    55             // cloning for preprocessing not done properly yet
    56           }
     44      if (itemsListView.SelectedItems.Count != 1) return;
     45      IViewShortcut item = itemsListView.SelectedItems[0].Tag as IViewShortcut;
     46      if (item == null) return;
     47      try {
     48        item = (IViewShortcut)item.Clone();
     49        var view = MainFormManager.MainForm.ShowContent(item);
     50        if (view != null) {
     51          view.ReadOnly = ReadOnly;
     52          view.Locked = Locked;
    5753        }
     54      } catch (NullReferenceException) {
     55        // cloning for preprocessing not done properly yet
    5856      }
    5957    }
  • trunk/sources/HeuristicLab.DataPreprocessing/3.4

  • trunk/sources/HeuristicLab.DataPreprocessing/3.4/Content/CorrelationMatrixContent.cs

    r15110 r15518  
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Core;
     25using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2526using HeuristicLab.Problems.DataAnalysis;
    2627
    2728namespace HeuristicLab.DataPreprocessing {
    2829  [Item("Feature Correlation Matrix", "Represents the feature correlation matrix.")]
    29   public class CorrelationMatrixContent : Item, IViewShortcut {
     30  [StorableClass]
     31  public class CorrelationMatrixContent : PreprocessingContent, IViewShortcut {
    3032    public static new Image StaticItemImage {
    3133      get { return HeuristicLab.Common.Resources.VSImageLibrary.Gradient; }
    3234    }
    3335
     36    [Storable]
    3437    public PreprocessingContext Context { get; private set; }
    35     public ITransactionalPreprocessingData PreprocessingData {
    36       get { return Context.Data; }
    37     }
     38
    3839
    3940    public DataAnalysisProblemData ProblemData {
     
    4748    }
    4849
    49     public CorrelationMatrixContent(PreprocessingContext context) {
     50    #region Constructor, Cloning & Persistence
     51    public CorrelationMatrixContent(PreprocessingContext context)
     52      : base(context.Data) {
    5053      Context = context;
    5154    }
     
    5558      Context = original.Context;
    5659    }
    57 
    5860    public override IDeepCloneable Clone(Cloner cloner) {
    5961      return new CorrelationMatrixContent(this, cloner);
    6062    }
     63
     64    [StorableConstructor]
     65    protected CorrelationMatrixContent(bool deserializing)
     66      : base(deserializing) { }
     67    #endregion
    6168
    6269    public event DataPreprocessingChangedEventHandler Changed {
  • trunk/sources/HeuristicLab.DataPreprocessing/3.4/Content/DataCompletenessChartContent.cs

    r15110 r15518  
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Core;
     25using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2526
    2627namespace HeuristicLab.DataPreprocessing {
    2728  [Item("Data Completeness Chart", "Represents a datacompleteness chart.")]
    28 
    29   public class DataCompletenessChartContent : Item, IViewShortcut {
     29  [StorableClass]
     30  public class DataCompletenessChartContent : PreprocessingContent, IViewShortcut {
    3031    public static new Image StaticItemImage {
    3132      get { return HeuristicLab.Common.Resources.VSImageLibrary.EditBrightnessContrast; }
    3233    }
    3334
    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) {
    3838    }
    3939
    4040    public DataCompletenessChartContent(DataCompletenessChartContent content, Cloner cloner)
    4141      : base(content, cloner) {
    42       SearchLogic = content.SearchLogic;
    4342    }
    44 
    4543    public override IDeepCloneable Clone(Cloner cloner) {
    4644      return new DataCompletenessChartContent(this, cloner);
    4745    }
     46
     47    [StorableConstructor]
     48    protected DataCompletenessChartContent(bool deserializing)
     49      : base(deserializing) { }
     50    #endregion
    4851  }
    4952}
  • trunk/sources/HeuristicLab.DataPreprocessing/3.4/Content/DataGridContent.cs

    r15110 r15518  
    2727using HeuristicLab.Core;
    2828using HeuristicLab.Data;
     29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     30using HeuristicLab.Random;
    2931
    3032namespace HeuristicLab.DataPreprocessing {
    31 
    3233  [Item("Data Grid", "Represents a data grid.")]
    33   public class DataGridContent : Item, IStringConvertibleMatrix, IViewShortcut {
     34  [StorableClass]
     35  public class DataGridContent : PreprocessingContent, IStringConvertibleMatrix, IViewShortcut {
    3436    public static new Image StaticItemImage {
    3537      get { return HeuristicLab.Common.Resources.VSImageLibrary.Table; }
    3638    }
    3739
    38     public ITransactionalPreprocessingData PreProcessingData { get; private set; }
    39 
    40     public ManipulationLogic ManipulationLogic { get; private set; }
    41     public FilterLogic FilterLogic { get; private set; }
    42 
    4340    public int Rows {
    44       get { return PreProcessingData.Rows; }
     41      get { return PreprocessingData.Rows; }
    4542      set { }
    4643    }
    4744
    4845    public int Columns {
    49       get { return PreProcessingData.Columns; }
     46      get { return PreprocessingData.Columns; }
    5047      set { }
    5148    }
    5249
    5350    public IEnumerable<string> ColumnNames {
    54       get { return PreProcessingData.VariableNames; }
     51      get { return PreprocessingData.VariableNames; }
    5552      set { }
    5653    }
     
    7168
    7269    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) {
    8681    }
    8782    public override IDeepCloneable Clone(Cloner cloner) {
     
    8984    }
    9085
     86    [StorableConstructor]
     87    protected DataGridContent(bool deserializing)
     88      : base(deserializing) { }
     89    #endregion
     90
    9191    public void DeleteRows(IEnumerable<int> rows) {
    92       PreProcessingData.DeleteRowsWithIndices(rows);
     92      PreprocessingData.DeleteRowsWithIndices(rows);
    9393    }
    9494
    9595    public void DeleteColumn(int column) {
    96       PreProcessingData.DeleteColumn(column);
     96      PreprocessingData.DeleteColumn(column);
    9797    }
    9898
    9999    public bool Validate(string value, out string errorMessage, int columnIndex) {
    100       return PreProcessingData.Validate(value, out errorMessage, columnIndex);
     100      return PreprocessingData.Validate(value, out errorMessage, columnIndex);
    101101    }
    102102
    103103    public string GetValue(int rowIndex, int columnIndex) {
    104       return PreProcessingData.GetCellAsString(columnIndex, rowIndex);
     104      return PreprocessingData.GetCellAsString(columnIndex, rowIndex);
    105105    }
    106106
    107107    public bool SetValue(string value, int rowIndex, int columnIndex) {
    108       return PreProcessingData.SetValue(value, columnIndex, rowIndex);
     108      return PreprocessingData.SetValue(value, columnIndex, rowIndex);
    109109    }
    110110
    111111    public event DataPreprocessingChangedEventHandler Changed {
    112       add { PreProcessingData.Changed += value; }
    113       remove { PreProcessingData.Changed -= value; }
     112      add { PreprocessingData.Changed += value; }
     113      remove { PreprocessingData.Changed -= value; }
    114114    }
    115115
     
    132132#pragma warning restore 0067
    133133    #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
    134347  }
    135348}
  • trunk/sources/HeuristicLab.DataPreprocessing/3.4/Content/FilterContent.cs

    r15110 r15518  
    2020#endregion
    2121
     22using System.Collections.Generic;
    2223using System.Drawing;
     24using System.Linq;
    2325using HeuristicLab.Common;
    2426using HeuristicLab.Core;
    2527using HeuristicLab.DataPreprocessing.Filter;
     28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2629
    2730namespace HeuristicLab.DataPreprocessing {
    2831  [Item("Filter", "Represents the filter grid.")]
    29   public class FilterContent : Item, IViewShortcut {
     32  [StorableClass]
     33  public class FilterContent : PreprocessingContent, IViewShortcut {
    3034    public static new Image StaticItemImage {
    3135      get { return HeuristicLab.Common.Resources.VSImageLibrary.Filter; }
    3236    }
    33 
    34     public FilterLogic FilterLogic { get; private set; }
    35 
     37    [Storable]
    3638    public ICheckedItemCollection<IFilter> Filters { get; private set; }
    3739
     40    [Storable]
    3841    public bool IsAndCombination { get; set; }
    3942
    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) {
    4171      Filters = new CheckedItemCollection<IFilter>();
    4272      IsAndCombination = true;
    43       FilterLogic = filterLogic;
    4473    }
    4574
    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;
    4879    }
    49 
    5080    public override IDeepCloneable Clone(Cloner cloner) {
    5181      return new FilterContent(this, cloner);
    5282    }
     83
     84    [StorableConstructor]
     85    protected FilterContent(bool deserializing)
     86      : base(deserializing) { }
     87    #endregion
    5388  }
    5489}
  • trunk/sources/HeuristicLab.DataPreprocessing/3.4/Content/HistogramContent.cs

    r15210 r15518  
    2626using HeuristicLab.Common;
    2727using HeuristicLab.Core;
     28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2829
    2930namespace HeuristicLab.DataPreprocessing {
    3031  [Item("Histogram", "Represents the histogram grid.")]
     32  [StorableClass]
    3133  public class HistogramContent : PreprocessingChartContent {
    3234    public static new Image StaticItemImage {
     
    3436    }
    3537
     38    [Storable]
    3639    public string GroupingVariableName { get; set; }
    3740
     41    [Storable]
    3842    public int Bins { get; set; }
     43    [Storable]
    3944    public bool ExactBins { get; set; }
    4045
     46    [Storable]
    4147    public LegendOrder Order { get; set; }
    4248
     49    #region Constructor, Cloning & Persistence
    4350    public HistogramContent(IFilteredPreprocessingData preprocessingData)
    4451      : base(preprocessingData) {
     
    4754    }
    4855
    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;
    5162    }
    5263    public override IDeepCloneable Clone(Cloner cloner) {
    5364      return new HistogramContent(this, cloner);
    5465    }
     66
     67    [StorableConstructor]
     68    protected HistogramContent(bool deserializing)
     69      : base(deserializing) { }
     70    #endregion
    5571
    5672    public static DataTable CreateHistogram(IFilteredPreprocessingData preprocessingData, string variableName, string groupingVariableName, DataTableVisualProperties.DataTableHistogramAggregation aggregation, LegendOrder legendOrder = LegendOrder.Alphabetically) {
  • trunk/sources/HeuristicLab.DataPreprocessing/3.4/Content/LineChartContent.cs

    r15110 r15518  
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Core;
     25using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2526
    2627namespace HeuristicLab.DataPreprocessing {
    27 
    2828  [Item("Line Chart", "Represents the line chart grid.")]
     29  [StorableClass]
    2930  public class LineChartContent : PreprocessingChartContent {
    30     public bool AllInOneMode { get; set; }
    31 
    3231    public static new Image StaticItemImage {
    3332      get { return HeuristicLab.Common.Resources.VSImageLibrary.Performance; }
    3433    }
    3534
     35    [Storable]
     36    public bool AllInOneMode { get; set; }
     37
     38
     39    #region Constructor, Cloning & Persistence
    3640    public LineChartContent(IFilteredPreprocessingData preprocessingData)
    3741      : base(preprocessingData) {
     
    3943    }
    4044
    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;
    4448    }
    4549    public override IDeepCloneable Clone(Cloner cloner) {
    4650      return new LineChartContent(this, cloner);
    4751    }
     52
     53    [StorableConstructor]
     54    protected LineChartContent(bool deserializing)
     55      : base(deserializing) { }
     56    #endregion
    4857  }
    4958}
  • trunk/sources/HeuristicLab.DataPreprocessing/3.4/Content/ManipulationContent.cs

    r15110 r15518  
    2020#endregion
    2121
     22using System;
     23using System.Collections.Generic;
    2224using System.Drawing;
     25using System.Linq;
    2326using HeuristicLab.Common;
    2427using HeuristicLab.Core;
     28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2529
    2630namespace HeuristicLab.DataPreprocessing {
    27 
    2831  [Item("Manipulation", "Represents the available manipulations on a data set.")]
    29   public class ManipulationContent : Item, IViewShortcut {
     32  [StorableClass]
     33  public class ManipulationContent : PreprocessingContent, IViewShortcut {
    3034    public static new Image StaticItemImage {
    3135      get { return HeuristicLab.Common.Resources.VSImageLibrary.Method; }
    3236    }
    3337
    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) {
    4241    }
    4342
    44     public ManipulationContent(ManipulationContent content, Cloner cloner) : base(content, cloner) { }
    45 
     43    public ManipulationContent(ManipulationContent original, Cloner cloner) :
     44      base(original, cloner) {
     45    }
    4646    public override IDeepCloneable Clone(Cloner cloner) {
    4747      return new ManipulationContent(this, cloner);
    4848    }
     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    }
    49125  }
    50126}
  • trunk/sources/HeuristicLab.DataPreprocessing/3.4/Content/MultiScatterPlotContent.cs

    r15110 r15518  
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Core;
     25using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2526
    2627namespace HeuristicLab.DataPreprocessing {
    27 
    2828  [Item("Multi Scatter Plot", "Represents a multi scatter plot.")]
     29  [StorableClass]
    2930  public class MultiScatterPlotContent : ScatterPlotContent {
    3031    public static new Image StaticItemImage {
     
    3233    }
    3334
     35    #region Constructor, Cloning & Persistence
    3436    public MultiScatterPlotContent(IFilteredPreprocessingData preprocessingData)
    3537      : base(preprocessingData) {
    3638    }
    3739
    38     public MultiScatterPlotContent(MultiScatterPlotContent content, Cloner cloner)
    39       : base(content, cloner) {
     40    public MultiScatterPlotContent(MultiScatterPlotContent original, Cloner cloner)
     41      : base(original, cloner) {
    4042    }
    41 
    4243    public override IDeepCloneable Clone(Cloner cloner) {
    4344      return new MultiScatterPlotContent(this, cloner);
    4445    }
     46
     47    [StorableConstructor]
     48    protected MultiScatterPlotContent(bool deserializing)
     49      : base(deserializing) { }
     50    #endregion
    4551  }
    4652}
  • trunk/sources/HeuristicLab.DataPreprocessing/3.4/Content/PreprocessingChartContent.cs

    r15210 r15518  
    2929using HeuristicLab.Core;
    3030using HeuristicLab.Data;
     31using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3132
    3233namespace HeuristicLab.DataPreprocessing {
    3334  [Item("PreprocessingChart", "Represents a preprocessing chart.")]
    34   public class PreprocessingChartContent : Item, IViewShortcut {
     35  [StorableClass]
     36  public class PreprocessingChartContent : PreprocessingContent, IViewShortcut {
    3537    public enum LegendOrder {
    3638      Alphabetically,
     
    4244    }
    4345
    44     private ICheckedItemList<StringValue> variableItemList = null;
     46    [Storable]
     47    private ICheckedItemList<StringValue> variableItemList;
    4548    public ICheckedItemList<StringValue> VariableItemList {
    4649      get {
    4750        if (variableItemList == null)
    4851          variableItemList = CreateVariableItemList(PreprocessingData);
    49         return this.variableItemList;
     52        return variableItemList;
    5053      }
    5154    }
    5255
    53     public IFilteredPreprocessingData PreprocessingData { get; private set; }
    5456    public event DataPreprocessingChangedEventHandler Changed {
    5557      add { PreprocessingData.Changed += value; }
     
    5759    }
    5860
    59     public PreprocessingChartContent(IFilteredPreprocessingData preprocessingData) {
    60       PreprocessingData = preprocessingData;
     61    #region Constructor, Cloning & Persistence
     62    public PreprocessingChartContent(IFilteredPreprocessingData preprocessingData)
     63       : base(preprocessingData) {
    6164    }
    6265
    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);
    6769    }
    6870    public override IDeepCloneable Clone(Cloner cloner) {
    6971      return new PreprocessingChartContent(this, cloner);
    7072    }
     73
     74    [StorableConstructor]
     75    protected PreprocessingChartContent(bool deserializing)
     76      : base(deserializing) { }
     77    #endregion
    7178
    7279    public DataRow CreateDataRow(string variableName, DataRowVisualProperties.DataRowChartType chartType) {
     
    7582
    7683    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      };
    8091      return row;
    8192    }
  • trunk/sources/HeuristicLab.DataPreprocessing/3.4/Content/ScatterPlotContent.cs

    r15210 r15518  
    2525using HeuristicLab.Analysis;
    2626using HeuristicLab.Common;
     27using HeuristicLab.Core;
     28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2729using HeuristicLab.Visualization.ChartControlsExtensions;
    2830
    2931namespace HeuristicLab.DataPreprocessing {
    30 
     32  [Item("ScatterPlotContent", "")]
     33  [StorableClass]
    3134  public abstract class ScatterPlotContent : PreprocessingChartContent {
     35    [Storable]
    3236    public string GroupingVariable { get; set; }
    3337
     38    #region Constructor, Cloning & Persistence
    3439    protected ScatterPlotContent(IFilteredPreprocessingData preprocessingData)
    3540      : base(preprocessingData) {
    3641    }
    3742
    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;
    4046    }
     47
     48    [StorableConstructor]
     49    protected ScatterPlotContent(bool deserializing)
     50      : base(deserializing) { }
     51    #endregion
    4152
    4253    public static ScatterPlot CreateScatterPlot(IFilteredPreprocessingData preprocessingData, string variableNameX, string variableNameY, string variableNameGroup = "-", LegendOrder legendOrder = LegendOrder.Alphabetically) {
  • trunk/sources/HeuristicLab.DataPreprocessing/3.4/Content/SingleScatterPlotContent.cs

    r15110 r15518  
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Core;
     25using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2526
    2627namespace HeuristicLab.DataPreprocessing {
    27 
    2828  [Item("Scatter Plot", "Represents a scatter plot.")]
     29  [StorableClass]
    2930  public class SingleScatterPlotContent : ScatterPlotContent {
    3031    public static new Image StaticItemImage {
     
    3233    }
    3334
     35    [Storable]
    3436    public string SelectedXVariable { get; set; }
     37    [Storable]
    3538    public string SelectedYVariable { get; set; }
    3639
     40    #region Constructor, Cloning & Persistence
    3741    public SingleScatterPlotContent(IFilteredPreprocessingData preprocessingData)
    3842      : base(preprocessingData) {
    3943    }
    4044
    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;
    4649    }
    47 
    4850    public override IDeepCloneable Clone(Cloner cloner) {
    4951      return new SingleScatterPlotContent(this, cloner);
    5052    }
     53
     54    [StorableConstructor]
     55    protected SingleScatterPlotContent(bool deserializing)
     56      : base(deserializing) { }
     57    #endregion
    5158  }
    5259}
  • trunk/sources/HeuristicLab.DataPreprocessing/3.4/Content/StatisticsContent.cs

    r15110 r15518  
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Core;
     25using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2526
    2627namespace HeuristicLab.DataPreprocessing {
    2728  [Item("Statistics", "Represents the statistics grid.")]
    28   public class StatisticsContent : Item, IViewShortcut {
     29  [StorableClass]
     30  public class StatisticsContent : PreprocessingContent, IViewShortcut {
    2931    public static new Image StaticItemImage {
    3032      get { return HeuristicLab.Common.Resources.VSImageLibrary.Object; }
    3133    }
    3234
    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) {
    3938    }
    4039
    41     public StatisticsContent(StatisticsContent content, Cloner cloner)
    42       : base(content, cloner) {
     40    public StatisticsContent(StatisticsContent original, Cloner cloner)
     41      : base(original, cloner) {
    4342    }
    44 
    4543    public override IDeepCloneable Clone(Cloner cloner) {
    4644      return new StatisticsContent(this, cloner);
    4745    }
    4846
     47    [StorableConstructor]
     48    protected StatisticsContent(bool deserializing)
     49      : base(deserializing) { }
     50    #endregion
     51
    4952    public event DataPreprocessingChangedEventHandler Changed {
    50       add { StatisticsLogic.Changed += value; }
    51       remove { StatisticsLogic.Changed -= value; }
     53      add { PreprocessingData.Changed += value; }
     54      remove { PreprocessingData.Changed -= value; }
    5255    }
    5356  }
  • trunk/sources/HeuristicLab.DataPreprocessing/3.4/Content/TransformationContent.cs

    r15110 r15518  
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Core;
     25using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2526using HeuristicLab.Problems.DataAnalysis;
    2627
    2728namespace HeuristicLab.DataPreprocessing {
    2829  [Item("Transformation", "Represents the transformation grid.")]
    29   public class TransformationContent : Item, IViewShortcut {
     30  [StorableClass]
     31  public class TransformationContent : PreprocessingContent, IViewShortcut {
    3032    public static new Image StaticItemImage {
    3133      get { return HeuristicLab.Common.Resources.VSImageLibrary.Method; }
    3234    }
    3335
    34     public IPreprocessingData Data { get; private set; }
    35     public FilterLogic FilterLogic { get; private set; }
    36 
     36    [Storable]
    3737    public ICheckedItemList<ITransformation> CheckedTransformationList { get; private set; }
    3838
    39     public TransformationContent(IPreprocessingData data, FilterLogic filterLogic) {
    40       Data = data;
     39    #region Constructor, Cloning & Persistence
     40    public TransformationContent(IFilteredPreprocessingData preprocessingData)
     41      : base(preprocessingData) {
    4142      CheckedTransformationList = new CheckedItemList<ITransformation>();
    42       FilterLogic = filterLogic;
    4343    }
    4444
    4545    public TransformationContent(TransformationContent original, Cloner cloner)
    4646      : base(original, cloner) {
    47       Data = original.Data;
    48       CheckedTransformationList = new CheckedItemList<ITransformation>(original.CheckedTransformationList);
     47      CheckedTransformationList = cloner.Clone(original.CheckedTransformationList);
    4948    }
    50 
    5149    public override IDeepCloneable Clone(Cloner cloner) {
    5250      return new TransformationContent(this, cloner);
    5351    }
     52
     53    [StorableConstructor]
     54    protected TransformationContent(bool deserializing)
     55      : base(deserializing) { }
     56    #endregion
    5457  }
    5558}
  • trunk/sources/HeuristicLab.DataPreprocessing/3.4/Data/FilteredPreprocessingData.cs

    r15110 r15518  
    2222using System;
    2323using System.Collections.Generic;
     24using System.Linq;
    2425using HeuristicLab.Common;
    2526using HeuristicLab.Core;
    2627using HeuristicLab.Data;
     28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2729using HeuristicLab.Problems.DataAnalysis;
    2830
    2931namespace HeuristicLab.DataPreprocessing {
    30   public class FilteredPreprocessingData : NamedItem, IFilteredPreprocessingData {
    31     private readonly ITransactionalPreprocessingData originalData;
    32     private ITransactionalPreprocessingData filteredData;
    33 
     32  [Item("FilteredPreprocessingData", "Represents filtered data used for preprocessing.")]
     33  [StorableClass]
     34  public sealed class FilteredPreprocessingData : NamedItem, IFilteredPreprocessingData {
     35
     36    [Storable]
     37    private readonly IPreprocessingData originalData;
     38    [Storable]
     39    private IPreprocessingData filteredData;
     40
     41    public IPreprocessingData ActiveData {
     42      get { return IsFiltered ? filteredData : originalData; }
     43    }
     44
     45    #region Constructor, Cloning & Persistence
     46    public FilteredPreprocessingData(IPreprocessingData preprocessingData)
     47      : base() {
     48      originalData = preprocessingData;
     49      filteredData = null;
     50    }
     51
     52    private FilteredPreprocessingData(FilteredPreprocessingData original, Cloner cloner)
     53      : base(original, cloner) {
     54      originalData = original.originalData;
     55      filteredData = original.filteredData;
     56    }
     57    public override IDeepCloneable Clone(Cloner cloner) {
     58      return new FilteredPreprocessingData(this, cloner);
     59    }
     60
     61    [StorableConstructor]
     62    private FilteredPreprocessingData(bool deserializing)
     63      : base(deserializing) { }
     64    #endregion
     65
     66    #region Cells
     67    public bool IsCellEmpty(int columnIndex, int rowIndex) {
     68      return ActiveData.IsCellEmpty(columnIndex, rowIndex);
     69    }
     70
     71    public T GetCell<T>(int columnIndex, int rowIndex) {
     72      return ActiveData.GetCell<T>(columnIndex, rowIndex);
     73    }
     74
     75    public void SetCell<T>(int columnIndex, int rowIndex, T value) {
     76      if (IsFiltered)
     77        throw new InvalidOperationException("SetValues not possible while data is filtered");
     78      originalData.SetCell<T>(columnIndex, rowIndex, value);
     79    }
     80
     81    public string GetCellAsString(int columnIndex, int rowIndex) {
     82      return ActiveData.GetCellAsString(columnIndex, rowIndex);
     83    }
     84
     85    public IList<T> GetValues<T>(int columnIndex, bool considerSelection) {
     86      return ActiveData.GetValues<T>(columnIndex, considerSelection);
     87    }
     88
     89    public void SetValues<T>(int columnIndex, IList<T> values) {
     90      if (IsFiltered)
     91        throw new InvalidOperationException("SetValues not possible while data is filtered");
     92
     93      originalData.SetValues<T>(columnIndex, values);
     94    }
     95
     96    public bool SetValue(string value, int columnIndex, int rowIndex) {
     97      if (IsFiltered)
     98        throw new InvalidOperationException("SetValue not possible while data is filtered");
     99      return originalData.SetValue(value, columnIndex, rowIndex);
     100    }
     101
     102    public int Columns {
     103      get { return ActiveData.Columns; }
     104    }
     105
     106    public int Rows {
     107      get { return ActiveData.Rows; }
     108    }
     109    #endregion
     110
     111    #region Rows
     112    public void InsertRow(int rowIndex) {
     113      if (IsFiltered)
     114        throw new InvalidOperationException("InsertRow not possible while data is filtered");
     115
     116      originalData.InsertRow(rowIndex);
     117    }
     118
     119    public void DeleteRow(int rowIndex) {
     120      if (IsFiltered)
     121        throw new InvalidOperationException("DeleteRow not possible while data is filtered");
     122
     123      originalData.DeleteRow(rowIndex);
     124    }
     125
     126    public void DeleteRowsWithIndices(IEnumerable<int> rows) {
     127      if (IsFiltered)
     128        throw new InvalidOperationException("DeleteRowsWithIndices not possible while data is filtered");
     129
     130      originalData.DeleteRowsWithIndices(rows);
     131    }
     132
     133    public void InsertColumn<T>(string variableName, int columnIndex) {
     134      if (IsFiltered)
     135        throw new InvalidOperationException("InsertColumn not possible while data is filtered");
     136
     137      originalData.InsertColumn<T>(variableName, columnIndex);
     138    }
     139
     140    public void DeleteColumn(int columnIndex) {
     141      if (IsFiltered)
     142        throw new InvalidOperationException("DeleteColumn not possible while data is filtered");
     143      originalData.DeleteColumn(columnIndex);
     144    }
     145
     146    public void RenameColumn(int columnIndex, string name) {
     147      if (IsFiltered)
     148        throw new InvalidOperationException("RenameColumn not possible while data is filtered");
     149      originalData.RenameColumn(columnIndex, name);
     150    }
     151
     152    public void RenameColumns(IList<string> names) {
     153      if (IsFiltered)
     154        throw new InvalidOperationException("RenameColumns not possible while data is filtered");
     155      originalData.RenameColumns(names);
     156    }
     157
     158    public bool AreAllStringColumns(IEnumerable<int> columnIndices) {
     159      return originalData.AreAllStringColumns(columnIndices);
     160    }
     161    #endregion
     162
     163    #region Variables
     164    public IEnumerable<string> VariableNames {
     165      get { return ActiveData.VariableNames; }
     166    }
     167    public IEnumerable<string> GetDoubleVariableNames() {
     168      return originalData.GetDoubleVariableNames();
     169    }
     170    public string GetVariableName(int columnIndex) {
     171      return ActiveData.GetVariableName(columnIndex);
     172    }
     173
     174    public int GetColumnIndex(string variableName) {
     175      return ActiveData.GetColumnIndex(variableName);
     176    }
     177
     178    public bool VariableHasType<T>(int columnIndex) {
     179      return originalData.VariableHasType<T>(columnIndex);
     180    }
     181
     182    public Type GetVariableType(int columnIndex) {
     183      return ActiveData.GetVariableType(columnIndex);
     184    }
     185
     186    public IList<string> InputVariables {
     187      get { return ActiveData.InputVariables; }
     188    }
     189
     190    public string TargetVariable {
     191      get { return ActiveData.TargetVariable; }
     192    } // optional
     193    #endregion
     194
     195    #region Partitions
    34196    public IntRange TrainingPartition {
    35197      get { return originalData.TrainingPartition; }
     
    39201      get { return originalData.TestPartition; }
    40202    }
    41 
     203    #endregion
     204
     205    #region Transformations
    42206    public IList<ITransformation> Transformations {
    43207      get { return originalData.Transformations; }
    44208    }
    45 
    46     public IEnumerable<string> VariableNames {
    47       get { return ActiveData.VariableNames; }
    48     }
    49 
    50     public IList<string> InputVariables { get { return ActiveData.InputVariables; } }
    51     public string TargetVariable { get { return ActiveData.TargetVariable; } } // optional
    52 
     209    #endregion
     210
     211    #region Validation
     212    public bool Validate(string value, out string errorMessage, int columnIndex) {
     213      return originalData.Validate(value, out errorMessage, columnIndex);
     214    }
     215    #endregion
     216
     217    #region Import & Export
     218    public void Import(IDataAnalysisProblemData problemData) {
     219      if (IsFiltered)
     220        throw new InvalidOperationException("Import not possible while data is filtered");
     221      originalData.Import(problemData);
     222    }
     223
     224    public Dataset ExportToDataset() {
     225      return originalData.ExportToDataset();
     226    }
     227    #endregion
     228
     229    #region Selection
    53230    public IDictionary<int, IList<int>> Selection {
    54231      get { return originalData.Selection; }
     
    56233    }
    57234
    58     public int Columns {
    59       get { return ActiveData.Columns; }
    60     }
    61 
    62     public int Rows {
    63       get { return ActiveData.Rows; }
    64     }
    65 
    66     public ITransactionalPreprocessingData ActiveData {
    67       get { return IsFiltered ? filteredData : originalData; }
     235    public void ClearSelection() {
     236      originalData.ClearSelection();
     237    }
     238
     239    public event EventHandler SelectionChanged {
     240      add { originalData.SelectionChanged += value; }
     241      remove { originalData.SelectionChanged -= value; }
     242    }
     243    #endregion
     244
     245    #region Transactions
     246    public event DataPreprocessingChangedEventHandler Changed {
     247      add { originalData.Changed += value; }
     248      remove { originalData.Changed -= value; }
    68249    }
    69250
     
    72253    }
    73254
    74     public bool IsFiltered {
    75       get { return filteredData != null; }
    76     }
    77 
    78 
    79     public FilteredPreprocessingData(ITransactionalPreprocessingData preporcessingData)
    80       : base() {
    81       originalData = preporcessingData;
    82       filteredData = null;
    83     }
    84 
    85     protected FilteredPreprocessingData(FilteredPreprocessingData original, Cloner cloner)
    86       : base(original, cloner) {
    87       originalData = original.originalData;
    88       filteredData = original.filteredData;
    89     }
    90     public override IDeepCloneable Clone(Cloner cloner) {
    91       return new FilteredPreprocessingData(this, cloner);
    92     }
    93 
    94     public T GetCell<T>(int columnIndex, int rowIndex) {
    95       return ActiveData.GetCell<T>(columnIndex, rowIndex);
    96     }
    97 
    98     public void SetCell<T>(int columnIndex, int rowIndex, T value) {
    99       if (IsFiltered)
    100         throw new InvalidOperationException("SetValues not possible while data is filtered");
    101       originalData.SetCell<T>(columnIndex, rowIndex, value);
    102     }
    103 
    104     public string GetCellAsString(int columnIndex, int rowIndex) {
    105       return ActiveData.GetCellAsString(columnIndex, rowIndex);
    106     }
    107 
    108     public IList<T> GetValues<T>(int columnIndex, bool considerSelection) {
    109       return ActiveData.GetValues<T>(columnIndex, considerSelection);
    110     }
    111 
    112     public void SetValues<T>(int columnIndex, IList<T> values) {
    113       if (IsFiltered)
    114         throw new InvalidOperationException("SetValues not possible while data is filtered");
    115 
    116       originalData.SetValues<T>(columnIndex, values);
    117     }
    118 
    119     public void InsertRow(int rowIndex) {
    120       if (IsFiltered)
    121         throw new InvalidOperationException("InsertRow not possible while data is filtered");
    122 
    123       originalData.InsertRow(rowIndex);
    124     }
    125 
    126     public void DeleteRow(int rowIndex) {
    127       if (IsFiltered)
    128         throw new InvalidOperationException("DeleteRow not possible while data is filtered");
    129 
    130       originalData.DeleteRow(rowIndex);
    131     }
    132 
    133     public void InsertColumn<T>(string variableName, int columnIndex) {
    134       if (IsFiltered)
    135         throw new InvalidOperationException("InsertColumn not possible while data is filtered");
    136 
    137       originalData.InsertColumn<T>(variableName, columnIndex);
    138     }
    139 
    140     public void DeleteColumn(int columnIndex) {
    141       if (IsFiltered)
    142         throw new InvalidOperationException("DeleteColumn not possible while data is filtered");
    143       originalData.DeleteColumn(columnIndex);
    144     }
    145 
    146     public void RenameColumn(int columnIndex, string name) {
    147       if (IsFiltered)
    148         throw new InvalidOperationException("RenameColumn not possible while data is filtered");
    149       originalData.RenameColumn(columnIndex, name);
    150     }
    151 
    152     public void RenameColumns(IList<string> names) {
    153       if (IsFiltered)
    154         throw new InvalidOperationException("RenameColumns not possible while data is filtered");
    155       originalData.RenameColumns(names);
    156     }
    157 
    158     public string GetVariableName(int columnIndex) {
    159       return ActiveData.GetVariableName(columnIndex);
    160     }
    161 
    162     public int GetColumnIndex(string variableName) {
    163       return ActiveData.GetColumnIndex(variableName);
    164     }
    165 
    166     public bool VariableHasType<T>(int columnIndex) {
    167       return originalData.VariableHasType<T>(columnIndex);
    168     }
    169 
    170     public Dataset ExportToDataset() {
    171       return originalData.ExportToDataset();
    172     }
    173 
    174     public void SetFilter(bool[] rowFilters) {
    175       filteredData = (ITransactionalPreprocessingData)originalData.Clone();
     255    public void Undo() {
     256      if (IsFiltered)
     257        throw new InvalidOperationException("Undo not possible while data is filtered");
     258
     259      originalData.Undo();
     260    }
     261
     262    public void InTransaction(Action action, DataPreprocessingChangedEventType type = DataPreprocessingChangedEventType.Any) {
     263      if (IsFiltered)
     264        throw new InvalidOperationException("Transaction not possible while data is filtered");
     265      originalData.InTransaction(action, type);
     266    }
     267
     268    public void BeginTransaction(DataPreprocessingChangedEventType type) {
     269      if (IsFiltered)
     270        throw new InvalidOperationException("Transaction not possible while data is filtered");
     271      originalData.BeginTransaction(type);
     272    }
     273
     274    public void EndTransaction() {
     275      originalData.EndTransaction();
     276    }
     277    #endregion
     278
     279    #region Statistics
     280    public T GetMin<T>(int columnIndex, bool considerSelection = false, T emptyValue = default(T)) {
     281      return ActiveData.GetMin<T>(columnIndex, considerSelection, emptyValue);
     282    }
     283    public T GetMax<T>(int columnIndex, bool considerSelection = false, T emptyValue = default(T)) {
     284      return ActiveData.GetMax<T>(columnIndex, considerSelection, emptyValue);
     285    }
     286    public T GetMean<T>(int columnIndex, bool considerSelection = false, T emptyValue = default(T)) {
     287      return ActiveData.GetMean<T>(columnIndex, considerSelection, emptyValue);
     288    }
     289    public T GetMedian<T>(int columnIndex, bool considerSelection = false, T emptyValue = default(T)) where T : IComparable<T> {
     290      return ActiveData.GetMean<T>(columnIndex, considerSelection, emptyValue);
     291    }
     292    public T GetMode<T>(int columnIndex, bool considerSelection = false, T emptyValue = default(T)) where T : IEquatable<T> {
     293      return ActiveData.GetMode<T>(columnIndex, considerSelection, emptyValue);
     294    }
     295    public T GetStandardDeviation<T>(int columnIndex, bool considerSelection = false, T emptyValue = default(T)) {
     296      return ActiveData.GetStandardDeviation<T>(columnIndex, considerSelection, emptyValue);
     297    }
     298    public T GetVariance<T>(int columnIndex, bool considerSelection = false, T emptyValue = default(T)) {
     299      return ActiveData.GetVariance<T>(columnIndex, considerSelection, emptyValue);
     300    }
     301    public T GetQuantile<T>(double alpha, int columnIndex, bool considerSelection = false, T emptyValue = default(T)) where T : IComparable<T> {
     302      return ActiveData.GetQuantile<T>(alpha, columnIndex, considerSelection, emptyValue);
     303    }
     304    public int GetDistinctValues<T>(int columnIndex, bool considerSelection = false) {
     305      return ActiveData.GetDistinctValues<T>(columnIndex, considerSelection);
     306    }
     307
     308    public int GetMissingValueCount() {
     309      return ActiveData.GetMissingValueCount();
     310    }
     311    public int GetMissingValueCount(int columnIndex) {
     312      return ActiveData.GetMissingValueCount(columnIndex);
     313    }
     314    public int GetRowMissingValueCount(int rowIndex) {
     315      return ActiveData.GetRowMissingValueCount(rowIndex);
     316    }
     317    #endregion
     318
     319    #region Filters
     320    public void SetFilter(bool[] remainingRows) {
     321      filteredData = (IPreprocessingData)originalData.Clone();
    176322      filteredData.InTransaction(() => {
    177         for (int row = (rowFilters.Length - 1); row >= 0; --row) {
    178           if (rowFilters[row]) {
    179             filteredData.DeleteRow(row);
     323        var remainingIndices = Enumerable.Range(0, remainingRows.Length).Where(x => remainingRows[x]);
     324
     325        foreach (var v in filteredData.VariableNames) {
     326          var ci = filteredData.GetColumnIndex(v);
     327          if (filteredData.VariableHasType<double>(ci)) {
     328            var values = filteredData.GetValues<double>(ci);
     329            var filteredValues = remainingIndices.Select(x => values[x]).ToList();
     330            filteredData.SetValues(ci, filteredValues);
     331          } else if (filteredData.VariableHasType<DateTime>(ci)) {
     332            var values = filteredData.GetValues<DateTime>(ci);
     333            var filteredValues = remainingIndices.Select(x => values[x]).ToList();
     334            filteredData.SetValues(ci, filteredValues);
     335          } else if (filteredData.VariableHasType<string>(ci)) {
     336            var values = filteredData.GetValues<string>(ci);
     337            var filteredValues = remainingIndices.Select(x => values[x]).ToList();
     338            filteredData.SetValues(ci, filteredValues);
    180339          }
    181340        }
     
    206365    }
    207366
     367    public bool IsFiltered {
     368      get { return filteredData != null; }
     369    }
     370
     371    public event EventHandler FilterChanged;
     372
    208373    private void OnFilterChanged() {
    209374      if (FilterChanged != null) {
     
    211376      }
    212377    }
    213 
    214     public event DataPreprocessingChangedEventHandler Changed {
    215       add { originalData.Changed += value; }
    216       remove { originalData.Changed -= value; }
    217     }
    218 
    219     public bool SetValue(string value, int columnIndex, int rowIndex) {
    220       if (IsFiltered)
    221         throw new InvalidOperationException("SetValue not possible while data is filtered");
    222       return originalData.SetValue(value, columnIndex, rowIndex);
    223     }
    224 
    225     public bool AreAllStringColumns(IEnumerable<int> columnIndices) {
    226       return originalData.AreAllStringColumns(columnIndices);
    227     }
    228 
    229     public void DeleteRowsWithIndices(IEnumerable<int> rows) {
    230       if (IsFiltered)
    231         throw new InvalidOperationException("DeleteRowsWithIndices not possible while data is filtered");
    232 
    233       originalData.DeleteRowsWithIndices(rows);
    234     }
    235 
    236     public void Undo() {
    237       if (IsFiltered)
    238         throw new InvalidOperationException("Undo not possible while data is filtered");
    239 
    240       originalData.Undo();
    241     }
    242 
    243     public void InTransaction(Action action, DataPreprocessingChangedEventType type = DataPreprocessingChangedEventType.Any) {
    244       if (IsFiltered)
    245         throw new InvalidOperationException("Transaction not possible while data is filtered");
    246       originalData.InTransaction(action, type);
    247     }
    248 
    249     public void BeginTransaction(DataPreprocessingChangedEventType type) {
    250       if (IsFiltered)
    251         throw new InvalidOperationException("Transaction not possible while data is filtered");
    252       originalData.BeginTransaction(type);
    253     }
    254 
    255     public void EndTransaction() {
    256       originalData.EndTransaction();
    257     }
    258 
    259     public IEnumerable<string> GetDoubleVariableNames() {
    260       return originalData.GetDoubleVariableNames();
    261     }
    262 
    263     public void ClearSelection() {
    264       originalData.ClearSelection();
    265     }
    266 
    267     public event EventHandler SelectionChanged {
    268       add { originalData.SelectionChanged += value; }
    269       remove { originalData.SelectionChanged -= value; }
    270     }
    271 
    272     #region IPreprocessingData Members
    273     public bool Validate(string value, out string errorMessage, int columnIndex) {
    274       return originalData.Validate(value, out errorMessage, columnIndex);
    275     }
    276 
    277     public event EventHandler FilterChanged;
    278378    #endregion
    279379  }
  • trunk/sources/HeuristicLab.DataPreprocessing/3.4/Data/IFilteredPreprocessingData.cs

    r14185 r15518  
    2323
    2424namespace HeuristicLab.DataPreprocessing {
    25   public interface IFilteredPreprocessingData : ITransactionalPreprocessingData {
    26     void SetFilter(bool[] rowFilters);
     25  public interface IFilteredPreprocessingData : IPreprocessingData {
     26    #region Filters
     27    void SetFilter(bool[] remainingRows);
    2728    void PersistFilter();
    2829    void ResetFilter();
     
    3031
    3132    event EventHandler FilterChanged;
     33    #endregion
    3234  }
    3335}
  • trunk/sources/HeuristicLab.DataPreprocessing/3.4/Data/IPreprocessingData.cs

    r15110 r15518  
    2828namespace HeuristicLab.DataPreprocessing {
    2929  public interface IPreprocessingData : INamedItem {
     30    #region Cells
     31    bool IsCellEmpty(int columnIndex, int rowIndex);
    3032    T GetCell<T>(int columnIndex, int rowIndex);
    3133
     
    3941    bool SetValue(string value, int columnIndex, int rowIndex);
    4042
     43    int Columns { get; }
     44    int Rows { get; }
     45    #endregion
     46
     47    #region Rows
    4148    void InsertRow(int rowIndex);
    4249    void DeleteRow(int rowIndex);
     
    5057
    5158    bool AreAllStringColumns(IEnumerable<int> columnIndices);
    52     bool Validate(string value, out string errorMessage, int columnIndex);
     59    #endregion
    5360
    54     IntRange TrainingPartition { get; }
    55     IntRange TestPartition { get; }
    56 
    57     IList<ITransformation> Transformations { get; }
    58 
     61    #region Variables
    5962    IEnumerable<string> VariableNames { get; }
    6063    IEnumerable<string> GetDoubleVariableNames();
     
    6366
    6467    bool VariableHasType<T>(int columnIndex);
     68    Type GetVariableType(int columnIndex);
    6569
    6670    IList<string> InputVariables { get; }
    6771    string TargetVariable { get; } // optional
     72    #endregion
    6873
    69     int Columns { get; }
    70     int Rows { get; }
     74    #region Partitions
     75    IntRange TrainingPartition { get; }
     76    IntRange TestPartition { get; }
     77    #endregion
    7178
     79    #region Transformations
     80    IList<ITransformation> Transformations { get; }
     81    #endregion
     82
     83    #region Validation
     84    bool Validate(string value, out string errorMessage, int columnIndex);
     85    #endregion
     86
     87    #region Import & Export
     88    void Import(IDataAnalysisProblemData problemData);
    7289    Dataset ExportToDataset();
     90    #endregion
    7391
     92    #region Selection
    7493    IDictionary<int, IList<int>> Selection { get; set; }
    7594    void ClearSelection();
    7695
    7796    event EventHandler SelectionChanged;
     97    #endregion
     98
     99    #region Transactions
     100    event DataPreprocessingChangedEventHandler Changed;
     101
     102    bool IsUndoAvailable { get; }
     103    void Undo();
     104    void InTransaction(Action action, DataPreprocessingChangedEventType type = DataPreprocessingChangedEventType.Any);
     105    void BeginTransaction(DataPreprocessingChangedEventType type);
     106    void EndTransaction();
     107    #endregion
     108
     109    #region Statistics
     110    T GetMin<T>(int columnIndex, bool considerSelection = false, T emptyValue = default(T));
     111    T GetMax<T>(int columnIndex, bool considerSelection = false, T emptyValue = default(T));
     112    T GetMean<T>(int columnIndex, bool considerSelection = false, T emptyValue = default(T));
     113    T GetMedian<T>(int columnIndex, bool considerSelection = false, T emptyValue = default(T)) where T : IComparable<T>;
     114    T GetMode<T>(int columnIndex, bool considerSelection = false, T emptyValue = default(T)) where T : IEquatable<T>;
     115    T GetStandardDeviation<T>(int columnIndex, bool considerSelection = false, T emptyValue = default(T));
     116    T GetVariance<T>(int columnIndex, bool considerSelection = false, T emptyValue = default(T));
     117    T GetQuantile<T>(double alpha, int columnIndex, bool considerSelection = false, T emptyValue = default(T)) where T : IComparable<T>;
     118    int GetDistinctValues<T>(int columnIndex, bool considerSelection = false);
     119
     120    int GetMissingValueCount();
     121    int GetMissingValueCount(int columnIndex);
     122    int GetRowMissingValueCount(int rowIndex);
     123    #endregion
    78124  }
    79125}
  • trunk/sources/HeuristicLab.DataPreprocessing/3.4/Data/PreprocessingData.cs

    r15110 r15518  
    2323using System.Collections;
    2424using System.Collections.Generic;
     25using System.Globalization;
    2526using System.Linq;
    2627using HeuristicLab.Common;
    2728using HeuristicLab.Core;
    2829using HeuristicLab.Data;
     30using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2931using HeuristicLab.Problems.DataAnalysis;
    3032
     
    3234
    3335  [Item("PreprocessingData", "Represents data used for preprocessing.")]
    34   public abstract class PreprocessingData : NamedItem, IPreprocessingData {
    35     public IntRange TrainingPartition { get; set; }
    36     public IntRange TestPartition { get; set; }
    37 
    38     public IList<ITransformation> Transformations { get; protected set; }
    39 
     36  [StorableClass]
     37  public class PreprocessingData : NamedItem, IPreprocessingData {
     38
     39    [Storable]
    4040    protected IList<IList> variableValues;
     41    [Storable]
    4142    protected IList<string> variableNames;
    4243
    43     public IEnumerable<string> VariableNames {
    44       get { return variableNames; }
    45     }
    46 
    47     public IEnumerable<string> GetDoubleVariableNames() {
    48       var doubleVariableNames = new List<string>();
    49       for (int i = 0; i < Columns; ++i) {
    50         if (VariableHasType<double>(i)) {
    51           doubleVariableNames.Add(variableNames[i]);
    52         }
    53       }
    54       return doubleVariableNames;
    55     }
    56 
    57     public IList<string> InputVariables { get; private set; }
    58     public string TargetVariable { get; private set; } // optional
    59 
    60     public int Columns {
    61       get { return variableNames.Count; }
    62     }
    63 
    64     public int Rows {
    65       get { return variableValues.Count > 0 ? variableValues[0].Count : 0; }
    66     }
    67 
    68     protected IDictionary<int, IList<int>> selection;
    69     public IDictionary<int, IList<int>> Selection {
    70       get { return selection; }
    71       set {
    72         selection = value;
    73         OnSelectionChanged();
    74       }
     44    #region Constructor, Cloning & Persistence
     45    public PreprocessingData(IDataAnalysisProblemData problemData)
     46      : base() {
     47      Name = "Preprocessing Data";
     48
     49      Transformations = new List<ITransformation>();
     50      selection = new Dictionary<int, IList<int>>();
     51
     52      Import(problemData);
     53
     54      RegisterEventHandler();
    7555    }
    7656
     
    8868      RegisterEventHandler();
    8969    }
    90 
    91     protected PreprocessingData(IDataAnalysisProblemData problemData)
    92       : base() {
    93       Name = "Preprocessing Data";
    94 
    95       Transformations = new List<ITransformation>();
    96       selection = new Dictionary<int, IList<int>>();
    97 
    98       Import(problemData);
    99 
     70    public override IDeepCloneable Clone(Cloner cloner) {
     71      return new PreprocessingData(this, cloner);
     72    }
     73
     74    [StorableConstructor]
     75    protected PreprocessingData(bool deserializing)
     76      : base(deserializing) { }
     77    [StorableHook(HookType.AfterDeserialization)]
     78    private void AfterDeserialization() {
    10079      RegisterEventHandler();
    10180    }
    10281
     82    private void RegisterEventHandler() {
     83      Changed += (s, e) => {
     84        switch (e.Type) {
     85          case DataPreprocessingChangedEventType.DeleteRow:
     86          case DataPreprocessingChangedEventType.Any:
     87          case DataPreprocessingChangedEventType.Transformation:
     88            int maxRowIndex = Math.Max(0, Rows);
     89            TrainingPartition.Start = Math.Min(TrainingPartition.Start, maxRowIndex);
     90            TrainingPartition.End = Math.Min(TrainingPartition.End, maxRowIndex);
     91            TestPartition.Start = Math.Min(TestPartition.Start, maxRowIndex);
     92            TestPartition.End = Math.Min(TestPartition.End, maxRowIndex);
     93            break;
     94        }
     95      };
     96    }
     97    #endregion
     98
     99    #region Cells
     100    public bool IsCellEmpty(int columnIndex, int rowIndex) {
     101      var value = variableValues[columnIndex][rowIndex];
     102      return IsMissingValue(value);
     103    }
     104
     105    public T GetCell<T>(int columnIndex, int rowIndex) {
     106      return (T)variableValues[columnIndex][rowIndex];
     107    }
     108
     109    public void SetCell<T>(int columnIndex, int rowIndex, T value) {
     110      SaveSnapshot(DataPreprocessingChangedEventType.ChangeItem, columnIndex, rowIndex);
     111
     112      for (int i = Rows; i <= rowIndex; i++)
     113        InsertRow(i);
     114      for (int i = Columns; i <= columnIndex; i++)
     115        InsertColumn<T>(i.ToString(), i);
     116
     117      variableValues[columnIndex][rowIndex] = value;
     118      if (!IsInTransaction)
     119        OnChanged(DataPreprocessingChangedEventType.ChangeItem, columnIndex, rowIndex);
     120    }
     121
     122    public string GetCellAsString(int columnIndex, int rowIndex) {
     123      return variableValues[columnIndex][rowIndex].ToString();
     124    }
     125
     126    public IList<T> GetValues<T>(int columnIndex, bool considerSelection) {
     127      if (considerSelection) {
     128        var list = new List<T>();
     129        foreach (var rowIdx in selection[columnIndex]) {
     130          list.Add((T)variableValues[columnIndex][rowIdx]);
     131        }
     132        return list;
     133      } else {
     134        return (IList<T>)variableValues[columnIndex];
     135      }
     136    }
     137
     138    public void SetValues<T>(int columnIndex, IList<T> values) {
     139      SaveSnapshot(DataPreprocessingChangedEventType.ChangeColumn, columnIndex, -1);
     140      if (VariableHasType<T>(columnIndex)) {
     141        variableValues[columnIndex] = (IList)values;
     142      } else {
     143        throw new ArgumentException("The datatype of column " + columnIndex + " must be of type " + variableValues[columnIndex].GetType().Name + " but was " + typeof(T).Name);
     144      }
     145      if (!IsInTransaction)
     146        OnChanged(DataPreprocessingChangedEventType.ChangeColumn, columnIndex, -1);
     147    }
     148
     149    public bool SetValue(string value, int columnIndex, int rowIndex) {
     150      bool valid = false;
     151      if (VariableHasType<double>(columnIndex)) {
     152        double val;
     153        if (string.IsNullOrWhiteSpace(value)) {
     154          val = double.NaN;
     155          valid = true;
     156        } else {
     157          valid = double.TryParse(value, out val);
     158        }
     159        if (valid)
     160          SetCell(columnIndex, rowIndex, val);
     161      } else if (VariableHasType<string>(columnIndex)) {
     162        valid = value != null;
     163        if (valid)
     164          SetCell(columnIndex, rowIndex, value);
     165      } else if (VariableHasType<DateTime>(columnIndex)) {
     166        DateTime date;
     167        valid = DateTime.TryParse(value, out date);
     168        if (valid)
     169          SetCell(columnIndex, rowIndex, date);
     170      } else {
     171        throw new ArgumentException("column " + columnIndex + " contains a non supported type.");
     172      }
     173
     174      if (!IsInTransaction)
     175        OnChanged(DataPreprocessingChangedEventType.ChangeColumn, columnIndex, -1);
     176
     177      return valid;
     178    }
     179
     180    public int Columns {
     181      get { return variableNames.Count; }
     182    }
     183
     184    public int Rows {
     185      get { return variableValues.Count > 0 ? variableValues[0].Count : 0; }
     186    }
     187
     188    public static bool IsMissingValue(object value) {
     189      if (value is double) return double.IsNaN((double)value);
     190      if (value is string) return string.IsNullOrEmpty((string)value);
     191      if (value is DateTime) return ((DateTime)value).Equals(DateTime.MinValue);
     192      throw new ArgumentException();
     193    }
     194    #endregion
     195
     196    #region Rows
     197    public void InsertRow(int rowIndex) {
     198      SaveSnapshot(DataPreprocessingChangedEventType.DeleteRow, -1, rowIndex);
     199      foreach (IList column in variableValues) {
     200        Type type = column.GetType().GetGenericArguments()[0];
     201        column.Insert(rowIndex, type.IsValueType ? Activator.CreateInstance(type) : null);
     202      }
     203      if (TrainingPartition.Start <= rowIndex && rowIndex <= TrainingPartition.End) {
     204        TrainingPartition.End++;
     205        if (TrainingPartition.End <= TestPartition.Start) {
     206          TestPartition.Start++;
     207          TestPartition.End++;
     208        }
     209      } else if (TestPartition.Start <= rowIndex && rowIndex <= TestPartition.End) {
     210        TestPartition.End++;
     211        if (TestPartition.End <= TrainingPartition.Start) {
     212          TestPartition.Start++;
     213          TestPartition.End++;
     214        }
     215      }
     216      if (!IsInTransaction)
     217        OnChanged(DataPreprocessingChangedEventType.AddRow, -1, rowIndex);
     218    }
     219    public void DeleteRow(int rowIndex) {
     220      SaveSnapshot(DataPreprocessingChangedEventType.AddRow, -1, rowIndex);
     221      foreach (IList column in variableValues) {
     222        column.RemoveAt(rowIndex);
     223      }
     224      if (TrainingPartition.Start <= rowIndex && rowIndex <= TrainingPartition.End) {
     225        TrainingPartition.End--;
     226        if (TrainingPartition.End <= TestPartition.Start) {
     227          TestPartition.Start--;
     228          TestPartition.End--;
     229        }
     230      } else if (TestPartition.Start <= rowIndex && rowIndex <= TestPartition.End) {
     231        TestPartition.End--;
     232        if (TestPartition.End <= TrainingPartition.Start) {
     233          TestPartition.Start--;
     234          TestPartition.End--;
     235        }
     236      }
     237      if (!IsInTransaction)
     238        OnChanged(DataPreprocessingChangedEventType.DeleteRow, -1, rowIndex);
     239    }
     240    public void DeleteRowsWithIndices(IEnumerable<int> rows) {
     241      SaveSnapshot(DataPreprocessingChangedEventType.AddRow, -1, -1);
     242      foreach (int rowIndex in rows.OrderByDescending(x => x)) {
     243        foreach (IList column in variableValues) {
     244          column.RemoveAt(rowIndex);
     245        }
     246        if (TrainingPartition.Start <= rowIndex && rowIndex <= TrainingPartition.End) {
     247          TrainingPartition.End--;
     248          if (TrainingPartition.End <= TestPartition.Start) {
     249            TestPartition.Start--;
     250            TestPartition.End--;
     251          }
     252        } else if (TestPartition.Start <= rowIndex && rowIndex <= TestPartition.End) {
     253          TestPartition.End--;
     254          if (TestPartition.End <= TrainingPartition.Start) {
     255            TestPartition.Start--;
     256            TestPartition.End--;
     257          }
     258        }
     259      }
     260      if (!IsInTransaction)
     261        OnChanged(DataPreprocessingChangedEventType.DeleteRow, -1, -1);
     262    }
     263
     264    public void InsertColumn<T>(string variableName, int columnIndex) {
     265      SaveSnapshot(DataPreprocessingChangedEventType.DeleteColumn, columnIndex, -1);
     266      variableValues.Insert(columnIndex, new List<T>(Enumerable.Repeat(default(T), Rows)));
     267      variableNames.Insert(columnIndex, variableName);
     268      if (!IsInTransaction)
     269        OnChanged(DataPreprocessingChangedEventType.AddColumn, columnIndex, -1);
     270    }
     271
     272    public void DeleteColumn(int columnIndex) {
     273      SaveSnapshot(DataPreprocessingChangedEventType.AddColumn, columnIndex, -1);
     274      variableValues.RemoveAt(columnIndex);
     275      variableNames.RemoveAt(columnIndex);
     276      if (!IsInTransaction)
     277        OnChanged(DataPreprocessingChangedEventType.DeleteColumn, columnIndex, -1);
     278    }
     279
     280    public void RenameColumn(int columnIndex, string name) {
     281      SaveSnapshot(DataPreprocessingChangedEventType.ChangeColumn, columnIndex, -1);
     282      if (columnIndex < 0 || columnIndex > variableNames.Count)
     283        throw new ArgumentOutOfRangeException("columnIndex");
     284      variableNames[columnIndex] = name;
     285
     286      if (!IsInTransaction)
     287        OnChanged(DataPreprocessingChangedEventType.ChangeColumn, -1, -1);
     288    }
     289
     290    public void RenameColumns(IList<string> names) {
     291      if (names == null) throw new ArgumentNullException("names");
     292      if (names.Count != variableNames.Count) throw new ArgumentException("number of names must match the number of columns.", "names");
     293
     294      SaveSnapshot(DataPreprocessingChangedEventType.ChangeColumn, -1, -1);
     295      for (int i = 0; i < names.Count; i++)
     296        variableNames[i] = names[i];
     297
     298      if (!IsInTransaction)
     299        OnChanged(DataPreprocessingChangedEventType.ChangeColumn, -1, -1);
     300    }
     301
     302    public bool AreAllStringColumns(IEnumerable<int> columnIndices) {
     303      return columnIndices.All(x => VariableHasType<string>(x));
     304    }
     305    #endregion
     306
     307    #region Variables
     308    public IEnumerable<string> VariableNames {
     309      get { return variableNames; }
     310    }
     311
     312    public IEnumerable<string> GetDoubleVariableNames() {
     313      var doubleVariableNames = new List<string>();
     314      for (int i = 0; i < Columns; ++i) {
     315        if (VariableHasType<double>(i)) {
     316          doubleVariableNames.Add(variableNames[i]);
     317        }
     318      }
     319      return doubleVariableNames;
     320    }
     321
     322    public string GetVariableName(int columnIndex) {
     323      return variableNames[columnIndex];
     324    }
     325
     326    public int GetColumnIndex(string variableName) {
     327      return variableNames.IndexOf(variableName);
     328    }
     329
     330    public bool VariableHasType<T>(int columnIndex) {
     331      return columnIndex >= variableValues.Count || variableValues[columnIndex] is List<T>;
     332    }
     333
     334    public Type GetVariableType(int columnIndex) {
     335      var listType = variableValues[columnIndex].GetType();
     336      return listType.GenericTypeArguments.Single();
     337    }
     338
     339    public IList<string> InputVariables { get; private set; }
     340    public string TargetVariable { get; private set; } // optional
     341    #endregion
     342
     343    #region Partitions
     344    [Storable]
     345    public IntRange TrainingPartition { get; set; }
     346    [Storable]
     347    public IntRange TestPartition { get; set; }
     348    #endregion
     349
     350    #region Transformations
     351    [Storable]
     352    public IList<ITransformation> Transformations { get; protected set; }
     353    #endregion
     354
     355    #region Validation
     356    public bool Validate(string value, out string errorMessage, int columnIndex) {
     357      if (columnIndex < 0 || columnIndex > VariableNames.Count()) {
     358        throw new ArgumentOutOfRangeException("column index is out of range");
     359      }
     360
     361      bool valid = false;
     362      errorMessage = string.Empty;
     363      if (VariableHasType<double>(columnIndex)) {
     364        if (string.IsNullOrWhiteSpace(value)) {
     365          valid = true;
     366        } else {
     367          double val;
     368          valid = double.TryParse(value, out val);
     369          if (!valid) {
     370            errorMessage = "Invalid Value (Valid Value Format: \"" + FormatPatterns.GetDoubleFormatPattern() + "\")";
     371          }
     372        }
     373      } else if (VariableHasType<string>(columnIndex)) {
     374        valid = value != null;
     375        if (!valid) {
     376          errorMessage = "Invalid Value (string must not be null)";
     377        }
     378      } else if (VariableHasType<DateTime>(columnIndex)) {
     379        DateTime date;
     380        valid = DateTime.TryParse(value, out date);
     381        if (!valid) {
     382          errorMessage = "Invalid Value (Valid Value Format: \"" + CultureInfo.CurrentCulture.DateTimeFormat + "\"";
     383        }
     384      } else {
     385        throw new ArgumentException("column " + columnIndex + " contains a non supported type.");
     386      }
     387
     388      return valid;
     389    }
     390    #endregion
     391
     392    #region Import & Export
    103393    public void Import(IDataAnalysisProblemData problemData) {
    104394      Dataset dataset = (Dataset)problemData.Dataset;
     
    107397      TargetVariable = (problemData is IRegressionProblemData) ? ((IRegressionProblemData)problemData).TargetVariable
    108398        : (problemData is IClassificationProblemData) ? ((IClassificationProblemData)problemData).TargetVariable
    109         : null;
     399          : null;
    110400
    111401      int columnIndex = 0;
     
    128418    }
    129419
    130     private void RegisterEventHandler() {
    131       Changed += (s, e) => {
    132         switch (e.Type) {
    133           case DataPreprocessingChangedEventType.DeleteRow:
    134             CheckPartitionRanges();
    135             break;
    136           case DataPreprocessingChangedEventType.Any:
    137             CheckPartitionRanges();
    138             break;
    139           case DataPreprocessingChangedEventType.Transformation:
    140             CheckPartitionRanges();
    141             break;
    142         }
    143       };
    144     }
    145 
    146     private void CheckPartitionRanges() {
    147       int maxRowIndex = Math.Max(0, Rows);
    148       TrainingPartition.Start = Math.Min(TrainingPartition.Start, maxRowIndex);
    149       TrainingPartition.End = Math.Min(TrainingPartition.End, maxRowIndex);
    150       TestPartition.Start = Math.Min(TestPartition.Start, maxRowIndex);
    151       TestPartition.End = Math.Min(TestPartition.End, maxRowIndex);
    152     }
    153 
    154     protected IList<IList> CopyVariableValues(IList<IList> original) {
    155       var copy = new List<IList>(original);
    156       for (int i = 0; i < original.Count; ++i) {
    157         copy[i] = (IList)Activator.CreateInstance(original[i].GetType(), original[i]);
    158       }
    159       return copy;
    160     }
    161 
    162 
    163     #region IPreprocessingData Members
    164     public abstract T GetCell<T>(int columnIndex, int rowIndex);
    165 
    166     public abstract void SetCell<T>(int columnIndex, int rowIndex, T value);
    167 
    168     public abstract string GetCellAsString(int columnIndex, int rowIndex);
    169 
    170     public abstract string GetVariableName(int columnIndex);
    171 
    172     public abstract int GetColumnIndex(string variableName);
    173 
    174     public abstract bool VariableHasType<T>(int columnIndex);
    175 
    176     [Obsolete("use the index based variant, is faster")]
    177     public abstract IList<T> GetValues<T>(string variableName, bool considerSelection);
    178 
    179     public abstract IList<T> GetValues<T>(int columnIndex, bool considerSelection);
    180 
    181     public abstract void SetValues<T>(int columnIndex, IList<T> values);
    182 
    183     public abstract bool SetValue(string value, int columnIndex, int rowIndex);
    184 
    185     public abstract bool Validate(string value, out string errorMessage, int columnIndex);
    186 
    187     public abstract bool AreAllStringColumns(IEnumerable<int> columnIndices);
    188 
    189     public abstract void DeleteRowsWithIndices(IEnumerable<int> rows);
    190 
    191     public abstract void InsertRow(int rowIndex);
    192 
    193     public abstract void DeleteRow(int rowIndex);
    194 
    195     public abstract void InsertColumn<T>(string variableName, int columnIndex);
    196 
    197     public abstract void DeleteColumn(int columnIndex);
    198 
    199     public abstract void RenameColumn(int columnIndex, string name);
    200     public abstract void RenameColumns(IList<string> list);
    201 
    202     public abstract Dataset ExportToDataset();
    203 
    204     public abstract void ClearSelection();
    205 
    206     public abstract event EventHandler SelectionChanged;
    207     protected abstract void OnSelectionChanged();
     420    public Dataset ExportToDataset() {
     421      IList<IList> values = new List<IList>();
     422
     423      for (int i = 0; i < Columns; ++i) {
     424        values.Add(variableValues[i]);
     425      }
     426
     427      var dataset = new Dataset(variableNames, values);
     428      return dataset;
     429    }
     430    #endregion
     431
     432    #region Selection
     433    [Storable]
     434    protected IDictionary<int, IList<int>> selection;
     435    public IDictionary<int, IList<int>> Selection {
     436      get { return selection; }
     437      set {
     438        selection = value;
     439        OnSelectionChanged();
     440      }
     441    }
     442    public void ClearSelection() {
     443      Selection = new Dictionary<int, IList<int>>();
     444    }
     445
     446    public event EventHandler SelectionChanged;
     447    protected void OnSelectionChanged() {
     448      var listeners = SelectionChanged;
     449      if (listeners != null) listeners(this, EventArgs.Empty);
     450    }
     451    #endregion
     452
     453    #region Transactions
     454    // Stapshot/History are nost storable/cloneable on purpose
     455    private class Snapshot {
     456      public IList<IList> VariableValues { get; set; }
     457      public IList<string> VariableNames { get; set; }
     458
     459      public IntRange TrainingPartition { get; set; }
     460      public IntRange TestPartition { get; set; }
     461      public IList<ITransformation> Transformations { get; set; }
     462      public DataPreprocessingChangedEventType ChangedType { get; set; }
     463
     464      public int ChangedColumn { get; set; }
     465      public int ChangedRow { get; set; }
     466    }
    208467
    209468    public event DataPreprocessingChangedEventHandler Changed;
     
    212471      if (listeners != null) listeners(this, new DataPreprocessingChangedEventArgs(type, column, row));
    213472    }
    214     #endregion
     473
     474    private const int MAX_UNDO_DEPTH = 5;
     475
     476    private readonly IList<Snapshot> undoHistory = new List<Snapshot>();
     477    private readonly Stack<DataPreprocessingChangedEventType> eventStack = new Stack<DataPreprocessingChangedEventType>();
     478
     479    public bool IsInTransaction { get { return eventStack.Count > 0; } }
     480
     481    private void SaveSnapshot(DataPreprocessingChangedEventType changedType, int column, int row) {
     482      if (IsInTransaction) return;
     483
     484      var currentSnapshot = new Snapshot {
     485        VariableValues = CopyVariableValues(variableValues),
     486        VariableNames = new List<string>(variableNames),
     487        TrainingPartition = new IntRange(TrainingPartition.Start, TrainingPartition.End),
     488        TestPartition = new IntRange(TestPartition.Start, TestPartition.End),
     489        Transformations = new List<ITransformation>(Transformations),
     490        ChangedType = changedType,
     491        ChangedColumn = column,
     492        ChangedRow = row
     493      };
     494
     495      if (undoHistory.Count >= MAX_UNDO_DEPTH)
     496        undoHistory.RemoveAt(0);
     497
     498      undoHistory.Add(currentSnapshot);
     499    }
     500
     501    public bool IsUndoAvailable {
     502      get { return undoHistory.Count > 0; }
     503    }
     504
     505    public void Undo() {
     506      if (IsUndoAvailable) {
     507        Snapshot previousSnapshot = undoHistory[undoHistory.Count - 1];
     508        variableValues = previousSnapshot.VariableValues;
     509        variableNames = previousSnapshot.VariableNames;
     510        TrainingPartition = previousSnapshot.TrainingPartition;
     511        TestPartition = previousSnapshot.TestPartition;
     512        Transformations = previousSnapshot.Transformations;
     513        undoHistory.Remove(previousSnapshot);
     514        OnChanged(previousSnapshot.ChangedType,
     515          previousSnapshot.ChangedColumn,
     516          previousSnapshot.ChangedRow);
     517      }
     518    }
     519
     520    public void InTransaction(Action action, DataPreprocessingChangedEventType type = DataPreprocessingChangedEventType.Any) {
     521      BeginTransaction(type);
     522      action();
     523      EndTransaction();
     524    }
     525
     526    public void BeginTransaction(DataPreprocessingChangedEventType type) {
     527      SaveSnapshot(type, -1, -1);
     528      eventStack.Push(type);
     529    }
     530
     531    public void EndTransaction() {
     532      if (eventStack.Count == 0)
     533        throw new InvalidOperationException("There is no open transaction that can be ended.");
     534
     535      var @event = eventStack.Pop();
     536      OnChanged(@event, -1, -1);
     537    }
     538    #endregion
     539
     540    #region Statistics
     541    public T GetMin<T>(int columnIndex, bool considerSelection = false, T emptyValue = default(T)) {
     542      var values = GetValuesWithoutMissingValues<T>(columnIndex, considerSelection);
     543      return values.Any() ? values.Min() : emptyValue;
     544    }
     545
     546    public T GetMax<T>(int columnIndex, bool considerSelection = false, T emptyValue = default(T)) {
     547      var values = GetValuesWithoutMissingValues<T>(columnIndex, considerSelection);
     548      return values.Any() ? values.Max() : emptyValue;
     549    }
     550
     551    public T GetMean<T>(int columnIndex, bool considerSelection = false, T emptyValue = default(T)) {
     552      if (typeof(T) == typeof(double)) {
     553        var values = GetValuesWithoutMissingValues<double>(columnIndex, considerSelection);
     554        return values.Any() ? Convert<T>(values.Average()) : emptyValue;
     555      }
     556      if (typeof(T) == typeof(string)) {
     557        return Convert<T>(string.Empty);
     558      }
     559      if (typeof(T) == typeof(DateTime)) {
     560        var values = GetValuesWithoutMissingValues<DateTime>(columnIndex, considerSelection);
     561        return values.Any() ? Convert<T>(AggregateAsDouble(values, Enumerable.Average)) : emptyValue;
     562      }
     563
     564      throw new InvalidOperationException(typeof(T) + " not supported");
     565    }
     566
     567    public T GetMedian<T>(int columnIndex, bool considerSelection = false, T emptyValue = default(T)) where T : IComparable<T> {
     568      if (typeof(T) == typeof(double)) {// IEnumerable<double> is faster 
     569        var doubleValues = GetValuesWithoutMissingValues<double>(columnIndex, considerSelection);
     570        return doubleValues.Any() ? Convert<T>(doubleValues.Median()) : emptyValue;
     571      }
     572      var values = GetValuesWithoutMissingValues<T>(columnIndex, considerSelection);
     573      return values.Any() ? values.Quantile(0.5) : emptyValue;
     574    }
     575
     576    public T GetMode<T>(int columnIndex, bool considerSelection = false, T emptyValue = default(T)) where T : IEquatable<T> {
     577      var values = GetValuesWithoutMissingValues<T>(columnIndex, considerSelection);
     578      return values.Any() ? values.GroupBy(x => x).OrderByDescending(g => g.Count()).Select(g => g.Key).First() : emptyValue;
     579    }
     580
     581    public T GetStandardDeviation<T>(int columnIndex, bool considerSelection = false, T emptyValue = default(T)) {
     582      if (typeof(T) == typeof(double)) {
     583        var values = GetValuesWithoutMissingValues<double>(columnIndex, considerSelection);
     584        return values.Any() ? Convert<T>(values.StandardDeviation()) : emptyValue;
     585      }
     586      // For DateTime, std.dev / variance would have to be TimeSpan
     587      //if (typeof(T) == typeof(DateTime)) {
     588      //  var values = GetValuesWithoutMissingValues<DateTime>(columnIndex, considerSelection);
     589      //  return values.Any() ? Convert<T>(AggregateAsDouble(values, EnumerableStatisticExtensions.StandardDeviation)) : emptyValue;
     590      //}
     591      return default(T);
     592    }
     593
     594    public T GetVariance<T>(int columnIndex, bool considerSelection = false, T emptyValue = default(T)) {
     595      if (typeof(T) == typeof(double)) {
     596        var values = GetValuesWithoutMissingValues<double>(columnIndex, considerSelection);
     597        return values.Any() ? Convert<T>(values.Variance()) : emptyValue;
     598      }
     599      // DateTime variance often overflows long, thus the corresponding DateTime is invalid
     600      //if (typeof(T) == typeof(DateTime)) {
     601      //  var values = GetValuesWithoutMissingValues<DateTime>(columnIndex, considerSelection);
     602      //  return values.Any() ? Convert<T>(AggregateAsDouble(values, EnumerableStatisticExtensions.Variance)) : emptyValue;
     603      //}
     604      return default(T);
     605    }
     606
     607    public T GetQuantile<T>(double alpha, int columnIndex, bool considerSelection = false, T emptyValue = default(T)) where T : IComparable<T> {
     608      if (typeof(T) == typeof(double)) {// IEnumerable<double> is faster 
     609        var doubleValues = GetValuesWithoutMissingValues<double>(columnIndex, considerSelection);
     610        return doubleValues.Any() ? Convert<T>(doubleValues.Quantile(alpha)) : emptyValue;
     611      }
     612      var values = GetValuesWithoutMissingValues<T>(columnIndex, considerSelection);
     613      return values.Any() ? values.Quantile(alpha) : emptyValue;
     614    }
     615
     616    public int GetDistinctValues<T>(int columnIndex, bool considerSelection = false) {
     617      var values = GetValuesWithoutMissingValues<T>(columnIndex, considerSelection);
     618      return values.GroupBy(x => x).Count();
     619    }
     620
     621    private IEnumerable<T> GetValuesWithoutMissingValues<T>(int columnIndex, bool considerSelection) {
     622      return GetValues<T>(columnIndex, considerSelection).Where(x => !IsMissingValue(x));
     623    }
     624
     625    private static DateTime AggregateAsDouble(IEnumerable<DateTime> values, Func<IEnumerable<double>, double> func) {
     626      return new DateTime((long)(func(values.Select(x => (double)x.Ticks / TimeSpan.TicksPerSecond)) * TimeSpan.TicksPerSecond));
     627    }
     628    private static T Convert<T>(object obj) { return (T)obj; }
     629
     630    public int GetMissingValueCount() {
     631      int count = 0;
     632      for (int i = 0; i < Columns; ++i) {
     633        count += GetMissingValueCount(i);
     634      }
     635      return count;
     636    }
     637    public int GetMissingValueCount(int columnIndex) {
     638      int sum = 0;
     639      for (int i = 0; i < Rows; i++) {
     640        if (IsCellEmpty(columnIndex, i))
     641          sum++;
     642      }
     643      return sum;
     644    }
     645    public int GetRowMissingValueCount(int rowIndex) {
     646      int sum = 0;
     647      for (int i = 0; i < Columns; i++) {
     648        if (IsCellEmpty(i, rowIndex))
     649          sum++;
     650      }
     651      return sum;
     652    }
     653    #endregion
     654
     655    #region Helpers
     656    private static IList<IList> CopyVariableValues(IList<IList> original) {
     657      var copy = new List<IList>(original);
     658      for (int i = 0; i < original.Count; ++i) {
     659        copy[i] = (IList)Activator.CreateInstance(original[i].GetType(), original[i]);
     660      }
     661      return copy;
     662    }
     663    #endregion
     664  }
     665
     666  // Adapted from HeuristicLab.Common.EnumerableStatisticExtensions
     667  internal static class EnumerableExtensions {
     668    public static T Quantile<T>(this IEnumerable<T> values, double alpha) where T : IComparable<T> {
     669      T[] valuesArr = values.ToArray();
     670      int n = valuesArr.Length;
     671      if (n == 0) throw new InvalidOperationException("Enumeration contains no elements.");
     672
     673      var pos = n * alpha;
     674
     675      return Select((int)Math.Ceiling(pos) - 1, valuesArr);
     676
     677    }
     678
     679    private static T Select<T>(int k, T[] arr) where T : IComparable<T> {
     680      int i, ir, j, l, mid, n = arr.Length;
     681      T a;
     682      l = 0;
     683      ir = n - 1;
     684      for (;;) {
     685        if (ir <= l + 1) {
     686          // Active partition contains 1 or 2 elements.
     687          if (ir == l + 1 && arr[ir].CompareTo(arr[l]) < 0) {
     688            // Case of 2 elements.
     689            Swap(arr, l, ir);
     690          }
     691          return arr[k];
     692        } else {
     693          mid = (l + ir) >> 1; // Choose median of left, center, and right elements
     694          Swap(arr, mid, l + 1); // as partitioning element a. Also
     695
     696          if (arr[l].CompareTo(arr[ir]) > 0) {  // rearrange so that arr[l] arr[ir] <= arr[l+1],
     697            Swap(arr, l, ir); // . arr[ir] >= arr[l+1]
     698          }
     699
     700          if (arr[l + 1].CompareTo(arr[ir]) > 0) {
     701            Swap(arr, l + 1, ir);
     702          }
     703          if (arr[l].CompareTo(arr[l + 1]) > 0) {
     704            Swap(arr, l, l + 1);
     705          }
     706          i = l + 1; // Initialize pointers for partitioning.
     707          j = ir;
     708          a = arr[l + 1]; // Partitioning element.
     709          for (;;) { // Beginning of innermost loop.
     710            do i++; while (arr[i].CompareTo(a) < 0); // Scan up to find element > a.
     711            do j--; while (arr[j].CompareTo(a) > 0); // Scan down to find element < a.
     712            if (j < i) break; // Pointers crossed. Partitioning complete.
     713            Swap(arr, i, j);
     714          } // End of innermost loop.
     715          arr[l + 1] = arr[j]; // Insert partitioning element.
     716          arr[j] = a;
     717          if (j >= k) ir = j - 1; // Keep active the partition that contains the
     718          if (j <= k) l = i; // kth element.
     719        }
     720      }
     721    }
     722
     723    private static void Swap<T>(T[] arr, int i, int j) {
     724      T temp = arr[i];
     725      arr[i] = arr[j];
     726      arr[j] = temp;
     727    }
    215728  }
    216729}
  • trunk/sources/HeuristicLab.DataPreprocessing/3.4/HeuristicLab.DataPreprocessing-3.4.csproj

    r15110 r15518  
    7979  <ItemGroup>
    8080    <Compile Include="Content\MultiScatterPlotContent.cs" />
     81    <Compile Include="Content\PreprocessingContent.cs" />
    8182    <Compile Include="Content\SingleScatterPlotContent.cs" />
    8283    <Compile Include="Content\ScatterPlotContent.cs" />
     
    9091    <Compile Include="PreprocessingTransformator.cs" />
    9192    <Compile Include="Data\DataPreprocessingChangedEvent.cs" />
    92     <Compile Include="Logic\Filter\ComparisonFilter.cs" />
    93     <Compile Include="Logic\Filter\IFilter.cs" />
    94     <Compile Include="Logic\ManipulationLogic.cs" />
     93    <Compile Include="Filter\ComparisonFilter.cs" />
     94    <Compile Include="Filter\IFilter.cs" />
    9595    <Compile Include="Data\IPreprocessingData.cs" />
    9696    <Compile Include="Content\FilterContent.cs" />
    97     <Compile Include="Logic\FilterLogic.cs" />
    9897    <Compile Include="Content\HistogramContent.cs" />
    9998    <Compile Include="Content\LineChartContent.cs" />
     
    105104    <Compile Include="Content\DataGridContent.cs" />
    106105    <Compile Include="PreprocessingContext.cs" />
    107     <Compile Include="Data\TransactionalPreprocessingData.cs" />
    108     <Compile Include="Logic\SearchLogic.cs" />
    109     <Compile Include="Logic\StatisticsLogic.cs" />
    110     <Compile Include="Data\ITransactionalPreprocessingData.cs" />
    111106    <Compile Include="Plugin.cs" />
    112107    <Compile Include="Properties\AssemblyInfo.cs" />
  • trunk/sources/HeuristicLab.DataPreprocessing/3.4/PreprocessingContext.cs

    r15110 r15518  
    7171      if (namedSource != null)
    7272        Name = "Preprocessing " + namedSource.Name;
    73       Data = new FilteredPreprocessingData(new TransactionalPreprocessingData(problemData));
     73      Data = new FilteredPreprocessingData(new PreprocessingData(problemData));
    7474      OnReset();
    7575      // Reset GUI:
  • trunk/sources/HeuristicLab.DataPreprocessing/3.4/PreprocessingTransformator.cs

    r14843 r15518  
    2929namespace HeuristicLab.DataPreprocessing {
    3030  public class PreprocessingTransformator {
    31     private readonly ITransactionalPreprocessingData preprocessingData;
     31    private readonly IPreprocessingData preprocessingData;
    3232
    3333    private readonly IDictionary<string, IList<double>> originalColumns;
     
    3636
    3737    public PreprocessingTransformator(IPreprocessingData preprocessingData) {
    38       this.preprocessingData = (ITransactionalPreprocessingData)preprocessingData;
     38      this.preprocessingData = preprocessingData;
    3939      originalColumns = new Dictionary<string, IList<double>>();
    4040      renamedColumns = new Dictionary<string, string>();
     
    6868          preprocessingData.Undo();
    6969        }
    70       }
    71       catch (Exception e) {
     70      } catch (Exception e) {
    7271        preprocessingData.Undo();
    7372        if (string.IsNullOrEmpty(errorMsg)) errorMsg = e.Message;
    74       }
    75       finally {
     73      } finally {
    7674        preprocessingData.EndTransaction();
    7775      }
Note: See TracChangeset for help on using the changeset viewer.