Changeset 10883
- Timestamp:
- 05/21/14 15:58:40 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataPreprocessing/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicExpressionTreeBacktransformator.cs
r10880 r10883 43 43 44 44 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 } 48 54 55 private void ApplyRegularBacktransformation(ITransformation transformation, IEnumerable<VariableTreeNode> variableNodes) { 49 56 foreach (var variableNode in variableNodes) { 50 57 // generate new subtrees because same subtree cannot be added more than once 51 58 var transformationTree = transformationMapper.GenerateModel(transformation); 52 Swap TransformationWithVariable(transformationTree, variableNode);59 SwapVariableWithTree(variableNode, transformationTree); 53 60 } 54 61 } 55 62 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) { 57 79 var parent = variableNode.Parent; 58 80 int index = parent.IndexOfSubtree(variableNode); 59 81 parent.RemoveSubtree(index); 60 82 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); 64 85 65 parent.InsertSubtree(index, tr ansformationTree);86 parent.InsertSubtree(index, treeNode); 66 87 } 67 88 … … 70 91 multiplicationNode.AddSubtree(new ConstantTreeNode(new Constant()) { Value = variableNode.Weight }); 71 92 multiplicationNode.AddSubtree(transformationTree); 72 transformationTree = multiplicationNode; 73 return transformationTree; 93 return multiplicationNode; 74 94 } 75 95 }
Note: See TracChangeset
for help on using the changeset viewer.