Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/04/18 17:18:02 (5 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.
File:
1 edited

Legend:

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

    r15879 r15884  
    241241      }
    242242    }
    243 
    244     public virtual IDataAnalysisProblemData Transform() {
    245       var newDataset = DataAnalysisTransformationModel.Transform(Dataset, Transformations);
    246 
    247       var extendedInputs = DataAnalysisTransformationModel.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));
    250 
    251       // TODO: Cannot create concrete instance here (maybe derived Create-method?)
    252       var cloner = new Cloner();
    253       cloner.RegisterClonedObject(Dataset, newDataset);
    254       cloner.RegisterClonedObject(InputVariables, checkedInputs.AsReadOnly());
    255       // TODO: valid values for target are not extended
    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       // TODO: check valid target values
    271 
    272       return cloner.Clone(this);
    273     }
    274 
    275     public static IDataset InverseTransform(IDataset dataset, IEnumerable<IDataAnalysisTransformation> transformations, bool removeVirtualVariables = true) {
    276       var modifiableDataset = ((Dataset)dataset).ToModifiable();
    277 
    278       var transformationsStack = new Stack<IDataAnalysisTransformation>(transformations);
    279       while (transformationsStack.Any()) {
    280         var transformation = transformationsStack.Pop();
    281         var trans = (ITransformation<double>)transformation.Transformation;
    282 
    283         var prevTransformations = transformations.Except(transformationsStack);
    284         bool originalWasChanged = prevTransformations.Any(x => x.TransformedVariable == transformation.OriginalVariable);
    285         if (originalWasChanged) {
    286           var transformedData = modifiableDataset.GetDoubleValues(transformation.TransformedVariable);
    287 
    288           var originalData = trans.InverseApply(transformedData).ToList();
    289           modifiableDataset.ReplaceVariable(transformation.OriginalVariable, originalData);
    290         }
    291 
    292         bool transformedVariablePending = transformationsStack.Any(x => x.OriginalVariable == transformation.TransformedVariable || x.TransformedVariable == transformation.TransformedVariable);
    293         if (removeVirtualVariables && !transformedVariablePending)
    294           modifiableDataset.RemoveVariable(transformation.TransformedVariable);
    295       }
    296 
    297       return modifiableDataset;
    298     }
    299243  }
    300244}
Note: See TracChangeset for help on using the changeset viewer.