Changeset 10978
- Timestamp:
- 06/11/14 12:36:39 (10 years ago)
- Location:
- branches/DataPreprocessing
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataPreprocessing/HeuristicLab 3.3.sln
r10925 r10978 1 1 2 2 Microsoft 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 6 4 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{96396439-A764-4022-A8D2-BE021449B8D1}" 7 5 ProjectSection(SolutionItems) = preProject … … 1926 1924 HideSolutionNode = FALSE 1927 1925 EndGlobalSection 1926 GlobalSection(Performance) = preSolution 1927 HasPerformanceSessions = true 1928 EndGlobalSection 1928 1929 EndGlobal -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.4/PreprocessingFeatureCorrelationView.Designer.cs
r10908 r10978 47 47 /// </summary> 48 48 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(); 225 50 this.ResumeLayout(false); 226 227 51 } 228 52 229 53 #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 244 54 } 245 55 } -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.4/PreprocessingFeatureCorrelationView.cs
r10934 r10978 30 30 using System; 31 31 using HeuristicLab.DataPreprocessing; 32 using HeuristicLab.Problems.DataAnalysis.Views; 32 33 33 34 namespace HeuristicLab.Problems.DataAnalysis.Views { … … 35 36 [Content(typeof(CorrelationMatrixContent), false)] 36 37 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;44 38 45 39 public new CorrelationMatrixContent Content … … 49 43 } 50 44 51 private FeatureCorrelationCache correlationCache;45 FeatureCorrelationView correlationView; 52 46 53 47 public PreprocessingFeatureCorrelationView() { 54 55 correlationCache = new FeatureCorrelationCache();56 48 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); 66 52 } 67 53 … … 69 55 protected override void RegisterContentEvents() { 70 56 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; 74 58 } 75 59 76 60 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; 80 62 base.DeregisterContentEvents(); 81 63 } … … 87 69 protected override void OnContentChanged() { 88 70 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; 138 73 return; 139 74 } 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; 143 77 } 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 }195 78 } 196 79 } -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations/ChartLogic.cs
r10973 r10978 140 140 public DataRow CreateSelectedDataRow(string variableName, DataRowVisualProperties.DataRowChartType chartType) { 141 141 142 IDictionary<int,IList<int>> selection = preprocessingData. GetSelection();142 IDictionary<int,IList<int>> selection = preprocessingData.Selection; 143 143 int variableIndex = preprocessingData.GetColumnIndex(variableName); 144 144 -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations/CorrelationMatrixContent.cs
r10962 r10978 26 26 27 27 namespace HeuristicLab.DataPreprocessing { 28 29 28 [Item("Feature Correlation Matrix", "Represents the feature correlation matrix.")] 30 29 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 } 31 38 32 39 public DataAnalysisProblemData ProblemData { … … 34 41 var creator = new ProblemDataCreator(Context); 35 42 return (DataAnalysisProblemData)creator.CreateProblemData(); 36 } 43 } 37 44 } 38 45 39 public ITransactionalPreprocessingData PreprocessingData {40 get {41 return Context.Data;42 }43 }44 45 private IPreprocessingContext Context { get; set; }46 46 public CorrelationMatrixContent(IPreprocessingContext context) { 47 47 Context = context; 48 49 50 48 } 51 49 52 50 public CorrelationMatrixContent(CorrelationMatrixContent original, Cloner cloner) 53 51 : base(original, cloner) { 54 55 52 } 56 57 public static new Image StaticItemImage {58 get { return HeuristicLab.Common.Resources.VSImageLibrary.Gradient; }59 }60 61 53 public override IDeepCloneable Clone(Cloner cloner) { 62 54 return new CorrelationMatrixContent(this, cloner); -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations/DataGridLogic.cs
r10900 r10978 144 144 145 145 146 147 146 public void SetSelection(IDictionary<int, IList<int>> selection) { 148 preprocessingData.Se tSelection(selection);147 preprocessingData.Selection = selection; 149 148 } 150 149 151 150 public IDictionary<int, IList<int>> GetSelection() { 152 return preprocessingData. GetSelection();151 return preprocessingData.Selection; 153 152 } 154 153 public void ClearSelection() { -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations/FilteredPreprocessingData.cs
r10939 r10978 10 10 namespace HeuristicLab.DataPreprocessing.Implementations { 11 11 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 } 14 19 15 20 protected FilteredPreprocessingData(FilteredPreprocessingData original, Cloner cloner) 16 21 : base(original, cloner) { 17 originalData = (ITransactionalPreprocessingData)original.originalData;18 filteredData = (ITransactionalPreprocessingData)original.filteredData;22 originalData = original.originalData; 23 filteredData = original.filteredData; 19 24 } 20 25 … … 34 39 35 40 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); 37 45 } 38 46 … … 50 58 51 59 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); 53 64 } 54 65 55 66 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); 57 71 } 58 72 59 73 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); 61 78 } 62 79 63 80 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); 65 85 } 66 86 67 87 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); 69 91 } 70 92 … … 153 175 } 154 176 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 163 182 164 183 public bool IsFiltered { … … 171 190 } 172 191 173 public bool IsUndoAvailable {174 get { return IsFiltered ? false : originalData.IsUndoAvailable; }175 }176 192 177 193 public void Undo() { 178 ReadOnlyOnFilterData.Undo(); 194 if (IsFiltered) 195 throw new InvalidOperationException("Undo not possible while data is filtered"); 196 197 originalData.Undo(); 179 198 } 180 199 181 200 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); 183 204 } 184 205 185 206 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); 187 210 } 188 211 … … 194 217 195 218 #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 }205 219 206 220 public void ClearSelection() { -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations/PreprocessingContext.cs
r10786 r10978 34 34 35 35 public IFilteredPreprocessingData Data { get; private set; } 36 37 public IDataAnalysisProblemData DataAnalysisProblemData { get; private set; }38 39 36 public IAlgorithm Algorithm { get; private set; } 40 41 37 public IDataAnalysisProblem Problem { get; private set; } 42 38 43 39 public PreprocessingContext(IDataAnalysisProblemData dataAnalysisProblemData, IAlgorithm algorithm, IDataAnalysisProblem problem) { 44 45 40 TransactionalPreprocessingData transactionalPreprocessingData = new TransactionalPreprocessingData(dataAnalysisProblemData); 46 41 47 42 Data = new FilteredPreprocessingData(transactionalPreprocessingData); 48 DataAnalysisProblemData = dataAnalysisProblemData;49 43 Algorithm = algorithm; 50 44 Problem = problem; … … 54 48 : base(original, cloner) { 55 49 Data = cloner.Clone(original.Data); 56 DataAnalysisProblemData = original.DataAnalysisProblemData;57 50 Algorithm = original.Algorithm; 58 51 Problem = original.Problem; -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations/PreprocessingData.cs
r10842 r10978 33 33 34 34 [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 } 36 49 37 50 protected IList<IList> variableValues; 38 39 51 protected IList<string> variableNames; 40 52 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 } 46 73 47 74 protected PreprocessingData(PreprocessingData original, Cloner cloner) … … 53 80 } 54 81 55 p ublicPreprocessingData(IDataAnalysisProblemData problemData)82 protected PreprocessingData(IDataAnalysisProblemData problemData) 56 83 : base() { 57 84 Name = "Preprocessing Data"; 58 85 59 86 transformations = new List<ITransformation>(); 60 currentSelection = new Dictionary<int, IList<int>>();87 selection = new Dictionary<int, IList<int>>(); 61 88 62 89 variableNames = new List<string>(problemData.Dataset.VariableNames); 63 // create dictionary from variable name to index64 90 65 91 int columnIndex = 0; … … 73 99 variableValues.Insert(columnIndex, CreateColumn<DateTime>(problemData.Dataset, columnIndex, x => DateTime.Parse(x))); 74 100 } 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"); 76 102 } 77 103 ++columnIndex; … … 97 123 } 98 124 99 #region NamedItem abstract Member Implementations100 101 public override IDeepCloneable Clone(Cloner cloner) {102 return new PreprocessingData(this, cloner);103 }104 105 #endregion106 125 107 126 #region IPreprocessingData Members … … 111 130 } 112 131 113 114 132 public virtual void SetCell<T>(int columnIndex, int rowIndex, T value) { 115 133 variableValues[columnIndex][rowIndex] = value; 116 134 } 117 135 118 119 136 public string GetCellAsString(int columnIndex, int rowIndex) { 120 137 return variableValues[columnIndex][rowIndex].ToString(); 121 138 } 122 139 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 } 123 151 124 152 [Obsolete("use the index based variant, is faster")] … … 130 158 if (considerSelection) { 131 159 var list = new List<T>(); 132 foreach (var rowIdx in currentSelection[columnIndex]) {160 foreach (var rowIdx in selection[columnIndex]) { 133 161 list.Add((T)variableValues[columnIndex][rowIdx]); 134 162 } … … 170 198 } 171 199 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 208 200 public Dataset ExportToDataset() { 209 201 IList<IList> values = new List<IList>(); … … 217 209 } 218 210 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 230 211 public void ClearSelection() { 231 currentSelection = new Dictionary<int, IList<int>>();212 Selection = new Dictionary<int, IList<int>>(); 232 213 } 233 214 234 215 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 } 236 226 #endregion 237 227 } -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations/SearchLogic.cs
r10817 r10978 114 114 { 115 115 if (considerSelection) { 116 var selectedRows = preprocessingData. GetSelection()[columnIndex];116 var selectedRows = preprocessingData.Selection[columnIndex]; 117 117 118 118 List<T> values = new List<T>(); -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations/TransactionalPreprocessingData.cs
r10814 r10978 30 30 namespace HeuristicLab.DataPreprocessing { 31 31 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 48 32 [Item("PreprocessingData", "Represents data used for preprocessing.")] 49 33 public class TransactionalPreprocessingData : PreprocessingData, ITransactionalPreprocessingData { 50 34 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 51 47 private const int MAX_UNDO_DEPTH = 5; 52 48 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>(); 58 51 59 52 public bool IsInTransaction { get { return eventStack.Count > 0; } } … … 61 54 public TransactionalPreprocessingData(IDataAnalysisProblemData problemData) 62 55 : base(problemData) { 63 undoHistory = new List<Snapshot>();64 56 } 65 57 66 58 private TransactionalPreprocessingData(TransactionalPreprocessingData original, Cloner cloner) 67 59 : base(original, cloner) { 68 undoHistory = new List<Snapshot>(); 69 } 60 } 70 61 71 62 private void SaveSnapshot(DataPreprocessingChangedEventType changedType, int column, int row) { 72 if ( eventStack.Count > 0) return;63 if (IsInTransaction) return; 73 64 74 65 var currentSnapshot = new Snapshot { … … 144 135 #region TransactionalPreprocessingData members 145 136 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 152 137 public bool IsUndoAvailable { 153 138 get { return undoHistory.Count > 0; } -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Interfaces/IPreprocessingContext.cs
r10783 r10978 27 27 28 28 namespace HeuristicLab.DataPreprocessing { 29 public interface IPreprocessingContext 30 : IItem { 29 public interface IPreprocessingContext : IItem { 31 30 32 31 IFilteredPreprocessingData Data { get; } 33 34 [Obsolete]35 IDataAnalysisProblemData DataAnalysisProblemData { get; }36 37 32 IAlgorithm Algorithm { get; } 38 39 33 IDataAnalysisProblem Problem { get; } 40 34 41 35 IItem ExportAlgorithmOrProblem(); 42 43 36 IAlgorithm ExportAlgorithm(); 44 45 37 IProblem ExportProblem(); 46 38 } -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Interfaces/IPreprocessingData.cs
r10811 r10978 65 65 Dataset ExportToDataset(); 66 66 67 void SetSelection(IDictionary<int, IList<int>> selection); 68 IDictionary<int, IList<int>> GetSelection(); 67 IDictionary<int, IList<int>> Selection { get; set; } 69 68 void ClearSelection(); 70 69
Note: See TracChangeset
for help on using the changeset viewer.