Changeset 10948
- Timestamp:
- 06/04/14 14:57:53 (10 years ago)
- Location:
- branches/DataPreprocessing
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.4/TransformationView.Designer.cs
r10902 r10948 49 49 this.transformationListView = new HeuristicLab.DataPreprocessing.Views.CheckedTransformationListView(); 50 50 this.applyButton = new System.Windows.Forms.Button(); 51 this.preserveColumnsCheckbox = new System.Windows.Forms.CheckBox(); 51 52 this.SuspendLayout(); 52 53 // 53 54 // transformationListView 54 55 // 55 this.transformationListView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 56 | System.Windows.Forms.AnchorStyles.Left) 56 this.transformationListView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 57 | System.Windows.Forms.AnchorStyles.Left) 57 58 | System.Windows.Forms.AnchorStyles.Right))); 58 59 this.transformationListView.Caption = "Transformations"; … … 75 76 this.applyButton.Click += new System.EventHandler(this.applyButton_Click); 76 77 // 78 // preserveColumnsCheckbox 79 // 80 this.preserveColumnsCheckbox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); 81 this.preserveColumnsCheckbox.AutoSize = true; 82 this.preserveColumnsCheckbox.Location = new System.Drawing.Point(337, 492); 83 this.preserveColumnsCheckbox.Name = "preserveColumnsCheckbox"; 84 this.preserveColumnsCheckbox.Size = new System.Drawing.Size(147, 17); 85 this.preserveColumnsCheckbox.TabIndex = 2; 86 this.preserveColumnsCheckbox.Text = "Preserve original Columns"; 87 this.preserveColumnsCheckbox.UseVisualStyleBackColor = true; 88 // 77 89 // TransformationView 78 90 // 79 91 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 80 92 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 93 this.Controls.Add(this.preserveColumnsCheckbox); 81 94 this.Controls.Add(this.applyButton); 82 95 this.Controls.Add(this.transformationListView); … … 84 97 this.Size = new System.Drawing.Size(627, 514); 85 98 this.ResumeLayout(false); 99 this.PerformLayout(); 86 100 87 101 } … … 90 104 private CheckedTransformationListView transformationListView; 91 105 private System.Windows.Forms.Button applyButton; 106 private System.Windows.Forms.CheckBox preserveColumnsCheckbox; 92 107 } 93 108 } -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.4/TransformationView.cs
r10945 r10948 60 60 61 61 var transformator = new PreprocessingTransformator(Content.Data); 62 bool preserve = preserveColumnsCheckbox.CheckState == CheckState.Checked; 62 63 string errorMsg; 63 bool success = transformator.ApplyTransformations(transformations, out errorMsg);64 bool success = transformator.ApplyTransformations(transformations, preserve, out errorMsg); 64 65 if (success) { 65 66 Content.CheckedTransformationList.Clear(); -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/PreprocessingTransformator.cs
r10819 r10948 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.Text; 26 using HeuristicLab.Data; 25 27 using HeuristicLab.Problems.DataAnalysis.Transformations; 26 28 … … 29 31 private readonly ITransactionalPreprocessingData preprocessingData; 30 32 33 private readonly IDictionary<string, IList<double>> originalColumns; 34 31 35 public PreprocessingTransformator(IPreprocessingData preprocessingData) { 32 36 this.preprocessingData = (ITransactionalPreprocessingData)preprocessingData; 37 originalColumns = new Dictionary<string, IList<double>>(); 33 38 } 34 39 35 public bool ApplyTransformations(IEnumerable<ITransformation> transformations, out string errorMsg) {40 public bool ApplyTransformations(IEnumerable<ITransformation> transformations, bool preserveColumns, out string errorMsg) { 36 41 bool success; 37 42 … … 39 44 try { 40 45 var doubleTransformations = transformations.OfType<Transformation<double>>().ToList(); 41 ApplyDoubleTranformations(doubleTransformations, out success, out errorMsg); 46 ApplyDoubleTranformations(doubleTransformations, preserveColumns, out success, out errorMsg); 47 48 if (preserveColumns) { 49 RestorePreservedColumns(doubleTransformations); 50 originalColumns.Clear(); 51 } 42 52 } finally { 43 53 preprocessingData.EndTransaction(); 44 //if (!success)45 //preprocessingData.Undo();46 54 } 47 55 … … 49 57 } 50 58 51 private void ApplyDoubleTranformations(I Enumerable<Transformation<double>> transformations, out bool success, out string errorMsg) {59 private void ApplyDoubleTranformations(IList<Transformation<double>> transformations, bool preserveColumns, out bool success, out string errorMsg) { 52 60 errorMsg = string.Empty; 53 61 success = true; … … 56 64 57 65 var originalData = preprocessingData.GetValues<double>(colIndex); 66 67 if (preserveColumns && !originalColumns.ContainsKey(transformation.Column)) 68 originalColumns.Add(transformation.Column, originalData); 69 58 70 string errorMsgPart; 59 71 bool successPart; 60 72 var transformedData = ApplyDoubleTransformation(transformation, originalData, out successPart, out errorMsgPart); 61 73 errorMsg += errorMsgPart + Environment.NewLine; 62 //if (!success) return; 74 63 75 if (!successPart) success = false; 64 76 preprocessingData.SetValues(colIndex, transformedData.ToList()); 65 77 preprocessingData.Transformations.Add(transformation); 66 78 } 67 68 79 } 69 80 70 private IEnumerable<double> ApplyDoubleTransformation(Transformation<double> transformation, I Enumerable<double> data, out bool success, out string errorMsg) {81 private IEnumerable<double> ApplyDoubleTransformation(Transformation<double> transformation, IList<double> data, out bool success, out string errorMsg) { 71 82 success = transformation.Check(data, out errorMsg); 72 83 return transformation.Apply(data); 73 84 } 85 86 private void RestorePreservedColumns(IList<Transformation<double>> transformations) { 87 foreach (var column in originalColumns) { 88 int originalColumnIndex = preprocessingData.GetColumnIndex(column.Key); 89 int newColumnIndex = originalColumnIndex + 1; 90 string newColumnName = GetTransformatedColumnName(transformations, column.Key); 91 92 // create new transformed column 93 preprocessingData.InsertColumn<double>(newColumnName, newColumnIndex); 94 preprocessingData.SetValues(newColumnIndex, preprocessingData.GetValues<double>(originalColumnIndex)); 95 // restore old values 96 preprocessingData.SetValues(originalColumnIndex, column.Value); 97 } 98 } 99 100 private string GetTransformatedColumnName(IList<Transformation<double>> transformations, string column) { 101 string suffix = GetTransformationSuffix(transformations, column); 102 return column + "_" + suffix; 103 } 104 105 private string GetTransformationSuffix(IList<Transformation<double>> transformations, string column) { 106 var suffixes = transformations.Where(t => t.Column == column).Select(t => t.ShortName); 107 var builder = new StringBuilder(); 108 foreach (var suffix in suffixes) { 109 builder.Append(suffix); 110 } 111 return builder.ToString(); 112 } 74 113 } 75 114 }
Note: See TracChangeset
for help on using the changeset viewer.