Changeset 5993
- Timestamp:
- 04/08/11 21:41:53 (14 years ago)
- Location:
- trunk/sources
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views/3.4/InteractiveSymbolicDiscriminantFunctionClassificationSolutionSimplifierView.cs
r5942 r5993 59 59 protected override Dictionary<ISymbolicExpressionTreeNode, double> CalculateReplacementValues(ISymbolicExpressionTree tree) { 60 60 Dictionary<ISymbolicExpressionTreeNode, double> replacementValues = new Dictionary<ISymbolicExpressionTreeNode, double>(); 61 foreach (ISymbolicExpressionTreeNode node in tree.IterateNodesPrefix()) { 62 if (!(node.Symbol is ProgramRootSymbol || node.Symbol is StartSymbol)) { 63 replacementValues[node] = CalculateReplacementValue(node); 64 } 61 foreach (ISymbolicExpressionTreeNode node in tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix()) { 62 replacementValues[node] = CalculateReplacementValue(node, tree); 65 63 } 66 64 return replacementValues; … … 90 88 foreach (ISymbolicExpressionTreeNode node in nodes) { 91 89 var parent = node.Parent; 92 constantNode.Value = CalculateReplacementValue(node );90 constantNode.Value = CalculateReplacementValue(node, tree); 93 91 ISymbolicExpressionTreeNode replacementNode = constantNode; 94 92 SwitchNode(parent, node, replacementNode); … … 111 109 } 112 110 113 private double CalculateReplacementValue(ISymbolicExpressionTreeNode node) { 111 private double CalculateReplacementValue(ISymbolicExpressionTreeNode node, ISymbolicExpressionTree sourceTree) { 112 // remove old ADFs 113 while (tempTree.Root.SubtreesCount > 1) tempTree.Root.RemoveSubtree(1); 114 // clone ADFs of source tree 115 for (int i = 1; i < sourceTree.Root.SubtreesCount; i++) { 116 tempTree.Root.AddSubtree((ISymbolicExpressionTreeNode)sourceTree.Root.GetSubtree(i).Clone()); 117 } 114 118 var start = tempTree.Root.GetSubtree(0); 115 119 while (start.SubtreesCount > 0) start.RemoveSubtree(0); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/InteractiveSymbolicRegressionSolutionSimplifierView.cs
r5942 r5993 60 60 protected override Dictionary<ISymbolicExpressionTreeNode, double> CalculateReplacementValues(ISymbolicExpressionTree tree) { 61 61 Dictionary<ISymbolicExpressionTreeNode, double> replacementValues = new Dictionary<ISymbolicExpressionTreeNode, double>(); 62 foreach (ISymbolicExpressionTreeNode node in tree.IterateNodesPrefix()) { 63 if (!(node.Symbol is ProgramRootSymbol || node.Symbol is StartSymbol)) { 64 replacementValues[node] = CalculateReplacementValue(node); 65 } 62 foreach (ISymbolicExpressionTreeNode node in tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix()) { 63 replacementValues[node] = CalculateReplacementValue(node, tree); 66 64 } 67 65 return replacementValues; … … 84 82 foreach (ISymbolicExpressionTreeNode node in nodes) { 85 83 var parent = node.Parent; 86 constantNode.Value = CalculateReplacementValue(node );84 constantNode.Value = CalculateReplacementValue(node, tree); 87 85 ISymbolicExpressionTreeNode replacementNode = constantNode; 88 86 SwitchNode(parent, node, replacementNode); … … 100 98 } 101 99 102 private double CalculateReplacementValue(ISymbolicExpressionTreeNode node) { 100 private double CalculateReplacementValue(ISymbolicExpressionTreeNode node, ISymbolicExpressionTree sourceTree) { 101 // remove old ADFs 102 while (tempTree.Root.SubtreesCount > 1) tempTree.Root.RemoveSubtree(1); 103 // clone ADFs of source tree 104 for (int i = 1; i < sourceTree.Root.SubtreesCount; i++) { 105 tempTree.Root.AddSubtree((ISymbolicExpressionTreeNode)sourceTree.Root.GetSubtree(i).Clone()); 106 } 103 107 var start = tempTree.Root.GetSubtree(0); 104 108 while (start.SubtreesCount > 0) start.RemoveSubtree(0); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs
r5809 r5993 96 96 for (int subTreeIndex = 0; subTreeIndex < parent.SubtreesCount; subTreeIndex++) { 97 97 var child = parent.GetSubtree(subTreeIndex); 98 if (!(child.Symbol is Constant) && nodeImpacts[child].IsAlmost( 1.0)) {98 if (!(child.Symbol is Constant) && nodeImpacts[child].IsAlmost(0.0)) { 99 99 SwitchNodeWithReplacementNode(parent, subTreeIndex); 100 100 } 101 101 } 102 102 } 103 // show only interesting part of solution 104 this.treeChart.Tree = new SymbolicExpressionTree(tree.Root.GetSubtree(0).GetSubtree(0)); 103 // show only interesting part of solution 104 if (tree.Root.SubtreesCount > 1) 105 this.treeChart.Tree = new SymbolicExpressionTree(tree.Root); // RPB + ADFs 106 else 107 this.treeChart.Tree = new SymbolicExpressionTree(tree.Root.GetSubtree(0).GetSubtree(0)); // 1st child of RPB 105 108 this.PaintNodeImpacts(); 106 109 } … … 126 129 for (int i = 0; i < treeNode.SubtreesCount; i++) { 127 130 ISymbolicExpressionTreeNode subTree = treeNode.GetSubtree(i); 128 if (subTree == visualTreeNode.SymbolicExpressionTreeNode) { 131 // only allow to replace nodes for which a replacement value is known (replacement value for ADF nodes are not available) 132 if (subTree == visualTreeNode.SymbolicExpressionTreeNode && replacementNodes.ContainsKey(subTree)) { 133 double replacementImpact = nodeImpacts.ContainsKey(replacementNodes[subTree]) ? nodeImpacts[replacementNodes[subTree]] : 0.0; 134 double originalImpact = nodeImpacts.ContainsKey(subTree) ? nodeImpacts[subTree] : 0.0; 129 135 SwitchNodeWithReplacementNode(treeNode, i); 130 } 131 } 132 } 133 134 // show only interesting part of solution 135 this.treeChart.Tree = new SymbolicExpressionTree(tree.Root.GetSubtree(0).GetSubtree(0)); 136 137 UpdateModel(tree); 136 137 // show only interesting part of solution 138 if (tree.Root.SubtreesCount > 1) 139 this.treeChart.Tree = new SymbolicExpressionTree(tree.Root); // RPB + ADFs 140 else 141 this.treeChart.Tree = new SymbolicExpressionTree(tree.Root.GetSubtree(0).GetSubtree(0)); // 1st child of RPB 142 if (!(originalImpact.IsAlmost(0.0) && replacementImpact.IsAlmost(0.0))) { 143 // update everything after the change if necessary (impact != 0) 144 UpdateModel(tree); 145 } else { 146 // both impacts are zero, so we only need to repaint the nodes 147 PaintNodeImpacts(); 148 } 149 return; // break all loops 150 } 151 } 152 } 138 153 } 139 154 … … 176 191 visualTree.ToolTip += Environment.NewLine + "Replacement value: " + constantReplacementNode.Value; 177 192 } 178 } 193 } 179 194 } 180 195 this.PaintCollapsedNodes();
Note: See TracChangeset
for help on using the changeset viewer.