Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/21/14 15:58:40 (11 years ago)
Author:
pfleck
Message:
  • Implemented inverse backtransformation.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/DataPreprocessing/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicExpressionTreeBacktransformator.cs

    r10880 r10883  
    4343
    4444    private void ApplyBacktransformation(ITransformation transformation, ISymbolicExpressionTree symbolicExpressionTree, string targetVariable) {
    45       var variableNodes = symbolicExpressionTree.IterateNodesBreadth()
    46         .OfType<VariableTreeNode>()
    47         .Where(n => n.VariableName == transformation.Column);
     45      if (transformation.Column != targetVariable) {
     46        var variableNodes = symbolicExpressionTree.IterateNodesBreadth()
     47          .OfType<VariableTreeNode>()
     48          .Where(n => n.VariableName == transformation.Column);
     49        ApplyRegularBacktransformation(transformation, variableNodes);
     50      } else {
     51        ApplyInverseBacktransformation(transformation, symbolicExpressionTree);
     52      }
     53    }
    4854
     55    private void ApplyRegularBacktransformation(ITransformation transformation, IEnumerable<VariableTreeNode> variableNodes) {
    4956      foreach (var variableNode in variableNodes) {
    5057        // generate new subtrees because same subtree cannot be added more than once
    5158        var transformationTree = transformationMapper.GenerateModel(transformation);
    52         SwapTransformationWithVariable(transformationTree, variableNode);
     59        SwapVariableWithTree(variableNode, transformationTree);
    5360      }
    5461    }
    5562
    56     private void SwapTransformationWithVariable(ISymbolicExpressionTreeNode transformationTree, VariableTreeNode variableNode) {
     63    private void ApplyInverseBacktransformation(ITransformation transformation, ISymbolicExpressionTree symbolicExpressionTree) {
     64      var startSymbol = symbolicExpressionTree.Root.GetSubtree(0);
     65      var modelTree = startSymbol.GetSubtree(0);
     66      startSymbol.RemoveSubtree(0);
     67
     68      var transformationTree = transformationMapper.GenerateInverseModel(transformation);
     69      var variableNode = transformationTree.IterateNodesBreadth()
     70        .OfType<VariableTreeNode>()
     71        .Single(n => n.VariableName == transformation.Column);
     72
     73      SwapVariableWithTree(variableNode, modelTree);
     74
     75      startSymbol.AddSubtree(transformationTree);
     76    }
     77
     78    private void SwapVariableWithTree(VariableTreeNode variableNode, ISymbolicExpressionTreeNode treeNode) {
    5779      var parent = variableNode.Parent;
    5880      int index = parent.IndexOfSubtree(variableNode);
    5981      parent.RemoveSubtree(index);
    6082
    61       if (!variableNode.Weight.IsAlmost(1.0)) {
    62         transformationTree = CreateNodeFromWeight(transformationTree, variableNode);
    63       }
     83      if (!variableNode.Weight.IsAlmost(1.0))
     84        treeNode = CreateNodeFromWeight(treeNode, variableNode);
    6485
    65       parent.InsertSubtree(index, transformationTree);
     86      parent.InsertSubtree(index, treeNode);
    6687    }
    6788
     
    7091      multiplicationNode.AddSubtree(new ConstantTreeNode(new Constant()) { Value = variableNode.Weight });
    7192      multiplicationNode.AddSubtree(transformationTree);
    72       transformationTree = multiplicationNode;
    73       return transformationTree;
     93      return multiplicationNode;
    7494    }
    7595  }
Note: See TracChangeset for help on using the changeset viewer.