- Timestamp:
- 03/28/18 17:17:31 (7 years ago)
- Location:
- branches/2906_Transformations
- Files:
-
- 8 added
- 4 deleted
- 11 edited
- 4 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/2906_Transformations/HeuristicLab.DataPreprocessing/3.4/ProblemDataCreator.cs
r15865 r15870 85 85 private IDataAnalysisProblemData CreateRegressionData(RegressionProblemData oldProblemData) { 86 86 // TODO: transformations (additional inputs, target changed) 87 var targetVariable = Regression ProblemData.GetTransformedTragetVariable(oldProblemData.TargetVariable, CreateDataAnalysisTransformation());87 var targetVariable = RegressionTransformationModel.GetTransformedTragetVariable(oldProblemData.TargetVariable, CreateDataAnalysisTransformation()); 88 88 if (!context.Data.VariableNames.Contains(targetVariable)) 89 89 targetVariable = context.Data.VariableNames.First(); -
branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis.Views/3.4/DataAnalysisTransformationModelView.Designer.cs
r15869 r15870 21 21 22 22 namespace HeuristicLab.Problems.DataAnalysis.Views { 23 partial class TransformedRegressionModelView {23 partial class DataAnalysisTransformationModelView { 24 24 /// <summary> 25 25 /// Required designer variable. … … 45 45 /// </summary> 46 46 private void InitializeComponent() { 47 this.originalModelTabPage = new System.Windows.Forms.TabPage(); 48 this.modelViewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost(); 47 49 this.tabControl = new System.Windows.Forms.TabControl(); 48 this.tabPageModel = new System.Windows.Forms.TabPage(); 49 this.tabPageTransformations = new System.Windows.Forms.TabPage(); 50 this.modelViewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost(); 51 this.transformationsViewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost(); 50 this.inputTransformationsTabPage = new System.Windows.Forms.TabPage(); 51 this.inputTransformationsViewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost(); 52 this.targetTransformationsTabPage = new System.Windows.Forms.TabPage(); 53 this.targetTransformationsViewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost(); 54 this.originalModelTabPage.SuspendLayout(); 52 55 this.tabControl.SuspendLayout(); 53 this. tabPageModel.SuspendLayout();54 this.ta bPageTransformations.SuspendLayout();56 this.inputTransformationsTabPage.SuspendLayout(); 57 this.targetTransformationsTabPage.SuspendLayout(); 55 58 this.SuspendLayout(); 59 // 60 // originalModelTabPage 61 // 62 this.originalModelTabPage.Controls.Add(this.modelViewHost); 63 this.originalModelTabPage.Location = new System.Drawing.Point(4, 22); 64 this.originalModelTabPage.Name = "originalModelTabPage"; 65 this.originalModelTabPage.Padding = new System.Windows.Forms.Padding(3); 66 this.originalModelTabPage.Size = new System.Drawing.Size(486, 392); 67 this.originalModelTabPage.TabIndex = 0; 68 this.originalModelTabPage.Text = "Original Model"; 69 this.originalModelTabPage.UseVisualStyleBackColor = true; 70 // 71 // modelViewHost 72 // 73 this.modelViewHost.Caption = "View"; 74 this.modelViewHost.Content = null; 75 this.modelViewHost.Dock = System.Windows.Forms.DockStyle.Fill; 76 this.modelViewHost.Enabled = false; 77 this.modelViewHost.Location = new System.Drawing.Point(3, 3); 78 this.modelViewHost.Name = "modelViewHost"; 79 this.modelViewHost.ReadOnly = false; 80 this.modelViewHost.Size = new System.Drawing.Size(480, 386); 81 this.modelViewHost.TabIndex = 0; 82 this.modelViewHost.ViewsLabelVisible = true; 83 this.modelViewHost.ViewType = null; 56 84 // 57 85 // tabControl 58 86 // 59 this.tabControl.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 60 | System.Windows.Forms.AnchorStyles.Left) 87 this.tabControl.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 88 | System.Windows.Forms.AnchorStyles.Left) 61 89 | System.Windows.Forms.AnchorStyles.Right))); 62 this.tabControl.Controls.Add(this.tabPageModel); 63 this.tabControl.Controls.Add(this.tabPageTransformations); 90 this.tabControl.Controls.Add(this.originalModelTabPage); 91 this.tabControl.Controls.Add(this.inputTransformationsTabPage); 92 this.tabControl.Controls.Add(this.targetTransformationsTabPage); 64 93 this.tabControl.Location = new System.Drawing.Point(3, 3); 65 94 this.tabControl.Name = "tabControl"; … … 68 97 this.tabControl.TabIndex = 0; 69 98 // 70 // tabPageModel99 // inputTransformationsTabPage 71 100 // 72 this. tabPageModel.Controls.Add(this.modelViewHost);73 this. tabPageModel.Location = new System.Drawing.Point(4, 22);74 this. tabPageModel.Name = "tabPageModel";75 this. tabPageModel.Padding = new System.Windows.Forms.Padding(3);76 this. tabPageModel.Size = new System.Drawing.Size(486, 392);77 this. tabPageModel.TabIndex = 0;78 this. tabPageModel.Text = "Original Model";79 this. tabPageModel.UseVisualStyleBackColor = true;101 this.inputTransformationsTabPage.Controls.Add(this.inputTransformationsViewHost); 102 this.inputTransformationsTabPage.Location = new System.Drawing.Point(4, 22); 103 this.inputTransformationsTabPage.Name = "inputTransformationsTabPage"; 104 this.inputTransformationsTabPage.Padding = new System.Windows.Forms.Padding(3); 105 this.inputTransformationsTabPage.Size = new System.Drawing.Size(486, 392); 106 this.inputTransformationsTabPage.TabIndex = 1; 107 this.inputTransformationsTabPage.Text = "Input Transformations"; 108 this.inputTransformationsTabPage.UseVisualStyleBackColor = true; 80 109 // 81 // tabPageTransformations110 // inputTransformationsViewHost 82 111 // 83 this.tabPageTransformations.Controls.Add(this.transformationsViewHost); 84 this.tabPageTransformations.Location = new System.Drawing.Point(4, 22); 85 this.tabPageTransformations.Name = "tabPageTransformations"; 86 this.tabPageTransformations.Padding = new System.Windows.Forms.Padding(3); 87 this.tabPageTransformations.Size = new System.Drawing.Size(486, 392); 88 this.tabPageTransformations.TabIndex = 1; 89 this.tabPageTransformations.Text = "Transformations"; 90 this.tabPageTransformations.UseVisualStyleBackColor = true; 112 this.inputTransformationsViewHost.Caption = "View"; 113 this.inputTransformationsViewHost.Content = null; 114 this.inputTransformationsViewHost.Dock = System.Windows.Forms.DockStyle.Fill; 115 this.inputTransformationsViewHost.Enabled = false; 116 this.inputTransformationsViewHost.Location = new System.Drawing.Point(3, 3); 117 this.inputTransformationsViewHost.Name = "inputTransformationsViewHost"; 118 this.inputTransformationsViewHost.ReadOnly = false; 119 this.inputTransformationsViewHost.Size = new System.Drawing.Size(480, 386); 120 this.inputTransformationsViewHost.TabIndex = 1; 121 this.inputTransformationsViewHost.ViewsLabelVisible = false; 122 this.inputTransformationsViewHost.ViewType = null; 91 123 // 92 // modelViewHost124 // targetTransformationsTabPage 93 125 // 94 this.modelViewHost.Dock = System.Windows.Forms.DockStyle.Fill; 95 this.modelViewHost.Location = new System.Drawing.Point(3, 3); 96 this.modelViewHost.Name = "modelViewHost"; 97 this.modelViewHost.Size = new System.Drawing.Size(480, 386); 98 this.modelViewHost.TabIndex = 0; 126 this.targetTransformationsTabPage.Controls.Add(this.targetTransformationsViewHost); 127 this.targetTransformationsTabPage.Location = new System.Drawing.Point(4, 22); 128 this.targetTransformationsTabPage.Name = "targetTransformationsTabPage"; 129 this.targetTransformationsTabPage.Padding = new System.Windows.Forms.Padding(3); 130 this.targetTransformationsTabPage.Size = new System.Drawing.Size(486, 392); 131 this.targetTransformationsTabPage.TabIndex = 2; 132 this.targetTransformationsTabPage.Text = "Target Transformations"; 133 this.targetTransformationsTabPage.UseVisualStyleBackColor = true; 99 134 // 100 // t ransformationsViewHost135 // targetTransformationsViewHost 101 136 // 102 this.transformationsViewHost.Dock = System.Windows.Forms.DockStyle.Fill; 103 this.transformationsViewHost.Location = new System.Drawing.Point(3, 3); 104 this.transformationsViewHost.Name = "transformationsViewHost"; 105 this.transformationsViewHost.Size = new System.Drawing.Size(480, 386); 106 this.transformationsViewHost.TabIndex = 0; 137 this.targetTransformationsViewHost.Caption = "View"; 138 this.targetTransformationsViewHost.Content = null; 139 this.targetTransformationsViewHost.Dock = System.Windows.Forms.DockStyle.Fill; 140 this.targetTransformationsViewHost.Enabled = false; 141 this.targetTransformationsViewHost.Location = new System.Drawing.Point(3, 3); 142 this.targetTransformationsViewHost.Name = "targetTransformationsViewHost"; 143 this.targetTransformationsViewHost.ReadOnly = false; 144 this.targetTransformationsViewHost.Size = new System.Drawing.Size(480, 386); 145 this.targetTransformationsViewHost.TabIndex = 1; 146 this.targetTransformationsViewHost.ViewsLabelVisible = false; 147 this.targetTransformationsViewHost.ViewType = null; 107 148 // 108 // TransformedRegressionModelView149 // DataAnalysisTransformationModelView 109 150 // 110 151 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 111 152 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 112 153 this.Controls.Add(this.tabControl); 113 this.Name = " TransformedRegressionModelView";154 this.Name = "DataAnalysisTransformationModelView"; 114 155 this.Size = new System.Drawing.Size(500, 424); 156 this.originalModelTabPage.ResumeLayout(false); 115 157 this.tabControl.ResumeLayout(false); 116 this. tabPageModel.ResumeLayout(false);117 this.ta bPageTransformations.ResumeLayout(false);158 this.inputTransformationsTabPage.ResumeLayout(false); 159 this.targetTransformationsTabPage.ResumeLayout(false); 118 160 this.ResumeLayout(false); 119 161 … … 122 164 #endregion 123 165 166 private System.Windows.Forms.TabPage originalModelTabPage; 167 private MainForm.WindowsForms.ViewHost modelViewHost; 124 168 private System.Windows.Forms.TabControl tabControl; 125 private System.Windows.Forms.TabPage tabPageModel;126 private System.Windows.Forms.TabPage ta bPageTransformations;127 private HeuristicLab.MainForm.WindowsForms.ViewHost modelViewHost;128 private HeuristicLab.MainForm.WindowsForms.ViewHost transformationsViewHost;169 private System.Windows.Forms.TabPage inputTransformationsTabPage; 170 private System.Windows.Forms.TabPage targetTransformationsTabPage; 171 private MainForm.WindowsForms.ViewHost inputTransformationsViewHost; 172 private MainForm.WindowsForms.ViewHost targetTransformationsViewHost; 129 173 } 130 174 } -
branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis.Views/3.4/DataAnalysisTransformationModelView.cs
r15869 r15870 24 24 25 25 namespace HeuristicLab.Problems.DataAnalysis.Views { 26 [View("Transform ed regression model")]27 [Content(typeof(I TransformedRegressionModel), true)]28 public partial class TransformedRegressionModelView : ItemView {26 [View("Transformation Model View")] 27 [Content(typeof(IDataAnalysisTransformationModel), true)] 28 public partial class DataAnalysisTransformationModelView : ItemView { 29 29 30 public new I TransformedRegressionModel Content {31 get { return (I TransformedRegressionModel)base.Content; }30 public new IDataAnalysisTransformationModel Content { 31 get { return (IDataAnalysisTransformationModel)base.Content; } 32 32 set { base.Content = value; } 33 33 } 34 34 35 public TransformedRegressionModelView() {35 public DataAnalysisTransformationModelView() { 36 36 InitializeComponent(); 37 37 } … … 40 40 base.OnContentChanged(); 41 41 modelViewHost.Content = Content?.OriginalModel; 42 transformationsViewHost.Content = Content?.Transformations; 42 inputTransformationsViewHost.Content = Content?.InputTransformations; 43 targetTransformationsTabPage.Visible = Content is IRegressionTransformationModel; 44 targetTransformationsViewHost.Content = Content?.TargetTransformations; 43 45 } 44 46 45 47 protected override void SetEnabledStateOfControls() { 46 48 base.SetEnabledStateOfControls(); 47 tabControl.Enabled = Content != null ;49 tabControl.Enabled = Content != null && !Locked; 48 50 } 49 51 } -
branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj
r15856 r15870 432 432 <DependentUpon>RegressionSolutionScatterPlotView.cs</DependentUpon> 433 433 </Compile> 434 <Compile Include="Regression\TransformedRegressionModelView.cs"> 435 <SubType>UserControl</SubType> 436 </Compile> 437 <Compile Include="Regression\TransformedRegressionModelView.Designer.cs"> 438 <DependentUpon>TransformedRegressionModelView.cs</DependentUpon> 439 </Compile> 440 <Compile Include="Solution Views\TransformedRegressionSolutionView.cs"> 441 <SubType>UserControl</SubType> 442 </Compile> 443 <Compile Include="Solution Views\TransformedRegressionSolutionView.Designer.cs"> 444 <DependentUpon>TransformedRegressionSolutionView.cs</DependentUpon> 434 <Compile Include="DataAnalysisTransformationModelView.cs"> 435 <SubType>UserControl</SubType> 436 </Compile> 437 <Compile Include="DataAnalysisTransformationModelView.Designer.cs"> 438 <DependentUpon>DataAnalysisTransformationModelView.cs</DependentUpon> 445 439 </Compile> 446 440 <Compile Include="Solution Views\ClassificationSolutionView.cs"> -
branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views/DataAnalysisSolutionView.Designer.cs
r15583 r15870 47 47 this.flowLayoutPanel = new System.Windows.Forms.FlowLayoutPanel(); 48 48 this.loadProblemDataButton = new System.Windows.Forms.Button(); 49 this.transformButton = new System.Windows.Forms.Button(); 49 50 this.loadProblemDataFileDialog = new System.Windows.Forms.OpenFileDialog(); 50 51 ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit(); … … 54 55 this.itemsGroupBox.SuspendLayout(); 55 56 this.detailsGroupBox.SuspendLayout(); 57 this.flowLayoutPanel.SuspendLayout(); 56 58 this.SuspendLayout(); 57 59 // … … 77 79 // 78 80 // flowLayoutPanel 79 // 80 this.flowLayoutPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); 81 this.flowLayoutPanel.FlowDirection = System.Windows.Forms.FlowDirection.LeftToRight; 81 // 82 this.flowLayoutPanel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 83 | System.Windows.Forms.AnchorStyles.Right))); 84 this.flowLayoutPanel.Controls.Add(this.loadProblemDataButton); 85 this.flowLayoutPanel.Controls.Add(this.transformButton); 82 86 this.flowLayoutPanel.Location = new System.Drawing.Point(0, 0); 87 this.flowLayoutPanel.Name = "flowLayoutPanel"; 83 88 this.flowLayoutPanel.Padding = new System.Windows.Forms.Padding(3, 0, 3, 0); 84 89 this.flowLayoutPanel.Size = new System.Drawing.Size(266, 30); 85 this.flowLayoutPanel. Controls.Add(this.loadProblemDataButton);86 // 90 this.flowLayoutPanel.TabIndex = 1; 91 // 87 92 // loadProblemDataButton 88 // 93 // 89 94 this.loadProblemDataButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom))); 90 95 this.loadProblemDataButton.AutoSize = true; … … 98 103 this.loadProblemDataButton.UseVisualStyleBackColor = true; 99 104 this.loadProblemDataButton.Click += new System.EventHandler(this.loadProblemDataButton_Click); 100 this.toolTip.SetToolTip(this.loadProblemDataButton, "Creates a new data analysis solution with the same model and the loaded problem data.");101 105 // 102 // openFileDialog 106 // transformButton 107 // 108 this.transformButton.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; 109 this.transformButton.Location = new System.Drawing.Point(6, 33); 110 this.transformButton.Name = "transformButton"; 111 this.transformButton.Size = new System.Drawing.Size(152, 23); 112 this.transformButton.TabIndex = 7; 113 this.transformButton.Text = "Integrate Transformations"; 114 this.transformButton.TextAlign = System.Drawing.ContentAlignment.MiddleRight; 115 this.transformButton.UseVisualStyleBackColor = true; 116 this.transformButton.Click += new System.EventHandler(this.transformButton_Click); 117 // 118 // loadProblemDataFileDialog 103 119 // 104 120 this.loadProblemDataFileDialog.Filter = "HL files|*.hl"; … … 115 131 this.itemsGroupBox.ResumeLayout(false); 116 132 this.detailsGroupBox.ResumeLayout(false); 133 this.flowLayoutPanel.ResumeLayout(false); 134 this.flowLayoutPanel.PerformLayout(); 117 135 this.ResumeLayout(false); 118 136 … … 124 142 protected System.Windows.Forms.OpenFileDialog loadProblemDataFileDialog; 125 143 protected System.Windows.Forms.FlowLayoutPanel flowLayoutPanel; 126 144 protected System.Windows.Forms.Button transformButton; 127 145 } 128 146 } -
branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views/DataAnalysisSolutionView.cs
r15583 r15870 25 25 using System.Linq; 26 26 using System.Windows.Forms; 27 using HeuristicLab.Common.Resources; 27 28 using HeuristicLab.Core; 28 29 using HeuristicLab.Core.Views; … … 37 38 [Content(typeof(DataAnalysisSolution), false)] 38 39 public partial class DataAnalysisSolutionView : NamedItemCollectionView<IResult> { 40 41 private const string BacktransformButtonText = "Integrate Transformations"; 42 private const string ReapplyTransformationsButtonText = "Restore Original Model"; 43 39 44 public DataAnalysisSolutionView() { 40 45 InitializeComponent(); 41 46 viewHost.ViewsLabelVisible = false; 47 transformButton.Image = VSImageLibrary.Event; 42 48 } 43 49 … … 52 58 removeButton.Enabled = false; 53 59 loadProblemDataButton.Enabled = Content != null && !Locked; 60 transformButton.Enabled = Content != null && !Locked; 61 transformButton.Visible = Content != null && Content.ProblemData.Transformations.Any(); 54 62 } 55 63 … … 81 89 } 82 90 } 91 92 if (Content == null) return; 93 94 transformButton.Text = Content.Model is IDataAnalysisTransformationModel 95 ? ReapplyTransformationsButtonText : BacktransformButtonText; 83 96 } 84 97 … … 147 160 solution.Name += " with loaded problemData"; 148 161 MainFormManager.MainForm.ShowContent(solution); 149 } 150 catch (InvalidOperationException invalidOperationException) { 162 } catch (InvalidOperationException invalidOperationException) { 151 163 ErrorHandling.ShowErrorDialog(this, invalidOperationException); 152 } 153 catch (ArgumentException argumentException) { 164 } catch (ArgumentException argumentException) { 154 165 ErrorHandling.ShowErrorDialog(this, argumentException); 155 166 } … … 238 249 Content.Filename = string.Empty; 239 250 MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().UpdateTitle(); 240 } 241 catch (InvalidOperationException invalidOperationException) { 251 } catch (InvalidOperationException invalidOperationException) { 242 252 ErrorHandling.ShowErrorDialog(this, invalidOperationException); 243 } 244 catch (ArgumentException argumentException) { 253 } catch (ArgumentException argumentException) { 245 254 ErrorHandling.ShowErrorDialog(this, argumentException); 246 255 } … … 248 257 #endregion 249 258 259 private void transformButton_Click(object sender, EventArgs e) { 260 var transformedSolution = CreateTransformedSolution(Content); 261 MainFormManager.MainForm.ShowContent(transformedSolution); 262 } 263 264 private static IDataAnalysisSolution CreateTransformedSolution(IDataAnalysisSolution solution) { 265 if (solution.Model is IRegressionTransformationModel regressionTransformationModel && !(solution.Model is ITimeSeriesPrognosisTransformationModel)) { 266 var originalData = (IRegressionProblemData)((IRegressionSolution)solution).ProblemData.Transform(); 267 return regressionTransformationModel.OriginalModel.CreateRegressionSolution(originalData); 268 } else if (solution.Model is IClassificationTransformationModel classificationTransformationModel) { 269 var originalData = (IClassificationProblemData)((IClassificationSolution)solution).ProblemData.Transform(); 270 return classificationTransformationModel.OriginalModel.CreateClassificationSolution(originalData); 271 } else if (solution.Model is IRegressionModel regressionModel && !(solution.Model is ITimeSeriesPrognosisModel)) { 272 var transformationModel = new RegressionTransformationModel(regressionModel, solution.ProblemData.Transformations); 273 var transformedData = (IRegressionProblemData)((IRegressionSolution)solution).ProblemData.InverseTransform(); 274 return transformationModel.CreateRegressionSolution(transformedData); 275 } else if (solution.Model is IClassificationModel classificationModel) { 276 var transformationModel = new ClassificationTransformationModel(classificationModel, solution.ProblemData.Transformations); 277 var transformedData = (IClassificationProblemData)((IClassificationSolution)solution).ProblemData.InverseTransform(); 278 return transformationModel.CreateClassificationSolution(transformedData); 279 } else throw new NotSupportedException(); 280 } 281 282 /*if (Content.Model is IDataAnalysisTransformationModel transformationModel) { 283 var originalModel = transformationModel.InverseTransform(); 284 originalModel.CreateSolution(); 285 } else { 286 var originalModel = Content.Model; 287 var transformationModel = originalModel.Transform(); 288 transformationModel.CreateSolution(); 289 }*/ 290 291 ////Content.Model.Transform() 292 293 //var transformedModel = new DataAnalysisTransformationModel(Content.Model, Content.ProblemData.Transformations); 294 //var originalProblemData = (IRegressionProblemData)Content.ProblemData.InverseTransform(); 295 //var transformedSolution = new TransformedRegressionSolution(transformedModel, originalProblemData); 296 //MainFormManager.MainForm.ShowContent(transformedSolution); 250 297 } 251 298 } -
branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views/RegressionSolutionView.Designer.cs
r15864 r15870 48 48 private void InitializeComponent() { 49 49 System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(RegressionSolutionView)); 50 this.TransformButton = new System.Windows.Forms.Button();51 50 ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit(); 52 51 this.splitContainer.Panel1.SuspendLayout(); … … 72 71 this.toolTip.SetToolTip(this.removeButton, "Remove"); 73 72 // 74 // TransformButton75 //76 this.TransformButton.AutoSize = true;77 this.TransformButton.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;78 this.TransformButton.Location = new System.Drawing.Point(117, 3);79 this.TransformButton.Name = "TransformButton";80 this.TransformButton.Size = new System.Drawing.Size(108, 23);81 this.TransformButton.TabIndex = 1;82 this.TransformButton.Text = "Transform Back";83 this.TransformButton.TextAlign = System.Drawing.ContentAlignment.MiddleRight;84 this.toolTip.SetToolTip(this.TransformButton, "TODO: Backtransform model based on the stored transformations.");85 this.TransformButton.UseVisualStyleBackColor = true;86 this.TransformButton.Click += new System.EventHandler(this.transformButton_Click);87 //88 73 // RegressionSolutionView 89 74 // … … 101 86 102 87 #endregion 103 104 protected System.Windows.Forms.Button TransformButton;105 88 } 106 89 } -
branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views/RegressionSolutionView.cs
r15864 r15870 20 20 #endregion 21 21 22 using System.Linq;23 22 using System.Windows.Forms; 24 using HeuristicLab.Common.Resources;25 23 using HeuristicLab.Core; 26 24 using HeuristicLab.MainForm; … … 32 30 public RegressionSolutionView() { 33 31 InitializeComponent(); 34 TransformButton.Image = VSImageLibrary.Event;35 flowLayoutPanel.Controls.Add(TransformButton);36 32 } 37 33 … … 43 39 protected override void SetEnabledStateOfControls() { 44 40 base.SetEnabledStateOfControls(); 45 TransformButton.Enabled = Content != null;46 TransformButton.Visible = Content != null && Content.ProblemData.Transformations.Any();47 41 } 48 42 … … 61 55 } 62 56 #endregion 63 64 protected virtual void transformButton_Click(object sender, System.EventArgs e) {65 var transformedModel = new TransformedRegressionModel(Content.Model, Content.ProblemData.Transformations);66 var originalProblemData = (IRegressionProblemData)Content.ProblemData.InverseTransform();67 var transformedSolution = new TransformedRegressionSolution(transformedModel, originalProblemData);68 MainFormManager.MainForm.ShowContent(transformedSolution);69 }70 57 } 71 58 } -
branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj
r15864 r15870 187 187 <Compile Include="Implementation\Classification\ClassificationSolutionBase.cs" /> 188 188 <Compile Include="Implementation\Classification\ClassificationSolutionVariableImpactsCalculator.cs" /> 189 <Compile Include="Implementation\Classification\ClassificationTransformationModel.cs" /> 189 190 <Compile Include="Implementation\Classification\ConstantClassificationSolution.cs" /> 190 191 <Compile Include="Implementation\Classification\DiscriminantFunctionClassificationSolutionBase.cs" /> … … 193 194 <Compile Include="Implementation\Clustering\ClusteringProblemData.cs" /> 194 195 <Compile Include="Implementation\Clustering\ClusteringSolution.cs" /> 196 <Compile Include="Implementation\Clustering\ClusteringTransformationModel.cs" /> 195 197 <Compile Include="Implementation\ConstantModel.cs" /> 196 198 <Compile Include="Implementation\DataAnalysisModel.cs" /> … … 206 208 <Compile Include="Implementation\Regression\RegressionModel.cs" /> 207 209 <Compile Include="Implementation\Regression\RegressionSolutionVariableImpactsCalculator.cs" /> 208 <Compile Include="Implementation\ Regression\TransformedRegressionModel.cs" />209 <Compile Include="Implementation\Regression\ TransformedRegressionSolution.cs" />210 <Compile Include="Implementation\DataAnalysisTransformationModel.cs" /> 211 <Compile Include="Implementation\Regression\RegressionTransformationModel.cs" /> 210 212 <Compile Include="Implementation\TimeSeriesPrognosis\Models\ConstantTimeSeriesPrognosisModel.cs" /> 211 213 <Compile Include="Implementation\TimeSeriesPrognosis\Models\TimeSeriesPrognosisAutoRegressiveModel.cs" /> 214 <Compile Include="Implementation\TimeSeriesPrognosis\Models\TimeSeriesPrognosisTransformationModel.cs" /> 212 215 <Compile Include="Implementation\TimeSeriesPrognosis\TimeSeriesPrognosisProblem.cs" /> 213 216 <Compile Include="Implementation\TimeSeriesPrognosis\TimeSeriesPrognosisProblemData.cs" /> … … 236 239 <SubType>Code</SubType> 237 240 </Compile> 241 <Compile Include="Interfaces\Classification\IClassificationTransformationModel.cs" /> 238 242 <Compile Include="Interfaces\Classification\IDiscriminantFunctionThresholdCalculator.cs" /> 243 <Compile Include="Interfaces\Clustering\IClusteringTransformationModel.cs" /> 239 244 <Compile Include="Interfaces\IDataAnalysisSolutionExporter.cs" /> 240 245 <Compile Include="Interfaces\IDataAnalysisTransformation.cs" /> 246 <Compile Include="Interfaces\IDataAnalysisTransformationModel.cs" /> 241 247 <Compile Include="Interfaces\IDataset.cs" /> 242 248 <Compile Include="Interfaces\IDependencyCalculator.cs" /> 243 249 <Compile Include="Interfaces\ITransformation.cs" /> 244 <Compile Include="Interfaces\Regression\ITransformedRegressionModel.cs" /> 245 <Compile Include="Interfaces\Regression\ITransformedRegressionSolution.cs" /> 250 <Compile Include="Interfaces\Regression\IRegressionTransformationModel.cs" /> 246 251 <Compile Include="Interfaces\Regression\IConfidenceRegressionModel.cs" /> 247 252 <Compile Include="Interfaces\Regression\IConfidenceRegressionSolution.cs" /> … … 256 261 <Compile Include="Interfaces\TimeSeriesPrognosis\ITimeSeriesPrognosisProblemData.cs" /> 257 262 <Compile Include="Interfaces\TimeSeriesPrognosis\ITimeSeriesPrognosisSolution.cs" /> 263 <Compile Include="Interfaces\TimeSeriesPrognosis\ITimeSeriesPrognosisTransformationModel.cs" /> 258 264 <Compile Include="ModifiableDataset.cs" /> 259 265 <Compile Include="OnlineCalculators\AutoCorrelationCalculator.cs" /> -
branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisProblemData.cs
r15858 r15870 243 243 244 244 public virtual IDataAnalysisProblemData Transform() { 245 var newDataset = Transform(Dataset, Transformations);245 var newDataset = DataAnalysisTransformationModel.Transform(Dataset, Transformations); 246 246 247 247 var extendedInputs = ExtendInputVariables(AllowedInputVariables, Transformations); … … 253 253 cloner.RegisterClonedObject(Dataset, newDataset); 254 254 cloner.RegisterClonedObject(InputVariables, checkedInputs.AsReadOnly()); 255 // cloner.RegisterClonedObject(TransformationsParameter.Value, new ItemList<IDataAnalysisTransformation>(transformations).AsReadOnly());255 // TODO: valid values for target are not extended 256 256 257 257 return cloner.Clone(this); … … 268 268 cloner.RegisterClonedObject(Dataset, newDataset); 269 269 cloner.RegisterClonedObject(InputVariables, checkedInputs.AsReadOnly()); 270 // cloner.RegisterClonedObject(TransformationsParameter.Value, new ItemList<IDataAnalysisTransformation>().AsReadOnly());270 // TODO: check valid target values 271 271 272 272 return cloner.Clone(this); 273 }274 275 public static IDataset Transform(IDataset dataset, IEnumerable<IDataAnalysisTransformation> transformations) {276 var modifiableDataset = ((Dataset)dataset).ToModifiable();277 278 foreach (var transformation in transformations) {279 var trans = (ITransformation<double>)transformation.Transformation;280 281 var originalData = modifiableDataset.GetDoubleValues(transformation.OriginalVariable);282 if (!trans.Check(originalData, out string errorMessage))283 throw new InvalidOperationException($"Cannot estimate Values, Transformation is invalid: {errorMessage}");284 285 var transformedData = trans.Apply(originalData).ToList();286 if (modifiableDataset.VariableNames.Contains(transformation.TransformedVariable))287 modifiableDataset.ReplaceVariable(transformation.TransformedVariable, transformedData);288 else289 modifiableDataset.AddVariable(transformation.TransformedVariable, transformedData);290 }291 292 return modifiableDataset;293 273 } 294 274 -
branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisTransformation.cs
r15865 r15870 20 20 #endregion 21 21 22 using System;23 22 using HeuristicLab.Common; 24 23 using HeuristicLab.Core; … … 40 39 } 41 40 42 private IValueParameter<ITransformation> TransformationParameter {43 get { return ( IValueParameter<ITransformation>)Parameters["Transformation"]; }41 private ValueParameter<ITransformation> TransformationParameter { 42 get { return (ValueParameter<ITransformation>)Parameters["Transformation"]; } 44 43 } 45 44 #endregion … … 48 47 public string OriginalVariable { 49 48 get { return OriginalVariableParameter.Value.Value; } 50 set { OriginalVariableParameter.Value.Value = value; }51 49 } 52 50 53 51 public string TransformedVariable { 54 52 get { return TransformedVariableParameter.Value.Value; } 55 set { TransformedVariableParameter.Value.Value = value; }56 53 } 57 54 58 55 public ITransformation Transformation { 59 56 get { return TransformationParameter.Value; } 60 set { TransformationParameter.Value = value; }61 57 } 62 58 #endregion 63 59 64 60 #region Constructor, Cloning & Persistence 65 public DataAnalysisTransformation()66 : this("", "", new IdentityTransformation()) {67 }68 61 public DataAnalysisTransformation(string originalVariable, string transformedVariable, ITransformation transformation) 69 62 : base() { 70 Parameters.Add(new FixedValueParameter<StringValue>("Original Variable", new StringValue(originalVariable))); 71 Parameters.Add(new FixedValueParameter<StringValue>("Transformed Variable", new StringValue(transformedVariable))); 72 Parameters.Add(new ValueParameter<ITransformation>("Transformation", transformation)); 73 74 RegisterEventHandlers(); 63 Parameters.Add(new FixedValueParameter<StringValue>("Original Variable", new StringValue(originalVariable).AsReadOnly())); 64 Parameters.Add(new FixedValueParameter<StringValue>("Transformed Variable", new StringValue(transformedVariable).AsReadOnly())); 65 Parameters.Add(new ValueParameter<ITransformation>("Transformation", transformation)); // TODO: should be readonly/fixed 75 66 } 76 67 77 68 protected DataAnalysisTransformation(DataAnalysisTransformation original, Cloner cloner) 78 69 : base(original, cloner) { 79 RegisterEventHandlers();80 70 } 81 71 … … 89 79 90 80 [StorableHook(HookType.AfterDeserialization)] 91 private void AfterDeserialization() {92 RegisterEventHandlers();93 }94 #endregion95 96 #region Event-Handling97 private void RegisterEventHandlers() {98 OriginalVariableParameter.Value.ValueChanged += OriginalVariableParameterValue_ValueChanged;99 TransformedVariableParameter.Value.ValueChanged += TransformedVariableParameterValue_ValueChanged;100 TransformationParameter.ValueChanged += TransformationParameter_ValueChanged;101 }102 103 private void OriginalVariableParameterValue_ValueChanged(object sender, EventArgs e) {104 OnToStringChanged();105 }106 private void TransformedVariableParameterValue_ValueChanged(object sender, EventArgs e) {107 OnToStringChanged();108 }109 private void TransformationParameter_ValueChanged(object sender, EventArgs e) {110 OnToStringChanged();111 }112 81 #endregion 113 82 -
branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisTransformationModel.cs
r15869 r15870 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using System.Linq; … … 27 28 28 29 namespace HeuristicLab.Problems.DataAnalysis { 29 [Item(" Transformed Regression Model", "A model that was transformed back to match the original variables after the training was performed on transformed variables.")]30 [Item("Data Analysis Transformation Model", "A model that was transformed back to match the original variables after the training was performed on transformed variables.")] 30 31 [StorableClass] 31 public class TransformedRegressionModel : RegressionModel, ITransformedRegressionModel {32 public abstract class DataAnalysisTransformationModel : DataAnalysisModel, IDataAnalysisTransformationModel { 32 33 33 34 [Storable] 34 public I RegressionModel OriginalModel { get; privateset; }35 public IDataAnalysisModel OriginalModel { get; protected set; } 35 36 36 37 [Storable] 37 public ItemList<IDataAnalysisTransformation> Transformations { get; private set; } 38 public ReadOnlyItemList<IDataAnalysisTransformation> InputTransformations { get; protected set; } 39 40 [Storable] 41 public ReadOnlyItemList<IDataAnalysisTransformation> TargetTransformations { get; protected set; } 42 43 // Usually, the TargetVariable is usually only implemented for Regression and Classification. 44 // However, we implement it in the base class for reducing code duplication and to avoid quasi-identical views. 45 [Storable] 46 private string targetVariable; 47 public string TargetVariable { 48 get { return targetVariable; } 49 set { 50 if (string.IsNullOrEmpty(value) || targetVariable == value) return; 51 targetVariable = value; 52 OnTargetVariableChanged(this, EventArgs.Empty); 53 } 54 } 38 55 39 56 public override IEnumerable<string> VariablesUsedForPrediction { 40 get { return OriginalModel.VariablesUsedForPrediction; }57 get { return OriginalModel.VariablesUsedForPrediction; /* TODO: reduce extend-inputs */} 41 58 } 42 59 43 60 #region Constructor, Cloning & Persistence 44 public TransformedRegressionModel(IRegressionModel originalModel, IEnumerable<IDataAnalysisTransformation> transformations) 45 : base(RegressionProblemData.GetOriginalTragetVariable(originalModel.TargetVariable, transformations)) { 46 Name = "Transformed " + originalModel.Name; 61 protected DataAnalysisTransformationModel(IDataAnalysisModel originalModel, IEnumerable<IDataAnalysisTransformation> transformations) 62 : base(originalModel.Name) { 47 63 OriginalModel = originalModel; 48 Transformations = new ItemList<IDataAnalysisTransformation>(transformations); 64 var transitiveInputs = CalculateTransitiveVariables(originalModel.VariablesUsedForPrediction, transformations); 65 InputTransformations = new ItemList<IDataAnalysisTransformation>(transformations.Where(t => transitiveInputs.Contains(t.OriginalVariable))).AsReadOnly(); 66 TargetTransformations = new ReadOnlyItemList<IDataAnalysisTransformation>(); 49 67 } 50 68 51 protected TransformedRegressionModel(TransformedRegressionModel original, Cloner cloner)69 protected DataAnalysisTransformationModel(DataAnalysisTransformationModel original, Cloner cloner) 52 70 : base(original, cloner) { 53 71 OriginalModel = cloner.Clone(original.OriginalModel); 54 Transformations = cloner.Clone(original.Transformations); 55 } 56 57 public override IDeepCloneable Clone(Cloner cloner) { 58 return new TransformedRegressionModel(this, cloner); 72 InputTransformations = cloner.Clone(original.InputTransformations); 73 TargetTransformations = cloner.Clone(original.TargetTransformations); 74 targetVariable = original.targetVariable; 59 75 } 60 76 61 77 [StorableConstructor] 62 protected TransformedRegressionModel(bool deserializing)78 protected DataAnalysisTransformationModel(bool deserializing) 63 79 : base(deserializing) { } 64 80 #endregion 65 81 82 public static ISet<string> CalculateTransitiveVariables(IEnumerable<string> inputVariables, IEnumerable<IDataAnalysisTransformation> transformations) { 83 var transitiveInputs = new HashSet<string>(inputVariables); 84 85 foreach (var transformation in transformations.Reverse()) { 86 if (transitiveInputs.Contains(transformation.TransformedVariable)) { 87 transitiveInputs.Add(transformation.OriginalVariable); 88 } 89 } 90 91 return transitiveInputs; 92 } 93 94 public static IDataset Transform(IDataset dataset, IEnumerable<IDataAnalysisTransformation> transformations) { 95 var modifiableDataset = ((Dataset)dataset).ToModifiable(); 96 97 foreach (var transformation in transformations) { 98 var trans = (ITransformation<double>)transformation.Transformation; 99 100 var originalData = modifiableDataset.GetDoubleValues(transformation.OriginalVariable); 101 if (!trans.Check(originalData, out string errorMessage)) 102 throw new InvalidOperationException($"Cannot estimate Values, Transformation is invalid: {errorMessage}"); 103 104 var transformedData = trans.Apply(originalData).ToList(); 105 if (modifiableDataset.VariableNames.Contains(transformation.TransformedVariable)) 106 modifiableDataset.ReplaceVariable(transformation.TransformedVariable, transformedData); 107 else 108 modifiableDataset.AddVariable(transformation.TransformedVariable, transformedData); 109 } 110 111 return modifiableDataset; 112 } 113 114 115 116 #region Events 117 public event EventHandler TargetVariableChanged; 118 private void OnTargetVariableChanged(object sender, EventArgs args) { 119 var changed = TargetVariableChanged; 120 if (changed != null) 121 changed(sender, args); 122 } 123 #endregion 124 125 126 127 128 129 130 /* 66 131 // dataset in original data range 67 132 public override IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) { 68 var transformedDataset = Transform Inputs(dataset, Transformations);133 var transformedDataset = Transform(dataset, Transformations); 69 134 70 135 var estimates = OriginalModel.GetEstimatedValues(transformedDataset, rows); 71 136 72 return InverseTransform Estimates(estimates, Transformations, OriginalModel.TargetVariable);137 return InverseTransform(estimates, Transformations, OriginalModel.TargetVariable); 73 138 } 74 139 … … 76 141 public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) { 77 142 // TODO: specialized views for the original solution type are lost (RandomForestSolutionView, ...) 78 return new TransformedRegressionSolution(this, new RegressionProblemData(problemData)); 79 } 80 81 private static IDataset TransformInputs(IDataset dataset, IEnumerable<IDataAnalysisTransformation> transformations) { 82 return DataAnalysisProblemData.Transform(dataset, transformations); 83 } 84 85 private static IEnumerable<double> InverseTransformEstimates(IEnumerable<double> data, IEnumerable<IDataAnalysisTransformation> transformations, string targetVariable) { 86 var estimates = data.ToList(); 87 88 foreach (var transformation in transformations.Reverse()) { 89 if (transformation.TransformedVariable == targetVariable) { 90 var trans = (ITransformation<double>)transformation.Transformation; 91 92 estimates = trans.InverseApply(estimates).ToList(); 93 94 // setup next iteration 95 targetVariable = transformation.OriginalVariable; 96 } 97 } 98 99 return estimates; 100 } 143 return new RegressionSolution(this, new RegressionProblemData(problemData)); 144 } */ 101 145 } 102 146 } -
branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblemData.cs
r15856 r15870 183 183 public override IDataAnalysisProblemData Transform() { 184 184 var transformedProblemData = (IRegressionProblemData)base.Transform(); 185 var targetVariable = GetTransformedTragetVariable(TargetVariable, Transformations);185 var targetVariable = RegressionTransformationModel.GetTransformedTragetVariable(TargetVariable, Transformations); 186 186 transformedProblemData.TargetVariable = targetVariable; 187 187 return transformedProblemData; … … 190 190 public override IDataAnalysisProblemData InverseTransform() { 191 191 var transformedProblemData = (IRegressionProblemData)base.InverseTransform(); 192 var targetVariable = GetOriginalTragetVariable(TargetVariable, Transformations);192 var targetVariable = RegressionTransformationModel.GetOriginalTragetVariable(TargetVariable, Transformations); 193 193 transformedProblemData.TargetVariable = targetVariable; 194 194 return transformedProblemData; 195 195 } 196 197 public static string GetTransformedTragetVariable(string originalTarget, IEnumerable<IDataAnalysisTransformation> transformations) {198 var transformedTarget = originalTarget;199 foreach (var transformation in transformations) {200 if (transformation.OriginalVariable == transformedTarget)201 transformedTarget = transformation.TransformedVariable;202 }203 return transformedTarget;204 }205 206 public static string GetOriginalTragetVariable(string transformedTarget, IEnumerable<IDataAnalysisTransformation> transformations) {207 var originalTarget = transformedTarget;208 foreach (var transformation in transformations.Reverse()) {209 if (transformation.TransformedVariable == originalTarget)210 originalTarget = transformation.OriginalVariable;211 }212 return originalTarget;213 }214 196 } 215 197 } -
branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDataAnalysisTransformation.cs
r15847 r15870 25 25 public interface IDataAnalysisTransformation : INamedItem { 26 26 27 string OriginalVariable { get; set;}28 string TransformedVariable { get; set;}27 string OriginalVariable { get; } 28 string TransformedVariable { get; } 29 29 30 ITransformation Transformation { get; set;}30 ITransformation Transformation { get; } 31 31 } 32 32 } -
branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Regression/IRegressionTransformationModel.cs
r15869 r15870 23 23 24 24 namespace HeuristicLab.Problems.DataAnalysis { 25 public interface ITransformedRegressionModel : IRegressionModel { 26 27 IRegressionModel OriginalModel { get; } 28 29 ItemList<IDataAnalysisTransformation> Transformations { get; } 25 public interface IRegressionTransformationModel : IDataAnalysisTransformationModel, IRegressionModel { 26 new IRegressionModel OriginalModel { get; } 30 27 } 31 28 }
Note: See TracChangeset
for help on using the changeset viewer.