Changeset 15856


Ignore:
Timestamp:
03/23/18 14:10:15 (18 months ago)
Author:
pfleck
Message:

#2906 Implemented transformation re-apply of an already reverse-transformed model.

Location:
branches/2906_Transformations
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • branches/2906_Transformations/HeuristicLab.DataPreprocessing.Views/3.4/TransformationView.cs

    r15846 r15856  
    7878
    7979      if (success) {
    80         Content.CheckedTransformationList.Clear();
     80        //Content.CheckedTransformationList.Clear();
    8181        MessageBox.Show(this, "Transformations applied.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
    8282      } else {
  • branches/2906_Transformations/HeuristicLab.DataPreprocessing/3.4/ProblemDataCreator.cs

    r15847 r15856  
    6060
    6161      SetTrainingAndTestPartition(problemData);
     62      SetAllowedInputVariables(problemData, oldProblemData.AllowedInputVariables);
    6263      // set the input variables to the correct checked state
    63       var inputVariables = oldProblemData.InputVariables.ToDictionary(x => x.Value, x => x);
    64       foreach (var variable in problemData.InputVariables) {
    65         bool isChecked = inputVariables.ContainsKey(variable.Value) && oldProblemData.InputVariables.ItemChecked(inputVariables[variable.Value]);
    66         problemData.InputVariables.SetItemCheckedState(variable, isChecked);
    67       }
     64      //var inputVariables = oldProblemData.InputVariables.ToDictionary(x => x.Value, x => x);
     65      //foreach (var variable in problemData.InputVariables) {
     66      //  bool isChecked = inputVariables.ContainsKey(variable.Value) && oldProblemData.InputVariables.ItemChecked(inputVariables[variable.Value]);
     67      //  problemData.InputVariables.SetItemCheckedState(variable, isChecked);
     68      //}
    6869
    6970      return problemData;
     
    8485    private IDataAnalysisProblemData CreateRegressionData(RegressionProblemData oldProblemData) {
    8586      // TODO: transformations (additional inputs, target changed)
    86       var targetVariable = oldProblemData.TargetVariable;
     87      var targetVariable = RegressionProblemData.GetTransformedTragetVariable(oldProblemData.TargetVariable, Transformations);
    8788      if (!context.Data.VariableNames.Contains(targetVariable))
    8889        targetVariable = context.Data.VariableNames.First();
     
    116117    }
    117118
     119     void SetAllowedInputVariables(IDataAnalysisProblemData problemData, IEnumerable<string> oldInputVariables) {
     120       var inputs = DataAnalysisProblemData.ExtendInputVariables(oldInputVariables, Transformations);
     121
     122      foreach (var input in problemData.InputVariables) {
     123        problemData.InputVariables.SetItemCheckedState(input, inputs.Contains(input.Value));
     124      }
     125    }
     126
    118127    private IEnumerable<string> GetDoubleInputVariables(string targetVariable) {
    119128      var variableNames = new List<string>();
  • branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj

    r15848 r15856  
    438438      <DependentUpon>TransformedRegressionModelView.cs</DependentUpon>
    439439    </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>
     445    </Compile>
    440446    <Compile Include="Solution Views\ClassificationSolutionView.cs">
    441447      <SubType>UserControl</SubType>
  • branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views/RegressionSolutionView.Designer.cs

    r15846 r15856  
    4646    /// </summary>
    4747    private void InitializeComponent() {
    48       this.transformButton = new System.Windows.Forms.Button();
     48      this.TransformButton = new System.Windows.Forms.Button();
    4949      ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit();
    5050      this.splitContainer.Panel1.SuspendLayout();
     
    7070      this.toolTip.SetToolTip(this.removeButton, "Remove");
    7171      //
    72       // transformButton
     72      // TransformButton
    7373      //
    74       this.transformButton.Location = new System.Drawing.Point(117, 3);
    75       this.transformButton.Name = "transformButton";
    76       this.transformButton.Size = new System.Drawing.Size(75, 23);
    77       this.transformButton.TabIndex = 1;
    78       this.transformButton.Text = "Transform";
    79       this.transformButton.UseVisualStyleBackColor = true;
    80       this.transformButton.Click += new System.EventHandler(this.transformButton_Click);
     74      this.TransformButton.Location = new System.Drawing.Point(117, 3);
     75      this.TransformButton.Name = "TransformButton";
     76      this.TransformButton.Size = new System.Drawing.Size(75, 23);
     77      this.TransformButton.TabIndex = 1;
     78      this.TransformButton.Text = "Reverse Transformations";
     79      this.TransformButton.UseVisualStyleBackColor = true;
     80      this.TransformButton.Click += new System.EventHandler(this.transformButton_Click);
    8181      //
    8282      // RegressionSolutionView
     
    9696    #endregion
    9797
    98     private System.Windows.Forms.Button transformButton;
     98    protected System.Windows.Forms.Button TransformButton;
    9999  }
    100100}
  • branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views/RegressionSolutionView.cs

    r15847 r15856  
    3131    public RegressionSolutionView() {
    3232      InitializeComponent();
    33       flowLayoutPanel.Controls.Add(transformButton);
     33      flowLayoutPanel.Controls.Add(TransformButton);
    3434    }
    3535
     
    4141    protected override void SetEnabledStateOfControls() {
    4242      base.SetEnabledStateOfControls();
    43       transformButton.Visible = Content != null && Content.ProblemData.Transformations.Any();
     43      TransformButton.Visible = Content != null && Content.ProblemData.Transformations.Any();
    4444    }
    4545
     
    5959    #endregion
    6060
    61     private void transformButton_Click(object sender, System.EventArgs e) {
     61    protected virtual void transformButton_Click(object sender, System.EventArgs e) {
    6262      var transformedModel = new TransformedRegressionModel(Content.Model, Content.ProblemData.Transformations);
    6363      var originalProblemData = (IRegressionProblemData)Content.ProblemData.InverseTransform();
  • branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisProblemData.cs

    r15848 r15856  
    242242    }
    243243
    244     public virtual IDataAnalysisProblemData InverseTransform() {
    245       var newDataset = InverseTransform(Dataset, Transformations);
     244    public virtual IDataAnalysisProblemData Transform() {
     245      var newDataset = Transform(Dataset, Transformations);
     246
     247      var extendedInputs = ExtendInputVariables(AllowedInputVariables, Transformations);
     248      var checkedInputs = new CheckedItemList<StringValue>(newDataset.VariableNames.Select(x => new StringValue(x)));
     249      foreach (var input in checkedInputs) checkedInputs.SetItemCheckedState(input, extendedInputs.Contains(input.Value));
    246250
    247251      // TODO: Cannot create concrete instance here (maybe derived Create-method?)
    248252      var cloner = new Cloner();
    249253      cloner.RegisterClonedObject(Dataset, newDataset);
    250       cloner.RegisterClonedObject(TransformationsParameter.Value, new ItemList<IDataAnalysisTransformation>().AsReadOnly());
     254      cloner.RegisterClonedObject(InputVariables, checkedInputs.AsReadOnly());
     255      //cloner.RegisterClonedObject(TransformationsParameter.Value, new ItemList<IDataAnalysisTransformation>(transformations).AsReadOnly());
     256
     257      return cloner.Clone(this);
     258    }
     259
     260    public virtual IDataAnalysisProblemData InverseTransform() {
     261      var newDataset = InverseTransform(Dataset, Transformations);
     262
     263      var checkedInputs = new CheckedItemList<StringValue>(newDataset.VariableNames.Select(x => new StringValue(x)));
     264      foreach (var input in checkedInputs) checkedInputs.SetItemCheckedState(input, AllowedInputVariables.Contains(input.Value));
     265
     266      // TODO: Cannot create concrete instance here (maybe derived Create-method?)
     267      var cloner = new Cloner();
     268      cloner.RegisterClonedObject(Dataset, newDataset);
     269      cloner.RegisterClonedObject(InputVariables, checkedInputs.AsReadOnly());
     270      //cloner.RegisterClonedObject(TransformationsParameter.Value, new ItemList<IDataAnalysisTransformation>().AsReadOnly());
    251271
    252272      return cloner.Clone(this);
     
    281301        var trans = (ITransformation<double>)transformation.Transformation;
    282302
    283         var transformedData = modifiableDataset.GetDoubleValues(transformation.TransformedVariable);
    284 
    285         var originalData = trans.InverseApply(transformedData).ToList();
    286         modifiableDataset.ReplaceVariable(transformation.OriginalVariable, originalData);
     303        var prevTransformations = transformations.Except(transformationsStack);
     304        bool originalWasChanged = prevTransformations.Any(x => x.TransformedVariable == transformation.OriginalVariable);
     305        if (originalWasChanged) {
     306          var transformedData = modifiableDataset.GetDoubleValues(transformation.TransformedVariable);
     307
     308          var originalData = trans.InverseApply(transformedData).ToList();
     309          modifiableDataset.ReplaceVariable(transformation.OriginalVariable, originalData);
     310        }
    287311
    288312        bool transformedVariablePending = transformationsStack.Any(x => x.OriginalVariable == transformation.TransformedVariable);
     
    293317      return modifiableDataset;
    294318    }
     319
     320    public static IEnumerable<string> ExtendInputVariables(IEnumerable<string> oldInputVariables, IEnumerable<IDataAnalysisTransformation> transformations) {
     321      var inputs = new HashSet<string>(oldInputVariables);
     322
     323      foreach (var transformation in transformations) {
     324        if (inputs.Contains(transformation.OriginalVariable))
     325          inputs.Add(transformation.TransformedVariable);
     326      }
     327
     328      return inputs;
     329    }
     330
     331    public static IEnumerable<string> RemoveVirtualVariables(IEnumerable<string> variables, IEnumerable<IDataAnalysisTransformation> transformations) {
     332      var remainingVariables = new HashSet<string>(variables);
     333
     334      var transformationsStack = new Stack<IDataAnalysisTransformation>(transformations);
     335
     336      while (transformationsStack.Any()) {
     337        var transformation = transformationsStack.Pop();
     338
     339
     340        bool transformedVariablePending = transformationsStack.Any(x => x.OriginalVariable == transformation.TransformedVariable);
     341        if (!transformedVariablePending)
     342          remainingVariables.Remove(transformation.TransformedVariable);
     343      }
     344
     345      return remainingVariables;
     346    }
    295347  }
    296348}
  • branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblemData.cs

    r15847 r15856  
    181181    }
    182182
     183    public override IDataAnalysisProblemData Transform() {
     184      var transformedProblemData = (IRegressionProblemData)base.Transform();
     185      var targetVariable = GetTransformedTragetVariable(TargetVariable, Transformations);
     186      transformedProblemData.TargetVariable = targetVariable;
     187      return transformedProblemData;
     188    }
     189
    183190    public override IDataAnalysisProblemData InverseTransform() {
    184191      var transformedProblemData = (IRegressionProblemData)base.InverseTransform();
     
    186193      transformedProblemData.TargetVariable = targetVariable;
    187194      return transformedProblemData;
     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;
    188204    }
    189205
  • branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDataAnalysisProblemData.cs

    r15847 r15856  
    4444
    4545    IEnumerable<IDataAnalysisTransformation> Transformations { get; }
     46    IDataAnalysisProblemData Transform();
    4647    IDataAnalysisProblemData InverseTransform();
    4748
Note: See TracChangeset for help on using the changeset viewer.