Changeset 15884 for branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression
- Timestamp:
- 04/04/18 17:18:02 (7 years ago)
- 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 180 180 base.AdjustProblemDataProperties(problemData); 181 181 } 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 }196 182 } 197 183 } -
branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionTransformationModel.cs
r15870 r15884 20 20 #endregion 21 21 22 using System;23 22 using System.Collections.Generic; 24 23 using System.Linq; … … 36 35 } 37 36 37 IEnumerable<IDataAnalysisTransformation> IRegressionTransformationModel.TargetTransformations { 38 get { return TargetTransformations; } 39 } 40 38 41 #region Constructor, Cloning & Persistence 39 42 public RegressionTransformationModel(IRegressionModel originalModel, IEnumerable<IDataAnalysisTransformation> transformations) 40 43 : base(originalModel, transformations) { 41 var transitiveTargets = CalculateTransitiveVariables(new[] { originalModel.TargetVariable }, transformations);44 var transitiveTargets = DataAnalysisTransformation.GetTransitiveVariables(new[] { originalModel.TargetVariable }, transformations, inverse: true).ToList(); 42 45 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); 44 47 } 45 48 46 49 protected RegressionTransformationModel(RegressionTransformationModel original, Cloner cloner) 47 50 : base(original, cloner) { 48 49 51 } 50 52 … … 59 61 60 62 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); 63 66 } 64 67 … … 67 70 } 68 71 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(); 81 76 } 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; 102 78 } 103 79 }
Note: See TracChangeset
for help on using the changeset viewer.