Free cookie consent management tool by TermsFeed Policy Generator

Changeset 15870 for branches


Ignore:
Timestamp:
03/28/18 17:17:31 (7 years ago)
Author:
pfleck
Message:

#2906

  • Implemented for classification, clustering, etc.
  • Simplified Transformation interfaces (read-only, ...).
  • Started moving transformation logic out of ProblemData.
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  
    8585    private IDataAnalysisProblemData CreateRegressionData(RegressionProblemData oldProblemData) {
    8686      // TODO: transformations (additional inputs, target changed)
    87       var targetVariable = RegressionProblemData.GetTransformedTragetVariable(oldProblemData.TargetVariable, CreateDataAnalysisTransformation());
     87      var targetVariable = RegressionTransformationModel.GetTransformedTragetVariable(oldProblemData.TargetVariable, CreateDataAnalysisTransformation());
    8888      if (!context.Data.VariableNames.Contains(targetVariable))
    8989        targetVariable = context.Data.VariableNames.First();
  • branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis.Views/3.4/DataAnalysisTransformationModelView.Designer.cs

    r15869 r15870  
    2121
    2222namespace HeuristicLab.Problems.DataAnalysis.Views {
    23   partial class TransformedRegressionModelView {
     23  partial class DataAnalysisTransformationModelView {
    2424    /// <summary>
    2525    /// Required designer variable.
     
    4545    /// </summary>
    4646    private void InitializeComponent() {
     47      this.originalModelTabPage = new System.Windows.Forms.TabPage();
     48      this.modelViewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost();
    4749      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();
    5255      this.tabControl.SuspendLayout();
    53       this.tabPageModel.SuspendLayout();
    54       this.tabPageTransformations.SuspendLayout();
     56      this.inputTransformationsTabPage.SuspendLayout();
     57      this.targetTransformationsTabPage.SuspendLayout();
    5558      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;
    5684      //
    5785      // tabControl
    5886      //
    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) 
    6189            | 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);
    6493      this.tabControl.Location = new System.Drawing.Point(3, 3);
    6594      this.tabControl.Name = "tabControl";
     
    6897      this.tabControl.TabIndex = 0;
    6998      //
    70       // tabPageModel
     99      // inputTransformationsTabPage
    71100      //
    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;
    80109      //
    81       // tabPageTransformations
     110      // inputTransformationsViewHost
    82111      //
    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;
    91123      //
    92       // modelViewHost
     124      // targetTransformationsTabPage
    93125      //
    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;
    99134      //
    100       // transformationsViewHost
     135      // targetTransformationsViewHost
    101136      //
    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;
    107148      //
    108       // TransformedRegressionModelView
     149      // DataAnalysisTransformationModelView
    109150      //
    110151      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    111152      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    112153      this.Controls.Add(this.tabControl);
    113       this.Name = "TransformedRegressionModelView";
     154      this.Name = "DataAnalysisTransformationModelView";
    114155      this.Size = new System.Drawing.Size(500, 424);
     156      this.originalModelTabPage.ResumeLayout(false);
    115157      this.tabControl.ResumeLayout(false);
    116       this.tabPageModel.ResumeLayout(false);
    117       this.tabPageTransformations.ResumeLayout(false);
     158      this.inputTransformationsTabPage.ResumeLayout(false);
     159      this.targetTransformationsTabPage.ResumeLayout(false);
    118160      this.ResumeLayout(false);
    119161
     
    122164    #endregion
    123165
     166    private System.Windows.Forms.TabPage originalModelTabPage;
     167    private MainForm.WindowsForms.ViewHost modelViewHost;
    124168    private System.Windows.Forms.TabControl tabControl;
    125     private System.Windows.Forms.TabPage tabPageModel;
    126     private System.Windows.Forms.TabPage tabPageTransformations;
    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;
    129173  }
    130174}
  • branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis.Views/3.4/DataAnalysisTransformationModelView.cs

    r15869 r15870  
    2424
    2525namespace HeuristicLab.Problems.DataAnalysis.Views {
    26   [View("Transformed regression model")]
    27   [Content(typeof(ITransformedRegressionModel), true)]
    28   public partial class TransformedRegressionModelView : ItemView {
     26  [View("Transformation Model View")]
     27  [Content(typeof(IDataAnalysisTransformationModel), true)]
     28  public partial class DataAnalysisTransformationModelView : ItemView {
    2929
    30     public new ITransformedRegressionModel Content {
    31       get { return (ITransformedRegressionModel)base.Content; }
     30    public new IDataAnalysisTransformationModel Content {
     31      get { return (IDataAnalysisTransformationModel)base.Content; }
    3232      set { base.Content = value; }
    3333    }
    3434
    35     public TransformedRegressionModelView() {
     35    public DataAnalysisTransformationModelView() {
    3636      InitializeComponent();
    3737    }
     
    4040      base.OnContentChanged();
    4141      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;
    4345    }
    4446
    4547    protected override void SetEnabledStateOfControls() {
    4648      base.SetEnabledStateOfControls();
    47       tabControl.Enabled = Content != null;
     49      tabControl.Enabled = Content != null && !Locked;
    4850    }
    4951  }
  • branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj

    r15856 r15870  
    432432      <DependentUpon>RegressionSolutionScatterPlotView.cs</DependentUpon>
    433433    </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>
    445439    </Compile>
    446440    <Compile Include="Solution Views\ClassificationSolutionView.cs">
  • branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views/DataAnalysisSolutionView.Designer.cs

    r15583 r15870  
    4747      this.flowLayoutPanel = new System.Windows.Forms.FlowLayoutPanel();
    4848      this.loadProblemDataButton = new System.Windows.Forms.Button();
     49      this.transformButton = new System.Windows.Forms.Button();
    4950      this.loadProblemDataFileDialog = new System.Windows.Forms.OpenFileDialog();
    5051      ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit();
     
    5455      this.itemsGroupBox.SuspendLayout();
    5556      this.detailsGroupBox.SuspendLayout();
     57      this.flowLayoutPanel.SuspendLayout();
    5658      this.SuspendLayout();
    5759      //
     
    7779      //
    7880      // 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);
    8286      this.flowLayoutPanel.Location = new System.Drawing.Point(0, 0);
     87      this.flowLayoutPanel.Name = "flowLayoutPanel";
    8388      this.flowLayoutPanel.Padding = new System.Windows.Forms.Padding(3, 0, 3, 0);
    8489      this.flowLayoutPanel.Size = new System.Drawing.Size(266, 30);
    85       this.flowLayoutPanel.Controls.Add(this.loadProblemDataButton);
    86       //
     90      this.flowLayoutPanel.TabIndex = 1;
     91      // 
    8792      // loadProblemDataButton
    88       //
     93      // 
    8994      this.loadProblemDataButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)));
    9095      this.loadProblemDataButton.AutoSize = true;
     
    98103      this.loadProblemDataButton.UseVisualStyleBackColor = true;
    99104      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.");
    101105      //
    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
    103119      //
    104120      this.loadProblemDataFileDialog.Filter = "HL files|*.hl";
     
    115131      this.itemsGroupBox.ResumeLayout(false);
    116132      this.detailsGroupBox.ResumeLayout(false);
     133      this.flowLayoutPanel.ResumeLayout(false);
     134      this.flowLayoutPanel.PerformLayout();
    117135      this.ResumeLayout(false);
    118136
     
    124142    protected System.Windows.Forms.OpenFileDialog loadProblemDataFileDialog;
    125143    protected System.Windows.Forms.FlowLayoutPanel flowLayoutPanel;
    126 
     144    protected System.Windows.Forms.Button transformButton;
    127145  }
    128146}
  • branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views/DataAnalysisSolutionView.cs

    r15583 r15870  
    2525using System.Linq;
    2626using System.Windows.Forms;
     27using HeuristicLab.Common.Resources;
    2728using HeuristicLab.Core;
    2829using HeuristicLab.Core.Views;
     
    3738  [Content(typeof(DataAnalysisSolution), false)]
    3839  public partial class DataAnalysisSolutionView : NamedItemCollectionView<IResult> {
     40
     41    private const string BacktransformButtonText = "Integrate Transformations";
     42    private const string ReapplyTransformationsButtonText = "Restore Original Model";
     43
    3944    public DataAnalysisSolutionView() {
    4045      InitializeComponent();
    4146      viewHost.ViewsLabelVisible = false;
     47      transformButton.Image = VSImageLibrary.Event;
    4248    }
    4349
     
    5258      removeButton.Enabled = false;
    5359      loadProblemDataButton.Enabled = Content != null && !Locked;
     60      transformButton.Enabled = Content != null && !Locked;
     61      transformButton.Visible = Content != null && Content.ProblemData.Transformations.Any();
    5462    }
    5563
     
    8189        }
    8290      }
     91
     92      if (Content == null) return;
     93
     94      transformButton.Text = Content.Model is IDataAnalysisTransformationModel
     95        ? ReapplyTransformationsButtonText : BacktransformButtonText;
    8396    }
    8497
     
    147160          solution.Name += " with loaded problemData";
    148161        MainFormManager.MainForm.ShowContent(solution);
    149       }
    150       catch (InvalidOperationException invalidOperationException) {
     162      } catch (InvalidOperationException invalidOperationException) {
    151163        ErrorHandling.ShowErrorDialog(this, invalidOperationException);
    152       }
    153       catch (ArgumentException argumentException) {
     164      } catch (ArgumentException argumentException) {
    154165        ErrorHandling.ShowErrorDialog(this, argumentException);
    155166      }
     
    238249        Content.Filename = string.Empty;
    239250        MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().UpdateTitle();
    240       }
    241       catch (InvalidOperationException invalidOperationException) {
     251      } catch (InvalidOperationException invalidOperationException) {
    242252        ErrorHandling.ShowErrorDialog(this, invalidOperationException);
    243       }
    244       catch (ArgumentException argumentException) {
     253      } catch (ArgumentException argumentException) {
    245254        ErrorHandling.ShowErrorDialog(this, argumentException);
    246255      }
     
    248257    #endregion
    249258
     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);
    250297  }
    251298}
  • branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views/RegressionSolutionView.Designer.cs

    r15864 r15870  
    4848    private void InitializeComponent() {
    4949      System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(RegressionSolutionView));
    50       this.TransformButton = new System.Windows.Forms.Button();
    5150      ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit();
    5251      this.splitContainer.Panel1.SuspendLayout();
     
    7271      this.toolTip.SetToolTip(this.removeButton, "Remove");
    7372      //
    74       // TransformButton
    75       //
    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       //
    8873      // RegressionSolutionView
    8974      //
     
    10186
    10287    #endregion
    103 
    104     protected System.Windows.Forms.Button TransformButton;
    10588  }
    10689}
  • branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views/RegressionSolutionView.cs

    r15864 r15870  
    2020#endregion
    2121
    22 using System.Linq;
    2322using System.Windows.Forms;
    24 using HeuristicLab.Common.Resources;
    2523using HeuristicLab.Core;
    2624using HeuristicLab.MainForm;
     
    3230    public RegressionSolutionView() {
    3331      InitializeComponent();
    34       TransformButton.Image = VSImageLibrary.Event;
    35       flowLayoutPanel.Controls.Add(TransformButton);
    3632    }
    3733
     
    4339    protected override void SetEnabledStateOfControls() {
    4440      base.SetEnabledStateOfControls();
    45       TransformButton.Enabled = Content != null;
    46       TransformButton.Visible = Content != null && Content.ProblemData.Transformations.Any();
    4741    }
    4842
     
    6155    }
    6256    #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     }
    7057  }
    7158}
  • branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj

    r15864 r15870  
    187187    <Compile Include="Implementation\Classification\ClassificationSolutionBase.cs" />
    188188    <Compile Include="Implementation\Classification\ClassificationSolutionVariableImpactsCalculator.cs" />
     189    <Compile Include="Implementation\Classification\ClassificationTransformationModel.cs" />
    189190    <Compile Include="Implementation\Classification\ConstantClassificationSolution.cs" />
    190191    <Compile Include="Implementation\Classification\DiscriminantFunctionClassificationSolutionBase.cs" />
     
    193194    <Compile Include="Implementation\Clustering\ClusteringProblemData.cs" />
    194195    <Compile Include="Implementation\Clustering\ClusteringSolution.cs" />
     196    <Compile Include="Implementation\Clustering\ClusteringTransformationModel.cs" />
    195197    <Compile Include="Implementation\ConstantModel.cs" />
    196198    <Compile Include="Implementation\DataAnalysisModel.cs" />
     
    206208    <Compile Include="Implementation\Regression\RegressionModel.cs" />
    207209    <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" />
    210212    <Compile Include="Implementation\TimeSeriesPrognosis\Models\ConstantTimeSeriesPrognosisModel.cs" />
    211213    <Compile Include="Implementation\TimeSeriesPrognosis\Models\TimeSeriesPrognosisAutoRegressiveModel.cs" />
     214    <Compile Include="Implementation\TimeSeriesPrognosis\Models\TimeSeriesPrognosisTransformationModel.cs" />
    212215    <Compile Include="Implementation\TimeSeriesPrognosis\TimeSeriesPrognosisProblem.cs" />
    213216    <Compile Include="Implementation\TimeSeriesPrognosis\TimeSeriesPrognosisProblemData.cs" />
     
    236239      <SubType>Code</SubType>
    237240    </Compile>
     241    <Compile Include="Interfaces\Classification\IClassificationTransformationModel.cs" />
    238242    <Compile Include="Interfaces\Classification\IDiscriminantFunctionThresholdCalculator.cs" />
     243    <Compile Include="Interfaces\Clustering\IClusteringTransformationModel.cs" />
    239244    <Compile Include="Interfaces\IDataAnalysisSolutionExporter.cs" />
    240245    <Compile Include="Interfaces\IDataAnalysisTransformation.cs" />
     246    <Compile Include="Interfaces\IDataAnalysisTransformationModel.cs" />
    241247    <Compile Include="Interfaces\IDataset.cs" />
    242248    <Compile Include="Interfaces\IDependencyCalculator.cs" />
    243249    <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" />
    246251    <Compile Include="Interfaces\Regression\IConfidenceRegressionModel.cs" />
    247252    <Compile Include="Interfaces\Regression\IConfidenceRegressionSolution.cs" />
     
    256261    <Compile Include="Interfaces\TimeSeriesPrognosis\ITimeSeriesPrognosisProblemData.cs" />
    257262    <Compile Include="Interfaces\TimeSeriesPrognosis\ITimeSeriesPrognosisSolution.cs" />
     263    <Compile Include="Interfaces\TimeSeriesPrognosis\ITimeSeriesPrognosisTransformationModel.cs" />
    258264    <Compile Include="ModifiableDataset.cs" />
    259265    <Compile Include="OnlineCalculators\AutoCorrelationCalculator.cs" />
  • branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisProblemData.cs

    r15858 r15870  
    243243
    244244    public virtual IDataAnalysisProblemData Transform() {
    245       var newDataset = Transform(Dataset, Transformations);
     245      var newDataset = DataAnalysisTransformationModel.Transform(Dataset, Transformations);
    246246
    247247      var extendedInputs = ExtendInputVariables(AllowedInputVariables, Transformations);
     
    253253      cloner.RegisterClonedObject(Dataset, newDataset);
    254254      cloner.RegisterClonedObject(InputVariables, checkedInputs.AsReadOnly());
    255       //cloner.RegisterClonedObject(TransformationsParameter.Value, new ItemList<IDataAnalysisTransformation>(transformations).AsReadOnly());
     255      // TODO: valid values for target are not extended
    256256
    257257      return cloner.Clone(this);
     
    268268      cloner.RegisterClonedObject(Dataset, newDataset);
    269269      cloner.RegisterClonedObject(InputVariables, checkedInputs.AsReadOnly());
    270       //cloner.RegisterClonedObject(TransformationsParameter.Value, new ItemList<IDataAnalysisTransformation>().AsReadOnly());
     270      // TODO: check valid target values
    271271
    272272      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         else
    289           modifiableDataset.AddVariable(transformation.TransformedVariable, transformedData);
    290       }
    291 
    292       return modifiableDataset;
    293273    }
    294274
  • branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisTransformation.cs

    r15865 r15870  
    2020#endregion
    2121
    22 using System;
    2322using HeuristicLab.Common;
    2423using HeuristicLab.Core;
     
    4039    }
    4140
    42     private IValueParameter<ITransformation> TransformationParameter {
    43       get { return (IValueParameter<ITransformation>)Parameters["Transformation"]; }
     41    private ValueParameter<ITransformation> TransformationParameter {
     42      get { return (ValueParameter<ITransformation>)Parameters["Transformation"]; }
    4443    }
    4544    #endregion
     
    4847    public string OriginalVariable {
    4948      get { return OriginalVariableParameter.Value.Value; }
    50       set { OriginalVariableParameter.Value.Value = value; }
    5149    }
    5250
    5351    public string TransformedVariable {
    5452      get { return TransformedVariableParameter.Value.Value; }
    55       set { TransformedVariableParameter.Value.Value = value; }
    5653    }
    5754
    5855    public ITransformation Transformation {
    5956      get { return TransformationParameter.Value; }
    60       set { TransformationParameter.Value = value; }
    6157    }
    6258    #endregion
    6359
    6460    #region Constructor, Cloning & Persistence
    65     public DataAnalysisTransformation()
    66       : this("", "", new IdentityTransformation()) {
    67     }
    6861    public DataAnalysisTransformation(string originalVariable, string transformedVariable, ITransformation transformation)
    6962      : 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
    7566    }
    7667
    7768    protected DataAnalysisTransformation(DataAnalysisTransformation original, Cloner cloner)
    7869      : base(original, cloner) {
    79       RegisterEventHandlers();
    8070    }
    8171
     
    8979
    9080    [StorableHook(HookType.AfterDeserialization)]
    91     private void AfterDeserialization() {
    92       RegisterEventHandlers();
    93     }
    94     #endregion
    95 
    96     #region Event-Handling
    97     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     }
    11281    #endregion
    11382
  • branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisTransformationModel.cs

    r15869 r15870  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.Linq;
     
    2728
    2829namespace 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.")]
    3031  [StorableClass]
    31   public class TransformedRegressionModel : RegressionModel, ITransformedRegressionModel {
     32  public abstract class DataAnalysisTransformationModel : DataAnalysisModel, IDataAnalysisTransformationModel {
    3233
    3334    [Storable]
    34     public IRegressionModel OriginalModel { get; private set; }
     35    public IDataAnalysisModel OriginalModel { get; protected set; }
    3536
    3637    [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    }
    3855
    3956    public override IEnumerable<string> VariablesUsedForPrediction {
    40       get { return OriginalModel.VariablesUsedForPrediction; }
     57      get { return OriginalModel.VariablesUsedForPrediction; /* TODO: reduce extend-inputs */}
    4158    }
    4259
    4360    #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) {
    4763      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>();
    4967    }
    5068
    51     protected TransformedRegressionModel(TransformedRegressionModel original, Cloner cloner)
     69    protected DataAnalysisTransformationModel(DataAnalysisTransformationModel original, Cloner cloner)
    5270      : base(original, cloner) {
    5371      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;
    5975    }
    6076
    6177    [StorableConstructor]
    62     protected TransformedRegressionModel(bool deserializing)
     78    protected DataAnalysisTransformationModel(bool deserializing)
    6379      : base(deserializing) { }
    6480    #endregion
    6581
     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    /*
    66131    // dataset in original data range
    67132    public override IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
    68       var transformedDataset = TransformInputs(dataset, Transformations);
     133      var transformedDataset = Transform(dataset, Transformations);
    69134
    70135      var estimates = OriginalModel.GetEstimatedValues(transformedDataset, rows);
    71136
    72       return InverseTransformEstimates(estimates, Transformations, OriginalModel.TargetVariable);
     137      return InverseTransform(estimates, Transformations, OriginalModel.TargetVariable);
    73138    }
    74139
     
    76141    public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
    77142      // 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    } */
    101145  }
    102146}
  • branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblemData.cs

    r15856 r15870  
    183183    public override IDataAnalysisProblemData Transform() {
    184184      var transformedProblemData = (IRegressionProblemData)base.Transform();
    185       var targetVariable = GetTransformedTragetVariable(TargetVariable, Transformations);
     185      var targetVariable = RegressionTransformationModel.GetTransformedTragetVariable(TargetVariable, Transformations);
    186186      transformedProblemData.TargetVariable = targetVariable;
    187187      return transformedProblemData;
     
    190190    public override IDataAnalysisProblemData InverseTransform() {
    191191      var transformedProblemData = (IRegressionProblemData)base.InverseTransform();
    192       var targetVariable = GetOriginalTragetVariable(TargetVariable, Transformations);
     192      var targetVariable = RegressionTransformationModel.GetOriginalTragetVariable(TargetVariable, Transformations);
    193193      transformedProblemData.TargetVariable = targetVariable;
    194194      return transformedProblemData;
    195195    }
    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     }
    214196  }
    215197}
  • branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDataAnalysisTransformation.cs

    r15847 r15870  
    2525  public interface IDataAnalysisTransformation : INamedItem {
    2626
    27     string OriginalVariable { get; set; }
    28     string TransformedVariable { get; set; }
     27    string OriginalVariable { get; }
     28    string TransformedVariable { get; }
    2929
    30     ITransformation Transformation { get; set; }
     30    ITransformation Transformation { get; }
    3131  }
    3232}
  • branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Regression/IRegressionTransformationModel.cs

    r15869 r15870  
    2323
    2424namespace 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; }
    3027  }
    3128}
Note: See TracChangeset for help on using the changeset viewer.