Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10976 for branches


Ignore:
Timestamp:
06/11/14 12:24:37 (10 years ago)
Author:
pfleck
Message:
  • Implemented creation of CopyColumsTransformations when preserving original columns.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/PreprocessingTransformator.cs

    r10948 r10976  
    3333    private readonly IDictionary<string, IList<double>> originalColumns;
    3434
     35    private readonly IDictionary<string, string> renamedColumns;
     36
    3537    public PreprocessingTransformator(IPreprocessingData preprocessingData) {
    3638      this.preprocessingData = (ITransactionalPreprocessingData)preprocessingData;
    3739      originalColumns = new Dictionary<string, IList<double>>();
     40      renamedColumns = new Dictionary<string, string>();
    3841    }
    3942
     
    4245
    4346      preprocessingData.BeginTransaction(DataPreprocessingChangedEventType.Transformation);
     47
    4448      try {
    4549        var doubleTransformations = transformations.OfType<Transformation<double>>().ToList();
    46         ApplyDoubleTranformations(doubleTransformations, preserveColumns, out success, out errorMsg);
    4750
    4851        if (preserveColumns) {
    49           RestorePreservedColumns(doubleTransformations);
     52          PreserveColumns(doubleTransformations);
     53        }
     54
     55        // all transformations are performed inplace. no creation of new columns for transformations
     56        ApplyDoubleTranformationsInplace(doubleTransformations, preserveColumns, out success, out errorMsg);
     57
     58        if (preserveColumns) {
     59          RenameTransformedColumsAndRestorePreservedColumns(doubleTransformations);
     60          RenameTransformationColumnParameter(doubleTransformations);
     61          InsertCopyColumTransformations(doubleTransformations);
     62
    5063          originalColumns.Clear();
     64          renamedColumns.Clear();
    5165        }
    5266      } finally {
     
    5771    }
    5872
    59     private void ApplyDoubleTranformations(IList<Transformation<double>> transformations, bool preserveColumns, out bool success, out string errorMsg) {
     73    private void PreserveColumns(IList<Transformation<double>> transformations) {
     74      foreach (var transformation in transformations) {
     75        if (!originalColumns.ContainsKey(transformation.Column)) {
     76          int colIndex = preprocessingData.GetColumnIndex(transformation.Column);
     77          var originalData = preprocessingData.GetValues<double>(colIndex);
     78          originalColumns.Add(transformation.Column, originalData);
     79        }
     80      }
     81    }
     82
     83    private void ApplyDoubleTranformationsInplace(IList<Transformation<double>> transformations, bool preserveColumns, out bool success, out string errorMsg) {
    6084      errorMsg = string.Empty;
    6185      success = true;
     
    6488
    6589        var originalData = preprocessingData.GetValues<double>(colIndex);
    66 
    67         if (preserveColumns && !originalColumns.ContainsKey(transformation.Column))
    68           originalColumns.Add(transformation.Column, originalData);
    6990
    7091        string errorMsgPart;
     
    84105    }
    85106
    86     private void RestorePreservedColumns(IList<Transformation<double>> transformations) {
     107    private void RenameTransformationColumnParameter(List<Transformation<double>> transformations) {
     108      foreach (var transformation in transformations) {
     109        var newColumnName = new StringValue(renamedColumns[transformation.Column]);
     110        transformation.ColumnParameter.ValidValues.Add(newColumnName);
     111        transformation.ColumnParameter.Value = newColumnName;
     112      }
     113    }
     114
     115    private void InsertCopyColumTransformations(IList<Transformation<double>> transformations) {
     116      foreach (var renaming in renamedColumns) {
     117        string oldName = renaming.Key;
     118        string newName = renaming.Value;
     119
     120        var copyTransformation = CreateCopyTransformation(oldName, newName);
     121        preprocessingData.Transformations.Add(copyTransformation);
     122
     123      }
     124
     125      //var transformedColumns = transformations.Select(x => x.Column).Distinct();
     126      //foreach (var column in transformedColumns) {
     127      //  var copyTransformation = CreateCopyTransformation(column);
     128      //  preprocessingData.Transformations.Add(copyTransformation);
     129      //}
     130    }
     131
     132    private CopyColumnTransformation CreateCopyTransformation(string oldColumn, string newColumn) {
     133      var newColumName = new StringValue(newColumn);
     134
     135      var copyTransformation = new CopyColumnTransformation();
     136      copyTransformation.ColumnParameter.ValidValues.Add(newColumName);
     137      copyTransformation.ColumnParameter.Value = newColumName;
     138
     139      copyTransformation.CopiedColumnNameParameter.Value.Value = oldColumn;
     140      return copyTransformation;
     141    }
     142
     143    private void RenameTransformedColumsAndRestorePreservedColumns(IList<Transformation<double>> transformations) {
    87144      foreach (var column in originalColumns) {
    88145        int originalColumnIndex = preprocessingData.GetColumnIndex(column.Key);
    89146        int newColumnIndex = originalColumnIndex + 1;
    90147        string newColumnName = GetTransformatedColumnName(transformations, column.Key);
    91 
     148        // save renaming mapping
     149        renamedColumns[column.Key] = newColumnName;
    92150        // create new transformed column
    93151        preprocessingData.InsertColumn<double>(newColumnName, newColumnIndex);
Note: See TracChangeset for help on using the changeset viewer.