Changeset 4462
- Timestamp:
- 09/21/10 14:18:06 (14 years ago)
- Location:
- branches/DataAnalysis
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.Views/3.3/Symbolic/InteractiveSymbolicRegressionSolutionSimplifierView.cs
r4068 r4462 83 83 SymbolicSimplifier simplifier = new SymbolicSimplifier(); 84 84 simplifiedExpressionTree = simplifier.Simplify(Content.Model.SymbolicExpressionTree); 85 SymbolicExpressionTreeNode root = new ProgramRootSymbol().CreateTreeNode();86 SymbolicExpressionTreeNode start = new StartSymbol().CreateTreeNode();87 root.AddSubTree(start);88 start.AddSubTree(simplifiedExpressionTree.Root);89 85 int samplesStart = Content.ProblemData.TrainingSamplesStart.Value; 90 86 int samplesEnd = Content.ProblemData.TrainingSamplesEnd.Value; 87 SymbolicExpressionTree tree = (SymbolicExpressionTree)simplifiedExpressionTree.Clone(); 91 88 double originalTrainingMeanSquaredError = SymbolicRegressionMeanSquaredErrorEvaluator.Calculate( 92 Content.Model.Interpreter, new SymbolicExpressionTree(root), Content.LowerEstimationLimit, Content.UpperEstimationLimit,89 Content.Model.Interpreter, tree, Content.LowerEstimationLimit, Content.UpperEstimationLimit, 93 90 Content.ProblemData.Dataset, Content.ProblemData.TargetVariable.Value, 94 91 Enumerable.Range(samplesStart, samplesEnd - samplesStart)); … … 96 93 this.CalculateReplacementNodes(); 97 94 98 this.CalculateNodeImpacts( new SymbolicExpressionTree(root), start, originalTrainingMeanSquaredError);99 this.treeChart.Tree = simplifiedExpressionTree;95 this.CalculateNodeImpacts(tree, tree.Root.SubTrees[0], originalTrainingMeanSquaredError); 96 this.treeChart.Tree = new SymbolicExpressionTree(simplifiedExpressionTree.Root.SubTrees[0].SubTrees[0]); 100 97 this.PaintNodeImpacts(); 101 98 } … … 110 107 SymbolicExpressionTree tree = new SymbolicExpressionTree(root); 111 108 foreach (SymbolicExpressionTreeNode node in this.simplifiedExpressionTree.IterateNodesPrefix()) { 112 while (start.SubTrees.Count > 0) start.RemoveSubTree(0); 113 start.AddSubTree(node); 114 double constantTreeNodeValue = interpreter.GetSymbolicExpressionTreeValues(tree, Content.ProblemData.Dataset, trainingSamples).Median(); 115 ConstantTreeNode constantTreeNode = MakeConstantTreeNode(constantTreeNodeValue); 116 replacementNodes[node] = constantTreeNode; 109 if (!(node.Symbol is ProgramRootSymbol || node.Symbol is StartSymbol)) { 110 while (start.SubTrees.Count > 0) start.RemoveSubTree(0); 111 start.AddSubTree(node); 112 double constantTreeNodeValue = interpreter.GetSymbolicExpressionTreeValues(tree, Content.ProblemData.Dataset, trainingSamples).Median(); 113 ConstantTreeNode constantTreeNode = MakeConstantTreeNode(constantTreeNodeValue); 114 replacementNodes[node] = constantTreeNode; 115 } 117 116 } 118 117 } … … 169 168 } 170 169 } 171 this.treeChart.Tree = simplifiedExpressionTree; 172 173 SymbolicExpressionTreeNode root = new ProgramRootSymbol().CreateTreeNode(); 174 SymbolicExpressionTreeNode start = new StartSymbol().CreateTreeNode(); 175 root.AddSubTree(start); 176 SymbolicExpressionTree tree = new SymbolicExpressionTree(root); 177 start.AddSubTree(simplifiedExpressionTree.Root); 170 this.treeChart.Tree = new SymbolicExpressionTree(simplifiedExpressionTree.Root.SubTrees[0].SubTrees[0]); 171 172 SymbolicExpressionTree tree = (SymbolicExpressionTree)simplifiedExpressionTree.Clone(); 178 173 179 174 this.Content.ModelChanged -= new EventHandler(Content_ModelChanged); … … 189 184 double min = impacts.Min(); 190 185 foreach (SymbolicExpressionTreeNode treeNode in simplifiedExpressionTree.IterateNodesPostfix()) { 191 if (!(treeNode is ConstantTreeNode) ) {186 if (!(treeNode is ConstantTreeNode) && nodeImpacts.ContainsKey(treeNode)) { 192 187 double impact = this.nodeImpacts[treeNode]; 193 188 double replacementValue = this.replacementNodes[treeNode].Value; -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/SymbolicSimplifier.cs
r4389 r4462 44 44 // macro expand (initially no argument trees) 45 45 var macroExpandedTree = MacroExpand(clone, clone.SubTrees[0], new List<SymbolicExpressionTreeNode>()); 46 return new SymbolicExpressionTree(GetSimplifiedTree(macroExpandedTree)); 46 SymbolicExpressionTreeNode rootNode = (new ProgramRootSymbol()).CreateTreeNode(); 47 rootNode.AddSubTree(GetSimplifiedTree(macroExpandedTree)); 48 return new SymbolicExpressionTree(rootNode); 47 49 } 48 50 … … 63 65 // return the correct argument sub-tree (already macro-expanded) 64 66 return (SymbolicExpressionTreeNode)argumentTrees[argSym.ArgumentIndex].Clone(); 65 } else if (node.Symbol is StartSymbol) {66 return MacroExpand(root, subtrees[0], argumentTrees);67 67 } else { 68 68 // recursive application
Note: See TracChangeset
for help on using the changeset viewer.