Changeset 15847
- Timestamp:
- 03/19/18 17:46:57 (7 years ago)
- Location:
- branches/2906_Transformations
- Files:
-
- 3 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2906_Transformations/HeuristicLab.DataPreprocessing.Views/3.4/HeuristicLab.DataPreprocessing.Views-3.4.csproj
r15846 r15847 347 347 <EmbeddedResource Include="ScatterPlotSingleView.resx"> 348 348 <DependentUpon>ScatterPlotSingleView.cs</DependentUpon> 349 </EmbeddedResource>350 <EmbeddedResource Include="TransformationView.resx">351 <DependentUpon>TransformationView.cs</DependentUpon>352 349 </EmbeddedResource> 353 350 </ItemGroup> -
branches/2906_Transformations/HeuristicLab.DataPreprocessing/3.4/ProblemDataCreator.cs
r15846 r15847 83 83 84 84 private IDataAnalysisProblemData CreateRegressionData(RegressionProblemData oldProblemData) { 85 // TODO: transformations (additional inputs, target changed) 85 86 var targetVariable = oldProblemData.TargetVariable; 86 87 if (!context.Data.VariableNames.Contains(targetVariable)) -
branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj
r15846 r15847 184 184 <Reference Include="HeuristicLab.Problems.DataAnalysis.Symbolic-3.4, Version=3.4.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 185 185 <SpecificVersion>False</SpecificVersion> 186 186 <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.dll</HintPath> 187 187 <Private>False</Private> 188 188 </Reference> … … 586 586 <DependentUpon>AbstractFeatureCorrelationView.cs</DependentUpon> 587 587 </EmbeddedResource> 588 <EmbeddedResource Include="Solution Views\RegressionSolutionView.resx">589 <DependentUpon>RegressionSolutionView.cs</DependentUpon>590 </EmbeddedResource>591 588 </ItemGroup> 592 589 <ItemGroup> -
branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views/RegressionSolutionView.cs
r15846 r15847 60 60 61 61 private void transformButton_Click(object sender, System.EventArgs e) { 62 var targetVariable = TransformedRegressionModel.GetOriginalTragetVariable(Content.Model.TargetVariable, Content.ProblemData.Transformations);63 62 var transformedModel = new TransformedRegressionModel(Content.Model, Content.ProblemData.Transformations); 64 var transformedSolution = new TransformedRegressionSolution(transformedModel, new RegressionProblemData(Content.ProblemData) { TargetVariable = targetVariable }); 63 var originalProblemData = (IRegressionProblemData)Content.ProblemData.InverseTransform(); 64 var transformedSolution = new TransformedRegressionSolution(transformedModel, originalProblemData); 65 65 MainFormManager.MainForm.ShowContent(transformedSolution); 66 66 } -
branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisProblemData.cs
r15846 r15847 241 241 } 242 242 } 243 244 public virtual IDataAnalysisProblemData InverseTransform() { 245 var newDataset = InverseTransform(Dataset, Transformations); 246 247 // TODO: Cannot create concrete instance here (maybe derived Create-method?) 248 var cloner = new Cloner(); 249 cloner.RegisterClonedObject(Dataset, newDataset); 250 cloner.RegisterClonedObject(TransformationsParameter.Value, new ItemList<IDataAnalysisTransformation>().AsReadOnly()); 251 252 return cloner.Clone(this); 253 } 254 255 public static IDataset Transform(IDataset dataset, IEnumerable<IDataAnalysisTransformation> transformations) { 256 var modifiableDataset = ((Dataset)dataset).ToModifiable(); 257 258 foreach (var transformation in transformations) { 259 var trans = (ITransformation<double>)transformation.Transformation; 260 261 var originalData = modifiableDataset.GetDoubleValues(transformation.OriginalVariable); 262 if (!trans.Check(originalData, out string errorMessage)) 263 throw new InvalidOperationException($"Cannot estimate Values, Transformation is invalid: {errorMessage}"); 264 265 var transformedData = trans.Apply(originalData).ToList(); 266 if (modifiableDataset.VariableNames.Contains(transformation.TransformedVariable)) 267 modifiableDataset.ReplaceVariable(transformation.TransformedVariable, transformedData); 268 else 269 modifiableDataset.AddVariable(transformation.TransformedVariable, transformedData); 270 } 271 272 return modifiableDataset; 273 } 274 275 public static IDataset InverseTransform(IDataset dataset, IEnumerable<IDataAnalysisTransformation> transformations) { 276 var modifiableDataset = ((Dataset)dataset).ToModifiable(); 277 278 foreach (var transformation in transformations.Reverse()) { 279 var trans = (ITransformation<double>)transformation.Transformation; 280 281 var transformedData = modifiableDataset.GetDoubleValues(transformation.TransformedVariable); 282 283 var originalData = trans.InverseApply(transformedData).ToList(); 284 modifiableDataset.ReplaceVariable(transformation.OriginalVariable, originalData); 285 } 286 287 return modifiableDataset; 288 } 243 289 } 244 290 } -
branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblemData.cs
r15846 r15847 180 180 base.AdjustProblemDataProperties(problemData); 181 181 } 182 183 public override IDataAnalysisProblemData InverseTransform() { 184 var transformedProblemData = (IRegressionProblemData)base.InverseTransform(); 185 var targetVariable = GetOriginalTragetVariable(TargetVariable, Transformations); 186 transformedProblemData.TargetVariable = targetVariable; 187 return transformedProblemData; 188 } 189 190 public static string GetOriginalTragetVariable(string transformedTarget, IEnumerable<IDataAnalysisTransformation> transformations) { 191 var originalTarget = transformedTarget; 192 foreach (var transformation in transformations.Reverse()) { 193 if (transformation.TransformedVariable == originalTarget) 194 originalTarget = transformation.OriginalVariable; 195 } 196 return originalTarget; 197 } 182 198 } 183 199 } -
branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/TransformedRegressionModel.cs
r15846 r15847 20 20 #endregion 21 21 22 using System;23 22 using System.Collections.Generic; 24 23 using System.Linq; … … 44 43 #region Constructor, Cloning & Persistence 45 44 public TransformedRegressionModel(IRegressionModel originalModel, IEnumerable<IDataAnalysisTransformation> transformations) 46 : base(GetOriginalTragetVariable(originalModel.TargetVariable, transformations)) { 45 : base(RegressionProblemData.GetOriginalTragetVariable(originalModel.TargetVariable, transformations)) { 46 Name = "Transformed " + originalModel.Name; 47 47 OriginalModel = originalModel; 48 48 Transformations = new ItemList<IDataAnalysisTransformation>(transformations); … … 64 64 #endregion 65 65 66 // dataset in original data range 66 67 public override IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) { 67 68 var transformedDataset = TransformInputs(dataset, Transformations); … … 69 70 var estimates = OriginalModel.GetEstimatedValues(transformedDataset, rows); 70 71 71 return TransformEstimates(estimates, Transformations, OriginalModel.TargetVariable);72 return InverseTransformEstimates(estimates, Transformations, OriginalModel.TargetVariable); 72 73 } 73 74 75 // problemData in original data range 74 76 public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) { 75 return new TransformedRegressionSolution(this, new RegressionProblemData(problemData) { TargetVariable = GetOriginalTragetVariable(TargetVariable, Transformations) });77 return new TransformedRegressionSolution(this, new RegressionProblemData(problemData)); 76 78 } 77 79 78 80 private static IDataset TransformInputs(IDataset dataset, IEnumerable<IDataAnalysisTransformation> transformations) { 79 return dataset; 81 return DataAnalysisProblemData.Transform(dataset, transformations); 82 } 80 83 81 var modifiableDataset = ((Dataset)dataset).ToModifiable(); 84 private static IEnumerable<double> InverseTransformEstimates(IEnumerable<double> data, IEnumerable<IDataAnalysisTransformation> transformations, string targetVariable) { 85 var estimates = data.ToList(); 82 86 83 87 foreach (var transformation in transformations.Reverse()) { 84 var trans = (ITransformation<double>)transformation.Transformation; 88 if (transformation.TransformedVariable == targetVariable) { 89 var trans = (ITransformation<double>)transformation.Transformation; 85 90 86 // no transformations on target (but what if target is an input?)91 estimates = trans.InverseApply(estimates).ToList(); 87 92 88 var originalData = modifiableDataset.GetDoubleValues(transformation.OriginalVariable); 89 if (!trans.Check(originalData, out string errorMessage)) 90 throw new InvalidOperationException($"Cannot estimate Values, Transformation is invalid: {errorMessage}"); 91 var transformedData = trans.Apply(originalData).ToList(); 92 93 if (modifiableDataset.VariableNames.Contains(transformation.TransformedVariable)) 94 modifiableDataset.ReplaceVariable(transformation.TransformedVariable, transformedData); 95 else 96 modifiableDataset.AddVariable(transformation.TransformedVariable, transformedData); 93 // setup next iteration 94 targetVariable = transformation.OriginalVariable; 95 } 97 96 } 98 97 99 return modifiableDataset; 100 } 101 102 private static IEnumerable<double> TransformEstimates(IEnumerable<double> data, IEnumerable<IDataAnalysisTransformation> transformations, string targetVariable) { 103 var targetTransformations = transformations.Where(x => x.TransformedVariable == targetVariable); 104 105 var transformedData = data.ToList(); 106 107 foreach (var transformation in targetTransformations.Reverse()) { 108 var trans = (ITransformation<double>)transformation.Transformation; 109 110 if (!trans.Check(transformedData, out string errorMessage)) 111 throw new InvalidOperationException($"Cannot estimate Values, Transformation is invalid: {errorMessage}"); 112 113 transformedData = trans.InverseApply(transformedData).ToList(); 114 } 115 116 return transformedData; 117 } 118 119 public static string GetOriginalTragetVariable(string transformedTarget, IEnumerable<IDataAnalysisTransformation> transformations) { 120 var target = transformedTarget; 121 foreach (var transformation in transformations.Reverse()) { 122 if (transformation.TransformedVariable == target) 123 target = transformation.OriginalVariable; 124 } 125 return target; 98 return estimates; 126 99 } 127 100 } -
branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDataAnalysisProblemData.cs
r15846 r15847 44 44 45 45 IEnumerable<IDataAnalysisTransformation> Transformations { get; } 46 IDataAnalysisProblemData InverseTransform(); 46 47 47 48 bool IsTrainingSample(int index); -
branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDataAnalysisTransformation.cs
r15846 r15847 29 29 30 30 ITransformation Transformation { get; set; } 31 32 31 } 33 32 }
Note: See TracChangeset
for help on using the changeset viewer.