Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/04/18 17:18:02 (7 years ago)
Author:
pfleck
Message:

#2906 Refactoring

  • Moved transformation-specific parts out of existing interfaces.
  • Moved all Transformation logic to DataAnalysisTransformation.
  • Simplified (Inverse)Transformation of Dataset/ProblemData/Model/Solution.
Location:
branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblemData.cs

    r15870 r15884  
    180180      base.AdjustProblemDataProperties(problemData);
    181181    }
    182 
    183     public override IDataAnalysisProblemData Transform() {
    184       var transformedProblemData = (IRegressionProblemData)base.Transform();
    185       var targetVariable = RegressionTransformationModel.GetTransformedTragetVariable(TargetVariable, Transformations);
    186       transformedProblemData.TargetVariable = targetVariable;
    187       return transformedProblemData;
    188     }
    189 
    190     public override IDataAnalysisProblemData InverseTransform() {
    191       var transformedProblemData = (IRegressionProblemData)base.InverseTransform();
    192       var targetVariable = RegressionTransformationModel.GetOriginalTragetVariable(TargetVariable, Transformations);
    193       transformedProblemData.TargetVariable = targetVariable;
    194       return transformedProblemData;
    195     }
    196182  }
    197183}
  • branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionTransformationModel.cs

    r15870 r15884  
    2020#endregion
    2121
    22 using System;
    2322using System.Collections.Generic;
    2423using System.Linq;
     
    3635    }
    3736
     37    IEnumerable<IDataAnalysisTransformation> IRegressionTransformationModel.TargetTransformations {
     38      get { return TargetTransformations; }
     39    }
     40
    3841    #region Constructor, Cloning & Persistence
    3942    public RegressionTransformationModel(IRegressionModel originalModel, IEnumerable<IDataAnalysisTransformation> transformations)
    4043      : base(originalModel, transformations) {
    41       var transitiveTargets = CalculateTransitiveVariables(new[] { originalModel.TargetVariable }, transformations);
     44      var transitiveTargets = DataAnalysisTransformation.GetTransitiveVariables(new[] { originalModel.TargetVariable }, transformations, inverse: true).ToList();
    4245      TargetTransformations = new ItemList<IDataAnalysisTransformation>(transformations.Where(t => transitiveTargets.Contains(t.OriginalVariable))).AsReadOnly();
    43       TargetVariable = GetOriginalTragetVariable(originalModel.TargetVariable, TargetTransformations);
     46      TargetVariable = DataAnalysisTransformation.GetLastTransitiveVariable(originalModel.TargetVariable, TargetTransformations, inverse: true);
    4447    }
    4548
    4649    protected RegressionTransformationModel(RegressionTransformationModel original, Cloner cloner)
    4750      : base(original, cloner) {
    48      
    4951    }
    5052
     
    5961
    6062    public virtual IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
    61       var estimates = OriginalModel.GetEstimatedValues(Transform(dataset, InputTransformations), rows);
    62       return InverseTransform(estimates, TargetTransformations, OriginalModel.TargetVariable);
     63      var transformedInput = DataAnalysisTransformation.Transform(dataset, InputTransformations);
     64      var estimates = OriginalModel.GetEstimatedValues(transformedInput, rows);
     65      return InverseTransform(estimates, TargetTransformations);
    6366    }
    6467
     
    6770    }
    6871
    69     public static IEnumerable<double> InverseTransform(IEnumerable<double> data, IEnumerable<IDataAnalysisTransformation> transformations, string targetVariable) {
    70       var estimates = data.ToList();
    71 
    72       foreach (var transformation in transformations.Reverse()) {
    73         if (transformation.TransformedVariable == targetVariable) {
    74           var trans = (ITransformation<double>)transformation.Transformation;
    75 
    76           estimates = trans.InverseApply(estimates).ToList();
    77 
    78           // setup next iteration
    79           targetVariable = transformation.OriginalVariable;
    80         }
     72    protected static IEnumerable<double> InverseTransform(IEnumerable<double> data, IEnumerable<IDataAnalysisTransformation> transformations) {
     73      foreach (var transformation in transformations.Reverse()) { // TargetTransformations only contains only relevant transformations
     74        var trans = (ITransformation<double>)transformation.Transformation;
     75        data = trans.InverseApply(data).ToList();
    8176      }
    82 
    83       return estimates;
    84     }
    85 
    86     public static string GetTransformedTragetVariable(string originalTarget, IEnumerable<IDataAnalysisTransformation> transformations) {
    87       var transformedTarget = originalTarget;
    88       foreach (var transformation in transformations) {
    89         if (transformation.OriginalVariable == transformedTarget)
    90           transformedTarget = transformation.TransformedVariable;
    91       }
    92       return transformedTarget;
    93     }
    94 
    95     public static string GetOriginalTragetVariable(string transformedTarget, IEnumerable<IDataAnalysisTransformation> transformations) {
    96       var originalTarget = transformedTarget;
    97       foreach (var transformation in transformations.Reverse()) {
    98         if (transformation.TransformedVariable == originalTarget)
    99           originalTarget = transformation.OriginalVariable;
    100       }
    101       return originalTarget;
     77      return data;
    10278    }
    10379  }
Note: See TracChangeset for help on using the changeset viewer.