Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10978 for branches


Ignore:
Timestamp:
06/11/14 12:36:39 (10 years ago)
Author:
mleitner
Message:

Refactoring

Location:
branches/DataPreprocessing
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • branches/DataPreprocessing/HeuristicLab 3.3.sln

    r10925 r10978  
    11
    22Microsoft Visual Studio Solution File, Format Version 12.00
    3 # Visual Studio 2013
    4 VisualStudioVersion = 12.0.30501.0
    5 MinimumVisualStudioVersion = 10.0.40219.1
     3# Visual Studio 2012
    64Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{96396439-A764-4022-A8D2-BE021449B8D1}"
    75  ProjectSection(SolutionItems) = preProject
     
    19261924    HideSolutionNode = FALSE
    19271925  EndGlobalSection
     1926  GlobalSection(Performance) = preSolution
     1927    HasPerformanceSessions = true
     1928  EndGlobalSection
    19281929EndGlobal
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.4/PreprocessingFeatureCorrelationView.Designer.cs

    r10908 r10978  
    4747    /// </summary>
    4848    private void InitializeComponent() {
    49       this.components = new System.ComponentModel.Container();
    50       System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AbstractFeatureCorrelationView));
    51       this.progressBar = new System.Windows.Forms.ProgressBar();
    52       this.partitionComboBox = new System.Windows.Forms.ComboBox();
    53       this.correlationCalcLabel = new System.Windows.Forms.Label();
    54       this.correlationCalcComboBox = new System.Windows.Forms.ComboBox();
    55       this.partitionLabel = new System.Windows.Forms.Label();
    56       this.minimumLabel = new System.Windows.Forms.Label();
    57       this.maximumLabel = new System.Windows.Forms.Label();
    58       this.pictureBox = new System.Windows.Forms.PictureBox();
    59       this.splitContainer = new System.Windows.Forms.SplitContainer();
    60       this.progressPanel = new System.Windows.Forms.Panel();
    61       this.progressLabel = new System.Windows.Forms.Label();
    62       this.dataView = new HeuristicLab.Data.Views.EnhancedStringConvertibleMatrixView();
    63       ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
    64       ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit();
    65       this.splitContainer.Panel1.SuspendLayout();
    66       this.splitContainer.Panel2.SuspendLayout();
    67       this.splitContainer.SuspendLayout();
    68       this.progressPanel.SuspendLayout();
    69       this.SuspendLayout();
    70       //
    71       // HeatMapProgressBar
    72       //
    73       this.progressBar.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
    74       this.progressBar.Location = new System.Drawing.Point(25, 46);
    75       this.progressBar.Name = "HeatMapProgressBar";
    76       this.progressBar.RightToLeft = System.Windows.Forms.RightToLeft.No;
    77       this.progressBar.Size = new System.Drawing.Size(154, 21);
    78       this.progressBar.TabIndex = 9;
    79       //
    80       // PartitionComboBox
    81       //
    82       this.partitionComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
    83       this.partitionComboBox.FormattingEnabled = true;
    84       this.partitionComboBox.Location = new System.Drawing.Point(333, 3);
    85       this.partitionComboBox.Name = "PartitionComboBox";
    86       this.partitionComboBox.Size = new System.Drawing.Size(142, 21);
    87       this.partitionComboBox.TabIndex = 8;
    88       this.partitionComboBox.SelectionChangeCommitted += new System.EventHandler(this.PartitionComboBox_SelectedChangeCommitted);
    89       //
    90       // CorrelationCalcLabel
    91       //
    92       this.correlationCalcLabel.AutoSize = true;
    93       this.correlationCalcLabel.Location = new System.Drawing.Point(0, 6);
    94       this.correlationCalcLabel.Name = "CorrelationCalcLabel";
    95       this.correlationCalcLabel.Size = new System.Drawing.Size(104, 13);
    96       this.correlationCalcLabel.TabIndex = 7;
    97       this.correlationCalcLabel.Text = "Correlation Measure:";
    98       //
    99       // CorrelationCalcComboBox
    100       //
    101       this.correlationCalcComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
    102       this.correlationCalcComboBox.FormattingEnabled = true;
    103       this.correlationCalcComboBox.Location = new System.Drawing.Point(110, 3);
    104       this.correlationCalcComboBox.Name = "CorrelationCalcComboBox";
    105       this.correlationCalcComboBox.Size = new System.Drawing.Size(163, 21);
    106       this.correlationCalcComboBox.TabIndex = 6;
    107       this.correlationCalcComboBox.SelectionChangeCommitted += new System.EventHandler(this.CorrelationMeasureComboBox_SelectedChangeCommitted);
    108       //
    109       // PartitionLabel
    110       //
    111       this.partitionLabel.AutoSize = true;
    112       this.partitionLabel.Location = new System.Drawing.Point(279, 6);
    113       this.partitionLabel.Name = "PartitionLabel";
    114       this.partitionLabel.Size = new System.Drawing.Size(48, 13);
    115       this.partitionLabel.TabIndex = 10;
    116       this.partitionLabel.Text = "Partition:";
    117       //
    118       // minimumLabel
    119       //
    120       this.minimumLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
    121       this.minimumLabel.BackColor = System.Drawing.Color.Transparent;
    122       this.minimumLabel.Location = new System.Drawing.Point(487, 314);
    123       this.minimumLabel.Name = "minimumLabel";
    124       this.minimumLabel.Size = new System.Drawing.Size(73, 19);
    125       this.minimumLabel.TabIndex = 13;
    126       this.minimumLabel.Text = "0.0";
    127       this.minimumLabel.TextAlign = System.Drawing.ContentAlignment.TopCenter;
    128       //
    129       // maximumLabel
    130       //
    131       this.maximumLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
    132       this.maximumLabel.BackColor = System.Drawing.Color.Transparent;
    133       this.maximumLabel.Location = new System.Drawing.Point(487, 2);
    134       this.maximumLabel.Name = "maximumLabel";
    135       this.maximumLabel.Size = new System.Drawing.Size(73, 25);
    136       this.maximumLabel.TabIndex = 12;
    137       this.maximumLabel.Text = "1.0";
    138       this.maximumLabel.TextAlign = System.Drawing.ContentAlignment.BottomCenter;
    139       //
    140       // PictureBox
    141       //
    142       this.pictureBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    143             | System.Windows.Forms.AnchorStyles.Right)));
    144       this.pictureBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
    145       this.pictureBox.Image = ((System.Drawing.Image)(resources.GetObject("PictureBox.Image")));
    146       this.pictureBox.Location = new System.Drawing.Point(507, 30);
    147       this.pictureBox.Name = "PictureBox";
    148       this.pictureBox.Size = new System.Drawing.Size(35, 281);
    149       this.pictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
    150       this.pictureBox.TabIndex = 15;
    151       this.pictureBox.TabStop = false;
    152       //
    153       // SplitContainer
    154       //
    155       this.splitContainer.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    156             | System.Windows.Forms.AnchorStyles.Left)
    157             | System.Windows.Forms.AnchorStyles.Right)));
    158       this.splitContainer.FixedPanel = System.Windows.Forms.FixedPanel.Panel1;
    159       this.splitContainer.IsSplitterFixed = true;
    160       this.splitContainer.Location = new System.Drawing.Point(3, 3);
    161       this.splitContainer.Name = "SplitContainer";
    162       this.splitContainer.Orientation = System.Windows.Forms.Orientation.Horizontal;
    163       //
    164       // SplitContainer.Panel1
    165       //
    166       this.splitContainer.Panel1.Controls.Add(this.correlationCalcLabel);
    167       this.splitContainer.Panel1.Controls.Add(this.correlationCalcComboBox);
    168       this.splitContainer.Panel1.Controls.Add(this.partitionComboBox);
    169       this.splitContainer.Panel1.Controls.Add(this.partitionLabel);
    170       //
    171       // SplitContainer.Panel2
    172       //
    173       this.splitContainer.Panel2.Controls.Add(this.progressPanel);
    174       this.splitContainer.Panel2.Controls.Add(this.dataView);
    175       this.splitContainer.Size = new System.Drawing.Size(475, 330);
    176       this.splitContainer.SplitterDistance = 25;
    177       this.splitContainer.TabIndex = 16;
    178       //
    179       // CalculatingPanel
    180       //
    181       this.progressPanel.Anchor = System.Windows.Forms.AnchorStyles.None;
    182       this.progressPanel.Controls.Add(this.progressLabel);
    183       this.progressPanel.Controls.Add(this.progressBar);
    184       this.progressPanel.Location = new System.Drawing.Point(138, 95);
    185       this.progressPanel.Name = "CalculatingPanel";
    186       this.progressPanel.Size = new System.Drawing.Size(200, 81);
    187       this.progressPanel.TabIndex = 10;
    188       //
    189       // CalculatingLabel
    190       //
    191       this.progressLabel.AutoSize = true;
    192       this.progressLabel.Location = new System.Drawing.Point(42, 19);
    193       this.progressLabel.Name = "CalculatingLabel";
    194       this.progressLabel.Size = new System.Drawing.Size(120, 13);
    195       this.progressLabel.TabIndex = 10;
    196       this.progressLabel.Text = "Calculating correlation...";
    197       //
    198       // DataGridView
    199       //
    200       this.dataView.Dock = System.Windows.Forms.DockStyle.Fill;
    201       this.dataView.Location = new System.Drawing.Point(0, 0);
    202       this.dataView.Name = "DataView";
    203       this.dataView.ReadOnly = true;
    204       this.dataView.Size = new System.Drawing.Size(475, 301);
    205       this.dataView.TabIndex = 0;
    206       //
    207       // AbstractFeatureCorrelationView
    208       //
    209       this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    210       this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    211       this.Controls.Add(this.splitContainer);
    212       this.Controls.Add(this.minimumLabel);
    213       this.Controls.Add(this.pictureBox);
    214       this.Controls.Add(this.maximumLabel);
    215       this.Name = "AbstractFeatureCorrelationView";
    216       this.Size = new System.Drawing.Size(569, 336);
    217       ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
    218       this.splitContainer.Panel1.ResumeLayout(false);
    219       this.splitContainer.Panel1.PerformLayout();
    220       this.splitContainer.Panel2.ResumeLayout(false);
    221       ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).EndInit();
    222       this.splitContainer.ResumeLayout(false);
    223       this.progressPanel.ResumeLayout(false);
    224       this.progressPanel.PerformLayout();
     49      this.components = new System.ComponentModel.Container();     
    22550      this.ResumeLayout(false);
    226 
    22751    }
    22852
    22953    #endregion
    230 
    231     protected System.Windows.Forms.ProgressBar progressBar;
    232     protected System.Windows.Forms.ComboBox partitionComboBox;
    233     protected System.Windows.Forms.Label correlationCalcLabel;
    234     protected System.Windows.Forms.ComboBox correlationCalcComboBox;
    235     protected System.Windows.Forms.Label partitionLabel;
    236     protected System.Windows.Forms.Label minimumLabel;
    237     protected System.Windows.Forms.Label maximumLabel;
    238     protected System.Windows.Forms.PictureBox pictureBox;
    239     protected System.Windows.Forms.SplitContainer splitContainer;
    240     protected System.Windows.Forms.Panel progressPanel;
    241     protected System.Windows.Forms.Label progressLabel;
    242     protected HeuristicLab.Data.Views.EnhancedStringConvertibleMatrixView dataView;
    243 
    24454  }
    24555}
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.4/PreprocessingFeatureCorrelationView.cs

    r10934 r10978  
    3030using System;
    3131using HeuristicLab.DataPreprocessing;
     32using HeuristicLab.Problems.DataAnalysis.Views;
    3233
    3334namespace HeuristicLab.Problems.DataAnalysis.Views {
     
    3536  [Content(typeof(CorrelationMatrixContent), false)]
    3637  public partial class PreprocessingFeatureCorrelationView : AsynchronousContentView {
    37     public const string ALLSAMPLES = "All Samples";
    38     public const string TRAININGSAMPLES = "Training Samples";
    39     public const string TESTSAMPLES = "Test Samples";
    40 
    41     public static readonly IList<string> Partitions = new List<string>() { ALLSAMPLES, TRAININGSAMPLES, TESTSAMPLES };
    42 
    43     protected FeatureCorrelationCalculator fcc;
    4438
    4539    public new CorrelationMatrixContent Content
     
    4943    }
    5044
    51     private FeatureCorrelationCache correlationCache;
     45    FeatureCorrelationView correlationView;
    5246
    5347    public PreprocessingFeatureCorrelationView() {
    54 
    55       correlationCache = new FeatureCorrelationCache();
    5648      InitializeComponent();
    57       fcc = new FeatureCorrelationCalculator();
    58       var calculators = ApplicationManager.Manager.GetInstances<IDependencyCalculator>();
    59       var calcList = calculators.OrderBy(c => c.Name).Select(c => new { Name = c.Name, Calculator = c }).ToList();
    60       correlationCalcComboBox.ValueMember = "Calculator";
    61       correlationCalcComboBox.DisplayMember = "Name";
    62       correlationCalcComboBox.DataSource = calcList;
    63       correlationCalcComboBox.SelectedItem = calcList.First(c => c.Calculator.GetType().Equals(typeof(PearsonsRDependenceCalculator)));
    64       partitionComboBox.DataSource = Partitions;
    65       partitionComboBox.SelectedItem = TRAININGSAMPLES;
     49      correlationView = new FeatureCorrelationView();
     50      correlationView.Dock = DockStyle.Fill;
     51      this.Controls.Add(correlationView);
    6652    }
    6753
     
    6955    protected override void RegisterContentEvents() {
    7056      base.RegisterContentEvents();
    71       Content.PreprocessingData.Changed += Data_Changed;
    72       fcc.ProgressCalculation += new FeatureCorrelationCalculator.ProgressCalculationHandler(Content_ProgressCalculation);
    73       fcc.CorrelationCalculationFinished += new FeatureCorrelationCalculator.CorrelationCalculationFinishedHandler(Content_CorrelationCalculationFinished);
     57      Content.Changed += Data_Changed;     
    7458    }
    7559
    7660    protected override void DeregisterContentEvents() {
    77       Content.PreprocessingData.Changed -= Data_Changed;
    78       fcc.CorrelationCalculationFinished -= new FeatureCorrelationCalculator.CorrelationCalculationFinishedHandler(Content_CorrelationCalculationFinished);
    79       fcc.ProgressCalculation -= new FeatureCorrelationCalculator.ProgressCalculationHandler(Content_ProgressCalculation);
     61      Content.Changed -= Data_Changed;     
    8062      base.DeregisterContentEvents();
    8163    }
     
    8769    protected override void OnContentChanged() {
    8870      base.OnContentChanged();
    89       fcc.TryCancelCalculation();
    90       if (Content != null) {
    91         fcc.ProblemData = Content.ProblemData;
    92         CalculateCorrelation();
    93       } else {
    94         dataView.Maximum = 0;
    95         dataView.Minimum = 0;
    96         dataView.Content = null;
    97         dataView.ResetVisibility();
    98       }
    99     }
    100 
    101     protected virtual bool[] SetInitialVariableVisibility() {
    102       bool[] initialVisibility = new bool[Content.ProblemData.Dataset.DoubleVariables.Count()];
    103       int i = 0;
    104       foreach (var variable in Content.ProblemData.Dataset.DoubleVariables) {
    105         initialVisibility[i] = Content.ProblemData.AllowedInputVariables.Contains(variable);
    106         i++;
    107       }
    108       return initialVisibility;
    109     }
    110 
    111     protected void CorrelationMeasureComboBox_SelectedChangeCommitted(object sender, System.EventArgs e) {
    112       CalculateCorrelation();
    113     }
    114     protected void PartitionComboBox_SelectedChangeCommitted(object sender, System.EventArgs e) {
    115       CalculateCorrelation();
    116     }
    117 
    118      protected void CalculateCorrelation() {
    119       if (correlationCalcComboBox.SelectedItem == null) return;
    120       if (partitionComboBox.SelectedItem == null) return;
    121 
    122       IDependencyCalculator calc = (IDependencyCalculator)correlationCalcComboBox.SelectedValue;
    123       string partition = (string)partitionComboBox.SelectedValue;
    124       dataView.Enabled = false;
    125       double[,] corr = correlationCache.GetCorrelation(calc, partition);
    126       if (corr == null) {
    127         fcc.CalculateElements(calc, partition);
    128       } else {
    129         fcc.TryCancelCalculation();
    130         var correlation = new DoubleMatrix(corr, Content.ProblemData.Dataset.DoubleVariables, Content.ProblemData.Dataset.DoubleVariables);
    131         UpdateDataView(correlation);
    132       }
    133     }
    134 
    135     protected void Content_CorrelationCalculationFinished(object sender, FeatureCorrelationCalculator.CorrelationCalculationFinishedArgs e) {
    136       if (InvokeRequired) {
    137         Invoke(new FeatureCorrelationCalculator.CorrelationCalculationFinishedHandler(Content_CorrelationCalculationFinished), sender, e);
     71      if (Content == null) {
     72        correlationView.Content = null;
    13873        return;
    13974      }
    140       correlationCache.SetCorrelation(e.Calculcator, e.Partition, e.Correlation);
    141       var correlation = new DoubleMatrix(e.Correlation, Content.ProblemData.Dataset.DoubleVariables, Content.ProblemData.Dataset.DoubleVariables);
    142       UpdateDataView(correlation);
     75
     76      correlationView.Content = Content.ProblemData;
    14377    }
    144 
    145     protected void UpdateDataView(DoubleMatrix correlation) {
    146       IDependencyCalculator calc = (IDependencyCalculator)correlationCalcComboBox.SelectedValue;
    147       maximumLabel.Text = calc.Maximum.ToString();
    148       minimumLabel.Text = calc.Minimum.ToString();
    149 
    150       correlation.SortableView = true;
    151       dataView.Maximum = calc.Maximum;
    152       dataView.Minimum = calc.Minimum;
    153       dataView.Content = correlation;
    154       dataView.Enabled = true;
    155     }
    156 
    157     protected void Content_ProgressCalculation(object sender, ProgressChangedEventArgs e) {
    158       if (!progressPanel.Visible && e.ProgressPercentage != progressBar.Maximum) {
    159         progressPanel.Show();
    160       } else if (e.ProgressPercentage == progressBar.Maximum) {
    161         progressPanel.Hide();
    162       }
    163       progressBar.Value = e.ProgressPercentage;
    164     }
    165 
    166       [NonDiscoverableType]
    167       private class FeatureCorrelationCache : Object {
    168         private Dictionary<Tuple<IDependencyCalculator, string>, double[,]> correlationsCache;
    169 
    170         public FeatureCorrelationCache()
    171           : base() {
    172           InitializeCaches();
    173         }
    174 
    175         private void InitializeCaches() {
    176           correlationsCache = new Dictionary<Tuple<IDependencyCalculator, string>, double[,]>();
    177         }
    178 
    179         public void Reset() {
    180           InitializeCaches();
    181         }
    182 
    183         public double[,] GetCorrelation(IDependencyCalculator calc, string partition) {
    184           double[,] corr;
    185           var key = new Tuple<IDependencyCalculator, string>(calc, partition);
    186           correlationsCache.TryGetValue(key, out corr);
    187           return corr;
    188         }
    189 
    190         public void SetCorrelation(IDependencyCalculator calc, string partition, double[,] correlation) {
    191           var key = new Tuple<IDependencyCalculator, string>(calc, partition);
    192           correlationsCache[key] = correlation;
    193         }
    194       }
    19578  }
    19679}
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations/ChartLogic.cs

    r10973 r10978  
    140140    public DataRow CreateSelectedDataRow(string variableName, DataRowVisualProperties.DataRowChartType chartType) {
    141141     
    142       IDictionary<int,IList<int>> selection = preprocessingData.GetSelection();
     142      IDictionary<int,IList<int>> selection = preprocessingData.Selection;
    143143      int variableIndex = preprocessingData.GetColumnIndex(variableName);
    144144
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations/CorrelationMatrixContent.cs

    r10962 r10978  
    2626
    2727namespace HeuristicLab.DataPreprocessing {
    28 
    2928  [Item("Feature Correlation Matrix", "Represents the feature correlation matrix.")]
    3029  public class CorrelationMatrixContent : Item, IViewChartShortcut {
     30    public static new Image StaticItemImage {
     31      get { return HeuristicLab.Common.Resources.VSImageLibrary.Gradient; }
     32    }
     33
     34    private IPreprocessingContext Context { get; set; }
     35    private ITransactionalPreprocessingData PreprocessingData {
     36      get { return Context.Data; }
     37    }
    3138
    3239    public DataAnalysisProblemData ProblemData {
     
    3441        var creator = new ProblemDataCreator(Context);
    3542        return (DataAnalysisProblemData)creator.CreateProblemData();
    36       } 
     43      }
    3744    }
    3845
    39     public ITransactionalPreprocessingData PreprocessingData {
    40       get {
    41         return Context.Data;
    42       }
    43     }
    44 
    45     private IPreprocessingContext Context { get; set; }
    4646    public CorrelationMatrixContent(IPreprocessingContext context) {
    4747      Context = context;
    48 
    49 
    5048    }
    5149
    5250    public CorrelationMatrixContent(CorrelationMatrixContent original, Cloner cloner)
    5351      : base(original, cloner) {
    54 
    5552    }
    56 
    57     public static new Image StaticItemImage {
    58       get { return HeuristicLab.Common.Resources.VSImageLibrary.Gradient; }
    59     }
    60 
    6153    public override IDeepCloneable Clone(Cloner cloner) {
    6254      return new CorrelationMatrixContent(this, cloner);
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations/DataGridLogic.cs

    r10900 r10978  
    144144
    145145
    146 
    147146    public void SetSelection(IDictionary<int, IList<int>> selection) {
    148       preprocessingData.SetSelection(selection);
     147      preprocessingData.Selection = selection;
    149148    }
    150149
    151150    public IDictionary<int, IList<int>> GetSelection() {
    152       return preprocessingData.GetSelection();
     151      return preprocessingData.Selection;
    153152    }
    154153    public void ClearSelection() {
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations/FilteredPreprocessingData.cs

    r10939 r10978  
    1010namespace HeuristicLab.DataPreprocessing.Implementations {
    1111  public class FilteredPreprocessingData : NamedItem, IFilteredPreprocessingData {
    12     protected ITransactionalPreprocessingData originalData;
    13     protected ITransactionalPreprocessingData filteredData;
     12    private readonly ITransactionalPreprocessingData originalData;
     13    private ITransactionalPreprocessingData filteredData;
     14
     15     public IDictionary<int, IList<int>> Selection {
     16      get { return originalData.Selection; }
     17      set { originalData.Selection = value; }
     18    }
    1419
    1520    protected FilteredPreprocessingData(FilteredPreprocessingData original, Cloner cloner)
    1621      : base(original, cloner) {
    17       originalData = (ITransactionalPreprocessingData)original.originalData;
    18       filteredData = (ITransactionalPreprocessingData)original.filteredData;
     22      originalData = original.originalData;
     23      filteredData = original.filteredData;
    1924    }
    2025
     
    3439
    3540    public void SetCell<T>(int columnIndex, int rowIndex, T value) {
    36       ReadOnlyOnFilterData.SetCell<T>(columnIndex, rowIndex, value);
     41      if (IsFiltered)
     42        throw new InvalidOperationException("SetCell not possible while data is filtered");
     43
     44      originalData.SetCell<T>(columnIndex, rowIndex, value);
    3745    }
    3846
     
    5058
    5159    public void SetValues<T>(int columnIndex, IList<T> values) {
    52       ReadOnlyOnFilterData.SetValues<T>(columnIndex, values);
     60      if (IsFiltered)
     61        throw new InvalidOperationException("SetValues not possible while data is filtered");
     62
     63      originalData.SetValues<T>(columnIndex, values);
    5364    }
    5465
    5566    public void InsertRow(int rowIndex) {
    56       ReadOnlyOnFilterData.InsertRow(rowIndex);
     67      if (IsFiltered)
     68        throw new InvalidOperationException("InsertRow not possible while data is filtered");
     69
     70      originalData.InsertRow(rowIndex);
    5771    }
    5872
    5973    public void DeleteRow(int rowIndex) {
    60       ReadOnlyOnFilterData.DeleteRow(rowIndex);
     74      if (IsFiltered)
     75        throw new InvalidOperationException("DeleteRow not possible while data is filtered");
     76
     77      originalData.DeleteRow(rowIndex);
    6178    }
    6279
    6380    public void InsertColumn<T>(string variableName, int columnIndex) {
    64       ReadOnlyOnFilterData.InsertColumn<T>(variableName, columnIndex);
     81      if (IsFiltered)
     82        throw new InvalidOperationException("InsertColumn not possible while data is filtered");
     83
     84      originalData.InsertColumn<T>(variableName, columnIndex);
    6585    }
    6686
    6787    public void DeleteColumn(int columnIndex) {
    68       ReadOnlyOnFilterData.DeleteColumn(columnIndex);
     88      if (IsFiltered)
     89        throw new InvalidOperationException("DeleteColumn not possible while data is filtered");
     90      originalData.DeleteColumn(columnIndex);
    6991    }
    7092
     
    153175    }
    154176
    155     public ITransactionalPreprocessingData ReadOnlyOnFilterData {
    156       get {
    157         if (IsFiltered)
    158           throw new InvalidOperationException();
    159 
    160         return originalData;
    161       }
    162     }
     177
     178    public bool IsUndoAvailable {
     179      get { return IsFiltered ? false : originalData.IsUndoAvailable; }
     180    }
     181
    163182
    164183    public bool IsFiltered {
     
    171190    }
    172191
    173     public bool IsUndoAvailable {
    174       get { return IsFiltered ? false : originalData.IsUndoAvailable; }
    175     }
    176192
    177193    public void Undo() {
    178       ReadOnlyOnFilterData.Undo();
     194      if (IsFiltered)
     195        throw new InvalidOperationException("Undo not possible while data is filtered");
     196
     197      originalData.Undo();
    179198    }
    180199
    181200    public void InTransaction(Action action, DataPreprocessingChangedEventType type = DataPreprocessingChangedEventType.Any) {
    182       ReadOnlyOnFilterData.InTransaction(action, type);
     201      if (IsFiltered)
     202        throw new InvalidOperationException("Transaction not possible while data is filtered");
     203      originalData.InTransaction(action, type);
    183204    }
    184205
    185206    public void BeginTransaction(DataPreprocessingChangedEventType type) {
    186       ReadOnlyOnFilterData.BeginTransaction(type);
     207      if (IsFiltered)
     208        throw new InvalidOperationException("Transaction not possible while data is filtered");
     209      originalData.BeginTransaction(type);
    187210    }
    188211
     
    194217
    195218    #region IPreprocessingData Members
    196 
    197 
    198     public void SetSelection(IDictionary<int, IList<int>> selection) {
    199       originalData.SetSelection(selection);
    200     }
    201 
    202     public IDictionary<int, IList<int>> GetSelection() {
    203       return originalData.GetSelection();
    204     }
    205219
    206220    public void ClearSelection() {
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations/PreprocessingContext.cs

    r10786 r10978  
    3434
    3535    public IFilteredPreprocessingData Data { get; private set; }
    36 
    37     public IDataAnalysisProblemData DataAnalysisProblemData { get; private set; }
    38 
    3936    public IAlgorithm Algorithm { get; private set; }
    40 
    4137    public IDataAnalysisProblem Problem { get; private set; }
    4238
    4339    public PreprocessingContext(IDataAnalysisProblemData dataAnalysisProblemData, IAlgorithm algorithm, IDataAnalysisProblem problem) {
    44 
    4540      TransactionalPreprocessingData transactionalPreprocessingData = new TransactionalPreprocessingData(dataAnalysisProblemData);
    4641
    4742      Data = new FilteredPreprocessingData(transactionalPreprocessingData);
    48       DataAnalysisProblemData = dataAnalysisProblemData;
    4943      Algorithm = algorithm;
    5044      Problem = problem;
     
    5448      : base(original, cloner) {
    5549      Data = cloner.Clone(original.Data);
    56       DataAnalysisProblemData = original.DataAnalysisProblemData;
    5750      Algorithm = original.Algorithm;
    5851      Problem = original.Problem;
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations/PreprocessingData.cs

    r10842 r10978  
    3333
    3434  [Item("PreprocessingData", "Represents data used for preprocessing.")]
    35   public class PreprocessingData : NamedItem, IPreprocessingData {
     35  public abstract class PreprocessingData : NamedItem, IPreprocessingData {
     36
     37    protected double trainingToTestRatio;
     38    public IntRange TrainingPartition {
     39      get { return new IntRange(0, (int)(Rows * trainingToTestRatio)); }
     40    }
     41    public IntRange TestPartition {
     42      get { return new IntRange((int)(Rows * trainingToTestRatio), Rows); }
     43    }
     44
     45    protected IList<ITransformation> transformations;
     46    public IList<ITransformation> Transformations {
     47      get { return transformations; }
     48    }
    3649
    3750    protected IList<IList> variableValues;
    38 
    3951    protected IList<string> variableNames;
    4052
    41     protected double trainingToTestRatio;
    42 
    43     protected IList<ITransformation> transformations;
    44 
    45     protected IDictionary<int, IList<int>> currentSelection;
     53    public IEnumerable<string> VariableNames {
     54      get { return variableNames; }
     55    }
     56
     57    public int Columns {
     58      get { return variableNames.Count; }
     59    }
     60
     61    public int Rows {
     62      get { return variableValues.Count > 0 ? variableValues[0].Count : 0; }
     63    }
     64
     65    protected IDictionary<int, IList<int>> selection;
     66    public IDictionary<int, IList<int>> Selection {
     67      get { return selection; }
     68      set {
     69          selection = value;
     70          OnSelectionChanged();
     71        }
     72      }   
    4673
    4774    protected PreprocessingData(PreprocessingData original, Cloner cloner)
     
    5380    }
    5481
    55     public PreprocessingData(IDataAnalysisProblemData problemData)
     82    protected PreprocessingData(IDataAnalysisProblemData problemData)
    5683      : base() {
    5784      Name = "Preprocessing Data";
    5885
    5986      transformations = new List<ITransformation>();
    60       currentSelection = new Dictionary<int, IList<int>>();
     87      selection = new Dictionary<int, IList<int>>();
    6188
    6289      variableNames = new List<string>(problemData.Dataset.VariableNames);
    63       // create dictionary from variable name to index
    6490
    6591      int columnIndex = 0;
     
    7399          variableValues.Insert(columnIndex, CreateColumn<DateTime>(problemData.Dataset, columnIndex, x => DateTime.Parse(x)));
    74100        } else {
    75           throw new ArgumentException("The datatype of column " + variableName + " must be of type List<double>, List<string> or List<DateTime>");
     101          throw new ArgumentException("The datatype of column " + variableName + " must be of type double, string or DateTime");
    76102        }
    77103        ++columnIndex;
     
    97123    }
    98124
    99     #region NamedItem abstract Member Implementations
    100 
    101     public override IDeepCloneable Clone(Cloner cloner) {
    102       return new PreprocessingData(this, cloner);
    103     }
    104 
    105     #endregion
    106125
    107126    #region IPreprocessingData Members
     
    111130    }
    112131
    113 
    114132    public virtual void SetCell<T>(int columnIndex, int rowIndex, T value) {
    115133      variableValues[columnIndex][rowIndex] = value;
    116134    }
    117135
    118 
    119136    public string GetCellAsString(int columnIndex, int rowIndex) {
    120137      return variableValues[columnIndex][rowIndex].ToString();
    121138    }
    122139
     140    public string GetVariableName(int columnIndex) {
     141      return variableNames[columnIndex];
     142    }
     143
     144    public int GetColumnIndex(string variableName) {
     145      return variableNames.IndexOf(variableName);
     146    }
     147
     148    public bool IsType<T>(int columnIndex) {
     149      return variableValues[columnIndex] is List<T>;
     150    }
    123151
    124152    [Obsolete("use the index based variant, is faster")]
     
    130158      if (considerSelection) {
    131159        var list = new List<T>();
    132         foreach (var rowIdx in currentSelection[columnIndex]) {
     160        foreach (var rowIdx in selection[columnIndex]) {
    133161          list.Add((T)variableValues[columnIndex][rowIdx]);
    134162        }
     
    170198    }
    171199
    172     public IntRange TrainingPartition {
    173       get { return new IntRange(0, (int)(Rows * trainingToTestRatio)); }
    174     }
    175 
    176     public IntRange TestPartition {
    177       get { return new IntRange((int)(Rows * trainingToTestRatio), Rows); }
    178     }
    179 
    180     public IList<ITransformation> Transformations {
    181       get { return transformations; }
    182     }
    183 
    184     public string GetVariableName(int columnIndex) {
    185       return variableNames[columnIndex];
    186     }
    187 
    188     public IEnumerable<string> VariableNames {
    189       get { return variableNames; }
    190     }
    191 
    192     public int GetColumnIndex(string variableName) {
    193       return variableNames.IndexOf(variableName);
    194     }
    195 
    196     public bool IsType<T>(int columnIndex) {
    197       return variableValues[columnIndex] is List<T>;
    198     }
    199 
    200     public int Columns {
    201       get { return variableNames.Count; }
    202     }
    203 
    204     public int Rows {
    205       get { return variableValues.Count > 0 ? variableValues[0].Count : 0; }
    206     }
    207 
    208200    public Dataset ExportToDataset() {
    209201      IList<IList> values = new List<IList>();
     
    217209    }
    218210
    219     public void SetSelection(IDictionary<int, IList<int>> selection) {
    220       currentSelection = selection;
    221       if (SelectionChanged != null) {
    222         SelectionChanged(this, new EventArgs());
    223       }
    224     }
    225 
    226     public IDictionary<int, IList<int>> GetSelection() {
    227       return currentSelection;
    228     }
    229 
    230211    public void ClearSelection() {
    231       currentSelection = new Dictionary<int, IList<int>>();
     212      Selection = new Dictionary<int, IList<int>>();
    232213    }
    233214
    234215    public event EventHandler SelectionChanged;
    235 
     216    protected virtual void OnSelectionChanged() {
     217       var listeners = SelectionChanged;
     218       if (listeners != null) listeners(this, EventArgs.Empty);
     219    }
     220
     221    public event DataPreprocessingChangedEventHandler Changed;
     222    protected virtual void OnChanged(DataPreprocessingChangedEventType type, int column, int row) {
     223      var listeners = Changed;
     224      if (listeners != null) listeners(this, new DataPreprocessingChangedEventArgs(type, column, row));
     225    }
    236226    #endregion
    237227  }
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations/SearchLogic.cs

    r10817 r10978  
    114114    {
    115115      if (considerSelection) {     
    116         var selectedRows =  preprocessingData.GetSelection()[columnIndex];
     116        var selectedRows =  preprocessingData.Selection[columnIndex];
    117117       
    118118        List<T> values = new List<T>();
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations/TransactionalPreprocessingData.cs

    r10814 r10978  
    3030namespace HeuristicLab.DataPreprocessing {
    3131
    32   internal class Snapshot {
    33     public IList<IList> VariableValues { get; set; }
    34 
    35     public IList<string> VariableNames { get; set; }
    36 
    37     public double TrainingToTestRatio { get; set; }
    38 
    39     public IList<ITransformation> Transformations { get; set; }
    40 
    41     public DataPreprocessingChangedEventType ChangedType { get; set; }
    42 
    43     public int ChangedColumn { get; set; }
    44 
    45     public int ChangedRow { get; set; }
    46   }
    47 
    4832  [Item("PreprocessingData", "Represents data used for preprocessing.")]
    4933  public class TransactionalPreprocessingData : PreprocessingData, ITransactionalPreprocessingData {
    5034
     35    private class Snapshot {
     36      public IList<IList> VariableValues { get; set; }
     37      public IList<string> VariableNames { get; set; }
     38
     39      public double TrainingToTestRatio { get; set; }
     40      public IList<ITransformation> Transformations { get; set; }
     41      public DataPreprocessingChangedEventType ChangedType { get; set; }
     42
     43      public int ChangedColumn { get; set; }
     44      public int ChangedRow { get; set; }
     45    }
     46
    5147    private const int MAX_UNDO_DEPTH = 5;
    5248
    53     private IList<Snapshot> undoHistory;
    54 
    55     private Stack<DataPreprocessingChangedEventType> eventStack = new Stack<DataPreprocessingChangedEventType>();
    56 
    57     private DataPreprocessingChangedEventType lastOccuredChangedType = DataPreprocessingChangedEventType.Any;
     49    private readonly IList<Snapshot> undoHistory = new List<Snapshot>();
     50    private readonly Stack<DataPreprocessingChangedEventType> eventStack = new Stack<DataPreprocessingChangedEventType>();
    5851
    5952    public bool IsInTransaction { get { return eventStack.Count > 0; } }
     
    6154    public TransactionalPreprocessingData(IDataAnalysisProblemData problemData)
    6255      : base(problemData) {
    63       undoHistory = new List<Snapshot>();
    6456    }
    6557
    6658    private TransactionalPreprocessingData(TransactionalPreprocessingData original, Cloner cloner)
    6759      : base(original, cloner) {
    68       undoHistory = new List<Snapshot>();
    69     }
     60     }
    7061
    7162    private void SaveSnapshot(DataPreprocessingChangedEventType changedType, int column, int row) {
    72       if (eventStack.Count > 0) return;
     63      if (IsInTransaction) return;
    7364
    7465      var currentSnapshot = new Snapshot {
     
    144135    #region TransactionalPreprocessingData members
    145136
    146     public event DataPreprocessingChangedEventHandler Changed;
    147     protected virtual void OnChanged(DataPreprocessingChangedEventType type, int column, int row) {
    148       var listeners = Changed;
    149       if (listeners != null) listeners(this, new DataPreprocessingChangedEventArgs(type, column, row));
    150     }
    151 
    152137    public bool IsUndoAvailable {
    153138      get { return undoHistory.Count > 0; }
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Interfaces/IPreprocessingContext.cs

    r10783 r10978  
    2727
    2828namespace HeuristicLab.DataPreprocessing {
    29   public interface IPreprocessingContext
    30     : IItem {
     29  public interface IPreprocessingContext : IItem {
    3130
    3231    IFilteredPreprocessingData Data { get; }
    33 
    34     [Obsolete]
    35     IDataAnalysisProblemData DataAnalysisProblemData { get; }
    36 
    3732    IAlgorithm Algorithm { get; }
    38 
    3933    IDataAnalysisProblem Problem { get; }
    4034
    4135    IItem ExportAlgorithmOrProblem();
    42 
    4336    IAlgorithm ExportAlgorithm();
    44 
    4537    IProblem ExportProblem();
    4638  }
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Interfaces/IPreprocessingData.cs

    r10811 r10978  
    6565    Dataset ExportToDataset();
    6666
    67     void SetSelection(IDictionary<int, IList<int>> selection);
    68     IDictionary<int, IList<int>> GetSelection();
     67    IDictionary<int, IList<int>> Selection { get; set; }
    6968    void ClearSelection();
    7069
Note: See TracChangeset for help on using the changeset viewer.