Changeset 10874


Ignore:
Timestamp:
05/21/14 13:15:53 (5 years ago)
Author:
pfleck
Message:
  • convert variable weights into multiplication nodes for backtransformation
File:
1 edited

Legend:

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

    r10872 r10874  
    4343    private void ApplyBacktransformation(ITransformation transformation, ISymbolicExpressionTree symbolicExpressionTree) {
    4444      var variableNodes = symbolicExpressionTree.IterateNodesBreadth()
    45         .Where(n => IsVariableNode(n, transformation.Column));
     45        .OfType<VariableTreeNode>()
     46        .Where(n => n.VariableName == transformation.Column);
    4647
    4748      var transformationTree = transformationMapper.GenerateModel(transformation);
    4849      foreach (var variableNode in variableNodes) {
    49         SwapTransformationTree(transformationTree, variableNode);
     50        SwapTransformationWithVariable(transformationTree, variableNode);
    5051      }
    5152    }
    5253
    53     private void SwapTransformationTree(ISymbolicExpressionTreeNode transformationTreeNode, ISymbolicExpressionTreeNode targetNode) {
    54       var parent = targetNode.Parent;
    55       int index = parent.IndexOfSubtree(targetNode);
     54    private void SwapTransformationWithVariable(ISymbolicExpressionTreeNode transformationTree, VariableTreeNode variableNode) {
     55      var parent = variableNode.Parent;
     56      int index = parent.IndexOfSubtree(variableNode);
    5657      parent.RemoveSubtree(index);
    57       parent.InsertSubtree(index, transformationTreeNode);
    58     }
    5958
    60     private bool IsVariableNode(ISymbolicExpressionTreeNode node, string variableName) {
    61       var variableNode = node as VariableTreeNode;
    62       if (variableNode == null) return false;
    63       return variableNode.VariableName == variableName;
     59      var multiplicationNode = new SymbolicExpressionTreeNode(new Multiplication());
     60      multiplicationNode.AddSubtree(new ConstantTreeNode(new Constant()) { Value = variableNode.Weight });
     61      multiplicationNode.AddSubtree(transformationTree);
     62
     63      parent.InsertSubtree(index, multiplicationNode);
    6464    }
    6565  }
Note: See TracChangeset for help on using the changeset viewer.