Changeset 5733
- Timestamp:
- 03/17/11 14:07:47 (14 years ago)
- Location:
- branches/DataAnalysis Refactoring
- Files:
-
- 3 deleted
- 43 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis Refactoring/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/LinearDiscriminantAnalysis.cs
r5681 r5733 90 90 ISymbolicExpressionTree tree = new SymbolicExpressionTree(new ProgramRootSymbol().CreateTreeNode()); 91 91 ISymbolicExpressionTreeNode startNode = new StartSymbol().CreateTreeNode(); 92 tree.Root.AddSub Tree(startNode);92 tree.Root.AddSubtree(startNode); 93 93 ISymbolicExpressionTreeNode addition = new Addition().CreateTreeNode(); 94 startNode.AddSub Tree(addition);94 startNode.AddSubtree(addition); 95 95 96 96 int col = 0; … … 99 99 vNode.VariableName = column; 100 100 vNode.Weight = w[col]; 101 addition.AddSub Tree(vNode);101 addition.AddSubtree(vNode); 102 102 col++; 103 103 } … … 105 105 ConstantTreeNode cNode = (ConstantTreeNode)new Constant().CreateTreeNode(); 106 106 cNode.Value = w[w.Length - 1]; 107 addition.AddSub Tree(cNode);107 addition.AddSubtree(cNode); 108 108 109 109 -
branches/DataAnalysis Refactoring/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/LinearRegression.cs
r5658 r5733 94 94 ISymbolicExpressionTree tree = new SymbolicExpressionTree(new ProgramRootSymbol().CreateTreeNode()); 95 95 ISymbolicExpressionTreeNode startNode = new StartSymbol().CreateTreeNode(); 96 tree.Root.AddSub Tree(startNode);96 tree.Root.AddSubtree(startNode); 97 97 ISymbolicExpressionTreeNode addition = new Addition().CreateTreeNode(); 98 startNode.AddSub Tree(addition);98 startNode.AddSubtree(addition); 99 99 100 100 int col = 0; … … 103 103 vNode.VariableName = column; 104 104 vNode.Weight = coefficients[col]; 105 addition.AddSub Tree(vNode);105 addition.AddSubtree(vNode); 106 106 col++; 107 107 } … … 109 109 ConstantTreeNode cNode = (ConstantTreeNode)new Constant().CreateTreeNode(); 110 110 cNode.Value = coefficients[coefficients.Length - 1]; 111 addition.AddSub Tree(cNode);111 addition.AddSubtree(cNode); 112 112 113 113 SymbolicRegressionSolution solution = new SymbolicRegressionSolution(new SymbolicRegressionModel(tree, new SymbolicDataAnalysisExpressionTreeInterpreter()), problemData); -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeChart.cs
r5549 r5733 263 263 264 264 //draw terminal node 265 if (node.Sub Trees.Count() == 0) {265 if (node.Subtrees.Count() == 0) { 266 266 graphics.FillRectangle(nodeFillBrush, visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height); 267 267 graphics.DrawRectangle(nodeLinePen, visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height); … … 281 281 //calculate areas for the subtrees according to their tree size and call drawFunctionTree 282 282 Point connectFrom = new Point(visualTreeNode.X + visualTreeNode.Width / 2, visualTreeNode.Y + visualTreeNode.Height); 283 int[] xBoundaries = new int[node.Sub Trees.Count() + 1];283 int[] xBoundaries = new int[node.Subtrees.Count() + 1]; 284 284 xBoundaries[0] = x; 285 for (int i = 0; i < node.Sub Trees.Count(); i++) {286 xBoundaries[i + 1] = (int)(xBoundaries[i] + (width * (double)node.Sub Trees.ElementAt(i).GetLength()) / (node.GetLength() - 1));287 DrawFunctionTree(node.Sub Trees.ElementAt(i), graphics, xBoundaries[i], y + height,285 for (int i = 0; i < node.Subtrees.Count(); i++) { 286 xBoundaries[i + 1] = (int)(xBoundaries[i] + (width * (double)node.Subtrees.ElementAt(i).GetLength()) / (node.GetLength() - 1)); 287 DrawFunctionTree(node.Subtrees.ElementAt(i), graphics, xBoundaries[i], y + height, 288 288 xBoundaries[i + 1] - xBoundaries[i], height, connectFrom); 289 289 } -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/ArgumentCreater.cs
r5686 r5733 124 124 // the branch at the cut point is to be replaced by a new argument node 125 125 var cutPoints = (from node in defunBranch.IterateNodesPrefix() 126 where node.Sub Trees.Count() > 0127 from subtree in node.Sub Trees126 where node.Subtrees.Count() > 0 127 from subtree in node.Subtrees 128 128 select new CutPoint(node, subtree)).ToList(); 129 129 … … 134 134 // replace the branch at the cut point with an argument node 135 135 var replacedBranch = selectedCutPoint.Child; 136 selectedCutPoint.Parent.RemoveSub Tree(selectedCutPoint.ChildIndex);137 selectedCutPoint.Parent.InsertSub Tree(selectedCutPoint.ChildIndex, newArgumentNode);136 selectedCutPoint.Parent.RemoveSubtree(selectedCutPoint.ChildIndex); 137 selectedCutPoint.Parent.InsertSubtree(selectedCutPoint.ChildIndex, newArgumentNode); 138 138 139 139 // find all old invocations of the selected ADF and attach a cloned version of the replaced branch (with all argument-nodes expanded) … … 141 141 var invocationNodes = (from node in tree.IterateNodesPostfix().OfType<InvokeFunctionTreeNode>() 142 142 where node.Symbol.FunctionName == defunBranch.FunctionName 143 where node.Sub Trees.Count() == defunBranch.NumberOfArguments143 where node.Subtrees.Count() == defunBranch.NumberOfArguments 144 144 select node).ToList(); 145 145 // do this repeatedly until no matching invocations are found … … 148 148 foreach (var invocationNode in invocationNodes) { 149 149 // check that the invocation node really has the correct number of arguments 150 if (invocationNode.Sub Trees.Count() != defunBranch.NumberOfArguments) throw new InvalidOperationException();150 if (invocationNode.Subtrees.Count() != defunBranch.NumberOfArguments) throw new InvalidOperationException(); 151 151 // append a new argument branch after expanding all argument nodes 152 152 var clonedBranch = (ISymbolicExpressionTreeNode)replacedBranch.Clone(); 153 clonedBranch = ReplaceArgumentsInBranch(clonedBranch, invocationNode.Sub Trees);154 invocationNode.InsertSub Tree(newArgumentNode.Symbol.ArgumentIndex, clonedBranch);153 clonedBranch = ReplaceArgumentsInBranch(clonedBranch, invocationNode.Subtrees); 154 invocationNode.InsertSubtree(newArgumentNode.Symbol.ArgumentIndex, clonedBranch); 155 155 newlyAddedBranches.Add(clonedBranch); 156 156 } … … 159 159 from node in newlyAddedBranch.IterateNodesPostfix().OfType<InvokeFunctionTreeNode>() 160 160 where node.Symbol.FunctionName == defunBranch.FunctionName 161 where node.Sub Trees.Count() == defunBranch.NumberOfArguments161 where node.Subtrees.Count() == defunBranch.NumberOfArguments 162 162 select node).ToList(); 163 163 } … … 173 173 defunBranch.Grammar.AddAllowedChildSymbol(symb, newArgumentNode.Symbol, i); 174 174 } 175 foreach (var subtree in tree.Root.Sub Trees) {175 foreach (var subtree in tree.Root.Subtrees) { 176 176 // when the changed function is known in the branch then update the number of arguments 177 177 var matchingSymbol = subtree.Grammar.Symbols.OfType<InvokeFunction>().Where(s => s.FunctionName == defunBranch.FunctionName).SingleOrDefault(); … … 196 196 } else { 197 197 // call recursively for all subtree 198 List<ISymbolicExpressionTreeNode> subtrees = new List<ISymbolicExpressionTreeNode>(branch.Sub Trees);199 while (branch.Sub Trees.Count() > 0) branch.RemoveSubTree(0);198 List<ISymbolicExpressionTreeNode> subtrees = new List<ISymbolicExpressionTreeNode>(branch.Subtrees); 199 while (branch.Subtrees.Count() > 0) branch.RemoveSubtree(0); 200 200 foreach (var subtree in subtrees) { 201 branch.AddSub Tree(ReplaceArgumentsInBranch(subtree, argumentTrees));201 branch.AddSubtree(ReplaceArgumentsInBranch(subtree, argumentTrees)); 202 202 } 203 203 return branch; -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/ArgumentDeleter.cs
r5686 r5733 71 71 select node).ToList(); 72 72 foreach (var invokeNode in invocationNodes) { 73 invokeNode.RemoveSub Tree(removedArgument);73 invokeNode.RemoveSubtree(removedArgument); 74 74 } 75 75 … … 81 81 selectedDefunBranch.NumberOfArguments--; 82 82 // reduce arity in known functions of all root branches 83 foreach (var subtree in symbolicExpressionTree.Root.Sub Trees) {83 foreach (var subtree in symbolicExpressionTree.Root.Subtrees) { 84 84 var matchingInvokeSymbol = subtree.Grammar.Symbols.OfType<InvokeFunction>().Where(s => s.FunctionName == selectedDefunBranch.FunctionName).SingleOrDefault(); 85 85 if (matchingInvokeSymbol != null) { -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/ArgumentDuplicater.cs
r5686 r5733 86 86 var invocationNodes = (from node in symbolicExpressionTree.IterateNodesPrefix().OfType<InvokeFunctionTreeNode>() 87 87 where node.Symbol.FunctionName == selectedDefunBranch.FunctionName 88 where node.Sub Trees.Count() == selectedDefunBranch.NumberOfArguments88 where node.Subtrees.Count() == selectedDefunBranch.NumberOfArguments 89 89 select node).ToList(); 90 90 // do this repeatedly until no matching invocations are found … … 93 93 foreach (var invokeNode in invocationNodes) { 94 94 // check that the invocation node really has the correct number of arguments 95 if (invokeNode.Sub Trees.Count() != selectedDefunBranch.NumberOfArguments) throw new InvalidOperationException();96 var argumentBranch = invokeNode.GetSub Tree(selectedArgumentSymbol.ArgumentIndex);95 if (invokeNode.Subtrees.Count() != selectedDefunBranch.NumberOfArguments) throw new InvalidOperationException(); 96 var argumentBranch = invokeNode.GetSubtree(selectedArgumentSymbol.ArgumentIndex); 97 97 var clonedArgumentBranch = (ISymbolicExpressionTreeNode)argumentBranch.Clone(); 98 invokeNode.InsertSub Tree(newArgumentIndex, clonedArgumentBranch);98 invokeNode.InsertSubtree(newArgumentIndex, clonedArgumentBranch); 99 99 newlyAddedBranches.Add(clonedArgumentBranch); 100 100 } … … 102 102 from node in newlyAddedBranch.IterateNodesPrefix().OfType<InvokeFunctionTreeNode>() 103 103 where node.Symbol.FunctionName == selectedDefunBranch.FunctionName 104 where node.Sub Trees.Count() == selectedDefunBranch.NumberOfArguments104 where node.Subtrees.Count() == selectedDefunBranch.NumberOfArguments 105 105 select node).ToList(); 106 106 } … … 116 116 117 117 // increase the arity of the changed ADF in all branches that can use this ADF 118 foreach (var subtree in symbolicExpressionTree.Root.Sub Trees) {118 foreach (var subtree in symbolicExpressionTree.Root.Subtrees) { 119 119 var matchingInvokeSymbol = (from symb in subtree.Grammar.Symbols.OfType<InvokeFunction>() 120 120 where symb.FunctionName == selectedDefunBranch.FunctionName -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/SubroutineCreater.cs
r5686 r5733 95 95 96 96 // select a random body (either the result producing branch or an ADF branch) 97 var bodies = from node in symbolicExpressionTree.Root.Sub Trees97 var bodies = from node in symbolicExpressionTree.Root.Subtrees 98 98 select new { Tree = node, Length = node.GetLength() }; 99 99 var totalNumberOfBodyNodes = bodies.Select(x => x.Length).Sum(); … … 111 111 // select a random cut point in the selected branch 112 112 var allCutPoints = (from parent in selectedBody.IterateNodesPrefix() 113 from subtree in parent.Sub Trees113 from subtree in parent.Subtrees 114 114 select new CutPoint(parent, subtree)).ToList(); 115 115 if (allCutPoints.Count() == 0) … … 122 122 ISymbolicExpressionTreeNode functionBody = selectedCutPoint.Child; 123 123 // disconnect the function body from the tree 124 selectedCutPoint.Parent.RemoveSub Tree(selectedCutPoint.ChildIndex);124 selectedCutPoint.Parent.RemoveSubtree(selectedCutPoint.ChildIndex); 125 125 // disconnect the argument branches from the function 126 126 functionBody = DisconnectBranches(functionBody, argumentCutPoints); 127 127 // insert a function invocation symbol instead 128 128 var invokeNode = (InvokeFunctionTreeNode)(new InvokeFunction(newFunctionName)).CreateTreeNode(); 129 selectedCutPoint.Parent.InsertSub Tree(selectedCutPoint.ChildIndex, invokeNode);129 selectedCutPoint.Parent.InsertSubtree(selectedCutPoint.ChildIndex, invokeNode); 130 130 // add the branches selected as argument as subtrees of the function invocation node 131 131 foreach (var argumentCutPoint in argumentCutPoints) 132 invokeNode.AddSub Tree(argumentCutPoint.Child);132 invokeNode.AddSubtree(argumentCutPoint.Child); 133 133 134 134 // insert a new function defining branch 135 135 var defunNode = (DefunTreeNode)(new Defun()).CreateTreeNode(); 136 136 defunNode.FunctionName = newFunctionName; 137 defunNode.AddSub Tree(functionBody);138 symbolicExpressionTree.Root.AddSub Tree(defunNode);137 defunNode.AddSubtree(functionBody); 138 symbolicExpressionTree.Root.AddSubtree(defunNode); 139 139 // the grammar in the newly defined function is a clone of the grammar of the originating branch 140 140 defunNode.SetGrammar((ISymbolicExpressionTreeGrammar)selectedBody.Grammar.Clone()); … … 157 157 if (selectedBody.Symbol is Defun) { 158 158 var originalFunctionDefinition = selectedBody as DefunTreeNode; 159 foreach (var subtree in symbolicExpressionTree.Root.Sub Trees) {159 foreach (var subtree in symbolicExpressionTree.Root.Subtrees) { 160 160 var originalBranchInvokeSymbol = (from symb in subtree.Grammar.Symbols.OfType<InvokeFunction>() 161 161 where symb.FunctionName == originalFunctionDefinition.FunctionName … … 177 177 } 178 178 // remove the subtrees so that we can clone only the root node 179 List<ISymbolicExpressionTreeNode> subtrees = new List<ISymbolicExpressionTreeNode>(node.Sub Trees);180 while (node.Sub Trees.Count() > 0) node.RemoveSubTree(0);179 List<ISymbolicExpressionTreeNode> subtrees = new List<ISymbolicExpressionTreeNode>(node.Subtrees); 180 while (node.Subtrees.Count() > 0) node.RemoveSubtree(0); 181 181 // recursively apply function for subtrees or append a argument terminal node 182 182 foreach (var subtree in subtrees) { 183 node.AddSub Tree(DisconnectBranches(subtree, argumentCutPoints));183 node.AddSubtree(DisconnectBranches(subtree, argumentCutPoints)); 184 184 } 185 185 return node; … … 198 198 } else { 199 199 // get the number of argument nodes (which must be cut-off) in the sub-trees 200 var numberOfArgumentsInSubtrees = (from subtree in selectedRoot.Sub Trees200 var numberOfArgumentsInSubtrees = (from subtree in selectedRoot.Subtrees 201 201 let nArgumentsInTree = subtree.IterateNodesPrefix().OfType<ArgumentTreeNode>().Count() 202 202 select nArgumentsInTree).ToList(); … … 209 209 } 210 210 // cut-off in the sub-trees in random order 211 var randomIndexes = (from index in Enumerable.Range(0, selectedRoot.Sub Trees.Count())211 var randomIndexes = (from index in Enumerable.Range(0, selectedRoot.Subtrees.Count()) 212 212 select new { Index = index, OrderValue = random.NextDouble() }) 213 213 .OrderBy(x => x.OrderValue) 214 214 .Select(x => x.Index); 215 215 foreach (var subtreeIndex in randomIndexes) { 216 var subtree = selectedRoot.GetSub Tree(subtreeIndex);216 var subtree = selectedRoot.GetSubtree(subtreeIndex); 217 217 minNewArgumentsForSubtrees[subtreeIndex] = 0; 218 218 // => cut-off at 0..n points somewhere in the current sub-tree -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/SubroutineDeleter.cs
r5686 r5733 62 62 var selectedDefunBranch = functionDefiningBranches.SelectRandom(random); 63 63 // remove the selected defun 64 int defunSubtreeIndex = symbolicExpressionTree.Root.IndexOfSub Tree(selectedDefunBranch);65 symbolicExpressionTree.Root.RemoveSub Tree(defunSubtreeIndex);64 int defunSubtreeIndex = symbolicExpressionTree.Root.IndexOfSubtree(selectedDefunBranch); 65 symbolicExpressionTree.Root.RemoveSubtree(defunSubtreeIndex); 66 66 67 67 // remove references to deleted function 68 foreach (var subtree in symbolicExpressionTree.Root.Sub Trees.OfType<SymbolicExpressionTreeTopLevelNode>()) {68 foreach (var subtree in symbolicExpressionTree.Root.Subtrees.OfType<SymbolicExpressionTreeTopLevelNode>()) { 69 69 var matchingInvokeSymbol = (from symb in subtree.Grammar.Symbols.OfType<InvokeFunction>() 70 70 where symb.FunctionName == selectedDefunBranch.FunctionName … … 84 84 // the invocations below it are removed already 85 85 var invocationCutPoint = (from node in symbolicExpressionTree.IterateNodesPrefix() 86 from subtree in node.Sub Trees.OfType<InvokeFunctionTreeNode>()86 from subtree in node.Subtrees.OfType<InvokeFunctionTreeNode>() 87 87 where subtree.Symbol.FunctionName == selectedDefunBranch.FunctionName 88 88 select new CutPoint(node, subtree)).FirstOrDefault(); … … 101 101 if (replacementTree.HasLocalParameters) 102 102 replacementTree.ResetLocalParameters(random); 103 invocationCutPoint.Parent.RemoveSub Tree(invocationCutPoint.ChildIndex);104 invocationCutPoint.Parent.InsertSub Tree(invocationCutPoint.ChildIndex, replacementTree);103 invocationCutPoint.Parent.RemoveSubtree(invocationCutPoint.ChildIndex); 104 invocationCutPoint.Parent.InsertSubtree(invocationCutPoint.ChildIndex, replacementTree); 105 105 106 106 ProbabilisticTreeCreator.PTC2(random, replacementTree, maxLength, maxDepth); 107 107 108 108 invocationCutPoint = (from node in symbolicExpressionTree.IterateNodesPrefix() 109 from subtree in node.Sub Trees.OfType<InvokeFunctionTreeNode>()109 from subtree in node.Subtrees.OfType<InvokeFunctionTreeNode>() 110 110 where subtree.Symbol.FunctionName == selectedDefunBranch.FunctionName 111 111 select new CutPoint(node, subtree)).FirstOrDefault(); -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/SubroutineDuplicater.cs
r5686 r5733 71 71 string newFunctionName = allowedFunctionNames.Except(UsedFunctionNames(symbolicExpressionTree)).First(); 72 72 duplicatedDefunBranch.FunctionName = newFunctionName; 73 symbolicExpressionTree.Root.AddSub Tree(duplicatedDefunBranch);73 symbolicExpressionTree.Root.AddSubtree(duplicatedDefunBranch); 74 74 duplicatedDefunBranch.SetGrammar((ISymbolicExpressionTreeGrammar)selectedBranch.Grammar.Clone()); 75 75 // add an invoke symbol for each branch that is allowed to invoke the original function 76 foreach (var subtree in symbolicExpressionTree.Root.Sub Trees.OfType<SymbolicExpressionTreeTopLevelNode>()) {76 foreach (var subtree in symbolicExpressionTree.Root.Subtrees.OfType<SymbolicExpressionTreeTopLevelNode>()) { 77 77 var matchingInvokeSymbol = (from symb in subtree.Grammar.Symbols.OfType<InvokeFunction>() 78 78 where symb.FunctionName == selectedBranch.FunctionName -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Compiler/SymbolicExpressionTreeCompiler.cs
r5571 r5733 33 33 entryPoint.Clear(); 34 34 // compile main body branches 35 foreach (var branch in tree.Root.GetSub Tree(0).SubTrees) {35 foreach (var branch in tree.Root.GetSubtree(0).Subtrees) { 36 36 code.AddRange(Compile(branch, opCodeMapper)); 37 37 } … … 43 43 if (code.Count > ushort.MaxValue) throw new ArgumentException("Code for the tree is too long (> ushort.MaxValue)."); 44 44 entryPoint[branch.FunctionName] = (ushort)code.Count; 45 code.AddRange(Compile(branch.GetSub Tree(0), opCodeMapper));45 code.AddRange(Compile(branch.GetSubtree(0), opCodeMapper)); 46 46 } 47 47 // address of all functions is fixed now … … 62 62 foreach (var node in branch.IterateNodesPrefix()) { 63 63 Instruction instr = new Instruction(); 64 int sub TreesCount = node.SubTrees.Count();65 if (sub TreesCount > 255) throw new ArgumentException("Number of subtrees is too big (>255)");66 instr.nArguments = (byte)sub TreesCount;64 int subtreesCount = node.SubtreesCount; 65 if (subtreesCount > 255) throw new ArgumentException("Number of subtrees is too big (>255)"); 66 instr.nArguments = (byte)subtreesCount; 67 67 instr.opCode = opCodeMapper(node); 68 68 if (node.Symbol is Argument) { -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/ProbabilisticTreeCreator.cs
r5727 r5733 89 89 startNode.SetGrammar(new SymbolicExpressionTreeGrammar(grammar)); 90 90 if (startNode.HasLocalParameters) startNode.ResetLocalParameters(random); 91 rootNode.AddSub Tree(startNode);91 rootNode.AddSubtree(startNode); 92 92 PTC2(random, startNode, maxTreeLength, maxTreeDepth); 93 93 tree.Root = rootNode; … … 120 120 } else { 121 121 // clean seedNode 122 while (seedNode.Sub Trees.Count() > 0) seedNode.RemoveSubTree(0);122 while (seedNode.Subtrees.Count() > 0) seedNode.RemoveSubtree(0); 123 123 } 124 124 // try a different length MAX_TRIES times … … 138 138 // insert a dummy sub-tree and add the pending extension to the list 139 139 var dummy = new SymbolicExpressionTreeNode(); 140 root.AddSub Tree(dummy);140 root.AddSubtree(dummy); 141 141 extensionPoints.Add(new TreeExtensionPoint { Parent = root, ChildIndex = i, ExtensionPointDepth = 0 }); 142 142 } … … 162 162 ISymbolicExpressionTreeNode newTree = selectedSymbol.CreateTreeNode(); 163 163 if (newTree.HasLocalParameters) newTree.ResetLocalParameters(random); 164 parent.RemoveSub Tree(argumentIndex);165 parent.InsertSub Tree(argumentIndex, newTree);164 parent.RemoveSubtree(argumentIndex); 165 parent.InsertSubtree(argumentIndex, newTree); 166 166 167 167 var topLevelNode = newTree as SymbolicExpressionTreeTopLevelNode; … … 177 177 // insert a dummy sub-tree and add the pending extension to the list 178 178 var dummy = new SymbolicExpressionTreeNode(); 179 newTree.AddSub Tree(dummy);179 newTree.AddSubtree(dummy); 180 180 extensionPoints.Add(new TreeExtensionPoint { Parent = newTree, ChildIndex = i, ExtensionPointDepth = extensionDepth + 1 }); 181 181 } … … 207 207 var tree = selectedSymbol.CreateTreeNode(); 208 208 if (tree.HasLocalParameters) tree.ResetLocalParameters(random); 209 parent.RemoveSub Tree(childIndex);210 parent.InsertSub Tree(childIndex, tree);209 parent.RemoveSubtree(childIndex); 210 parent.InsertSubtree(childIndex, tree); 211 211 212 212 var topLevelNode = tree as SymbolicExpressionTreeTopLevelNode; … … 217 217 // insert a dummy sub-tree and add the pending extension to the list 218 218 var dummy = new SymbolicExpressionTreeNode(); 219 tree.AddSub Tree(dummy);219 tree.AddSubtree(dummy); 220 220 // replace the just inserted dummy by recursive application 221 221 ReplaceWithMinimalTree(random, root, tree, i); -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Crossovers/SubtreeCrossover.cs
r5686 r5733 93 93 94 94 // calculate the max length and depth that the inserted branch can have 95 int maxInsertedBranchLength = maxTreeLength - (parent0.Length - crossoverPoint0.GetSub Tree(replacedSubtreeIndex).GetLength());95 int maxInsertedBranchLength = maxTreeLength - (parent0.Length - crossoverPoint0.GetSubtree(replacedSubtreeIndex).GetLength()); 96 96 int maxInsertedBranchDepth = maxTreeDepth - GetBranchLevel(parent0.Root, crossoverPoint0); 97 97 … … 111 111 // manipulate the tree of parent0 in place 112 112 // replace the branch in tree0 with the selected branch from tree1 113 crossoverPoint0.RemoveSub Tree(replacedSubtreeIndex);114 crossoverPoint0.InsertSub Tree(replacedSubtreeIndex, selectedBranch);113 crossoverPoint0.RemoveSubtree(replacedSubtreeIndex); 114 crossoverPoint0.InsertSubtree(replacedSubtreeIndex, selectedBranch); 115 115 return parent0; 116 116 } … … 139 139 List<CutPoint> leafCrossoverPoints = new List<CutPoint>(); 140 140 parent0.Root.ForEachNodePostfix((n) => { 141 if (n.Sub Trees.Any() && n != parent0.Root) {142 foreach (var child in n.Sub Trees) {141 if (n.Subtrees.Any() && n != parent0.Root) { 142 foreach (var child in n.Subtrees) { 143 143 if (child.GetLength() <= maxBranchLength && 144 144 child.GetDepth() <= maxBranchDepth) { 145 if (child.Sub Trees.Any())145 if (child.Subtrees.Any()) 146 146 internalCrossoverPoints.Add(new CutPoint(n, child)); 147 147 else … … 185 185 // select internal node if possible 186 186 allowedInternalBranches = (from branch in branches 187 where branch.Sub Trees.Any()187 where branch.Subtrees.Any() 188 188 select branch).ToList(); 189 189 if (allowedInternalBranches.Count > 0) { … … 192 192 // no internal nodes allowed => select leaf nodes 193 193 allowedLeafBranches = (from branch in branches 194 where !branch.Sub Trees.Any()194 where !branch.Subtrees.Any() 195 195 select branch).ToList(); 196 196 return allowedLeafBranches.SelectRandom(random); … … 199 199 // select leaf node if possible 200 200 allowedLeafBranches = (from branch in branches 201 where !branch.Sub Trees.Any()201 where !branch.Subtrees.Any() 202 202 select branch).ToList(); 203 203 if (allowedLeafBranches.Count > 0) { … … 205 205 } else { 206 206 allowedInternalBranches = (from branch in branches 207 where branch.Sub Trees.Any()207 where branch.Subtrees.Any() 208 208 select branch).ToList(); 209 209 return allowedInternalBranches.SelectRandom(random); … … 214 214 private static int GetBranchLevel(ISymbolicExpressionTreeNode root, ISymbolicExpressionTreeNode point) { 215 215 if (root == point) return 0; 216 foreach (var subtree in root.Sub Trees) {216 foreach (var subtree in root.Subtrees) { 217 217 int branchLevel = GetBranchLevel(subtree, point); 218 218 if (branchLevel < int.MaxValue) return 1 + branchLevel; -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/CutPoint.cs
r5686 r5733 32 32 this.Parent = parent; 33 33 this.Child = child; 34 this.childIndex = parent.IndexOfSub Tree(child);34 this.childIndex = parent.IndexOfSubtree(child); 35 35 } 36 36 } -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Formatters/SymbolicExpressionTreeStringFormatter.cs
r5510 r5733 55 55 strBuilder.Append("("); 56 56 // internal nodes or leaf nodes? 57 if (node.Sub Trees.Count() > 0) {57 if (node.Subtrees.Count() > 0) { 58 58 // symbol on same line as '(' 59 59 strBuilder.AppendLine(node.ToString()); 60 60 // each subtree expression on a new line 61 61 // and closing ')' also on new line 62 foreach (var subtree in node.Sub Trees) {62 foreach (var subtree in node.Subtrees) { 63 63 strBuilder.AppendLine(FormatRecursively(subtree, indentLength + 2)); 64 64 } -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/ISymbolicExpressionTreeNode.cs
r5686 r5733 38 38 void ForEachNodePrefix(Action<ISymbolicExpressionTreeNode> a); 39 39 40 IEnumerable<ISymbolicExpressionTreeNode> Sub Trees { get; }40 IEnumerable<ISymbolicExpressionTreeNode> Subtrees { get; } 41 41 int SubtreesCount { get; } 42 ISymbolicExpressionTreeNode GetSub Tree(int index);43 int IndexOfSub Tree(ISymbolicExpressionTreeNode tree);44 void AddSub Tree(ISymbolicExpressionTreeNode tree);45 void InsertSub Tree(int index, ISymbolicExpressionTreeNode tree);46 void RemoveSub Tree(int index);42 ISymbolicExpressionTreeNode GetSubtree(int index); 43 int IndexOfSubtree(ISymbolicExpressionTreeNode tree); 44 void AddSubtree(ISymbolicExpressionTreeNode tree); 45 void InsertSubtree(int index, ISymbolicExpressionTreeNode tree); 46 void RemoveSubtree(int index); 47 47 48 48 void ResetLocalParameters(IRandom random); -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/ChangeNodeTypeManipulation.cs
r5686 r5733 45 45 // select any node as parent (except the root node) 46 46 var manipulationPoints = (from parent in symbolicExpressionTree.Root.IterateNodesPrefix().Skip(1) 47 let subtreeCount = parent.Sub Trees.Count()47 let subtreeCount = parent.Subtrees.Count() 48 48 from subtreeIndex in Enumerable.Range(0, subtreeCount) 49 let subtree = parent.GetSub Tree(subtreeIndex)50 let existingSubtreeCount = subtree.Sub Trees.Count()49 let subtree = parent.GetSubtree(subtreeIndex) 50 let existingSubtreeCount = subtree.Subtrees.Count() 51 51 // find possible symbols for the node (also considering the existing branches below it) 52 52 let allowedSymbols = (from symbol in parent.Grammar.GetAllowedChildSymbols(parent.Symbol, subtreeIndex) … … 57 57 // keep only symbols that are still possible considering the existing sub-trees 58 58 where (from existingSubtreeIndex in Enumerable.Range(0, existingSubtreeCount) 59 let existingSubtree = subtree.GetSub Tree(existingSubtreeIndex)59 let existingSubtree = subtree.GetSubtree(existingSubtreeIndex) 60 60 select parent.Grammar.IsAllowedChildSymbol(symbol, existingSubtree.Symbol, existingSubtreeIndex)) 61 61 .All(x => x == true) … … 75 75 if (newNode.HasLocalParameters) 76 76 newNode.ResetLocalParameters(random); 77 foreach (var subtree in selectedManipulationPoint.Child.Sub Trees)78 newNode.AddSub Tree(subtree);79 selectedManipulationPoint.Parent.RemoveSub Tree(selectedManipulationPoint.Index);80 selectedManipulationPoint.Parent.InsertSub Tree(selectedManipulationPoint.Index, newNode);77 foreach (var subtree in selectedManipulationPoint.Child.Subtrees) 78 newNode.AddSubtree(subtree); 79 selectedManipulationPoint.Parent.RemoveSubtree(selectedManipulationPoint.Index); 80 selectedManipulationPoint.Parent.InsertSubtree(selectedManipulationPoint.Index, newNode); 81 81 } 82 82 } -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/ReplaceBranchManipulation.cs
r5686 r5733 70 70 // select any node as parent (except the root node) 71 71 var manipulationPoints = (from parent in symbolicExpressionTree.Root.IterateNodesPrefix().Skip(1) 72 from subtree in parent.Sub Trees73 let subtreeIndex = parent.IndexOfSub Tree(subtree)72 from subtree in parent.Subtrees 73 let subtreeIndex = parent.IndexOfSubtree(subtree) 74 74 let maxLength = maxTreeLength - symbolicExpressionTree.Length + subtree.GetLength() 75 75 let maxDepth = maxTreeDepth - symbolicExpressionTree.Depth + subtree.GetDepth() … … 103 103 seedNode.ResetLocalParameters(random); 104 104 105 selectedManipulationPoint.Parent.RemoveSub Tree(selectedManipulationPoint.Index);106 selectedManipulationPoint.Parent.InsertSub Tree(selectedManipulationPoint.Index, seedNode);105 selectedManipulationPoint.Parent.RemoveSubtree(selectedManipulationPoint.Index); 106 selectedManipulationPoint.Parent.InsertSubtree(selectedManipulationPoint.Index, seedNode); 107 107 ProbabilisticTreeCreator.PTC2(random, seedNode, selectedManipulationPoint.MaxLength, selectedManipulationPoint.MaxDepth); 108 108 } -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeNode.cs
r5728 r5733 30 30 public class SymbolicExpressionTreeNode : DeepCloneable, ISymbolicExpressionTreeNode { 31 31 [Storable] 32 private IList<ISymbolicExpressionTreeNode> sub Trees;32 private IList<ISymbolicExpressionTreeNode> subtrees; 33 33 [Storable] 34 34 private ISymbol symbol; … … 55 55 : base() { 56 56 symbol = original.symbol; // symbols are reused 57 sub Trees = new List<ISymbolicExpressionTreeNode>(original.subTrees.Count);58 foreach (var subtree in original.sub Trees) {59 var clonedSub Tree = cloner.Clone(subtree);60 sub Trees.Add(clonedSubTree);61 clonedSub Tree.Parent = this;57 subtrees = new List<ISymbolicExpressionTreeNode>(original.subtrees.Count); 58 foreach (var subtree in original.subtrees) { 59 var clonedSubtree = cloner.Clone(subtree); 60 subtrees.Add(clonedSubtree); 61 clonedSubtree.Parent = this; 62 62 } 63 63 } … … 74 74 public SymbolicExpressionTreeNode(ISymbol symbol) 75 75 : base() { 76 sub Trees = new List<ISymbolicExpressionTreeNode>(3);76 subtrees = new List<ISymbolicExpressionTreeNode>(3); 77 77 this.symbol = symbol; 78 78 } … … 81 81 [StorableHook(HookType.AfterDeserialization)] 82 82 private void AfterDeserialization() { 83 if (sub Trees != null) {84 foreach (var subtree in sub Trees)83 if (subtrees != null) { 84 foreach (var subtree in subtrees) 85 85 subtree.Parent = this; 86 86 } … … 91 91 } 92 92 93 public virtual IEnumerable<ISymbolicExpressionTreeNode> Sub Trees {94 get { return sub Trees; }93 public virtual IEnumerable<ISymbolicExpressionTreeNode> Subtrees { 94 get { return subtrees; } 95 95 } 96 96 … … 103 103 else { 104 104 length = 1; 105 if (sub Trees != null) {106 for (int i = 0; i < sub Trees.Count; i++) {107 checked { length += (ushort)sub Trees[i].GetLength(); }105 if (subtrees != null) { 106 for (int i = 0; i < subtrees.Count; i++) { 107 checked { length += (ushort)subtrees[i].GetLength(); } 108 108 } 109 109 } … … 115 115 if (depth > 0) return depth; 116 116 else { 117 if (sub Trees != null) {118 for (int i = 0; i < sub Trees.Count; i++) depth = Math.Max(depth, (ushort)subTrees[i].GetDepth());117 if (subtrees != null) { 118 for (int i = 0; i < subtrees.Count; i++) depth = Math.Max(depth, (ushort)subtrees[i].GetDepth()); 119 119 } 120 120 depth++; … … 128 128 public int SubtreesCount { 129 129 get { 130 if (sub Trees == null) return 0;131 return sub Trees.Count;130 if (subtrees == null) return 0; 131 return subtrees.Count; 132 132 } 133 133 } 134 134 135 public virtual ISymbolicExpressionTreeNode GetSub Tree(int index) {136 return sub Trees[index];135 public virtual ISymbolicExpressionTreeNode GetSubtree(int index) { 136 return subtrees[index]; 137 137 } 138 public virtual int IndexOfSub Tree(ISymbolicExpressionTreeNode tree) {139 return sub Trees.IndexOf(tree);138 public virtual int IndexOfSubtree(ISymbolicExpressionTreeNode tree) { 139 return subtrees.IndexOf(tree); 140 140 } 141 public virtual void AddSub Tree(ISymbolicExpressionTreeNode tree) {142 sub Trees.Add(tree);141 public virtual void AddSubtree(ISymbolicExpressionTreeNode tree) { 142 subtrees.Add(tree); 143 143 tree.Parent = this; 144 144 ResetCachedValues(); 145 145 } 146 public virtual void InsertSub Tree(int index, ISymbolicExpressionTreeNode tree) {147 sub Trees.Insert(index, tree);146 public virtual void InsertSubtree(int index, ISymbolicExpressionTreeNode tree) { 147 subtrees.Insert(index, tree); 148 148 tree.Parent = this; 149 149 ResetCachedValues(); 150 150 } 151 public virtual void RemoveSub Tree(int index) {152 sub Trees[index].Parent = null;153 sub Trees.RemoveAt(index);151 public virtual void RemoveSubtree(int index) { 152 subtrees[index].Parent = null; 153 subtrees.RemoveAt(index); 154 154 ResetCachedValues(); 155 155 } … … 163 163 public void ForEachNodePrefix(Action<ISymbolicExpressionTreeNode> a) { 164 164 a(this); 165 if (Sub Trees != null) {166 foreach (var subtree in Sub Trees) {165 if (Subtrees != null) { 166 foreach (var subtree in Subtrees) { 167 167 subtree.ForEachNodePrefix(a); 168 168 } … … 177 177 178 178 public void ForEachNodePostfix(Action<ISymbolicExpressionTreeNode> a) { 179 if (Sub Trees != null) {180 foreach (var subtree in Sub Trees) {179 if (Subtrees != null) { 180 foreach (var subtree in Subtrees) { 181 181 subtree.ForEachNodePostfix(a); 182 182 } -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeTerminalNode.cs
r5686 r5733 29 29 [StorableClass] 30 30 public abstract class SymbolicExpressionTreeTerminalNode : SymbolicExpressionTreeNode { 31 public override IEnumerable<ISymbolicExpressionTreeNode> Sub Trees {31 public override IEnumerable<ISymbolicExpressionTreeNode> Subtrees { 32 32 get { 33 33 return Enumerable.Empty<ISymbolicExpressionTreeNode>(); … … 51 51 } 52 52 53 public override int IndexOfSub Tree(ISymbolicExpressionTreeNode tree) {53 public override int IndexOfSubtree(ISymbolicExpressionTreeNode tree) { 54 54 return -1; 55 55 } 56 public override ISymbolicExpressionTreeNode GetSub Tree(int index) {56 public override ISymbolicExpressionTreeNode GetSubtree(int index) { 57 57 throw new NotSupportedException(); 58 58 } 59 public override void AddSub Tree(ISymbolicExpressionTreeNode tree) {59 public override void AddSubtree(ISymbolicExpressionTreeNode tree) { 60 60 throw new NotSupportedException(); 61 61 } 62 public override void InsertSub Tree(int index, ISymbolicExpressionTreeNode tree) {62 public override void InsertSubtree(int index, ISymbolicExpressionTreeNode tree) { 63 63 throw new NotSupportedException(); 64 64 } 65 public override void RemoveSub Tree(int index) {65 public override void RemoveSubtree(int index) { 66 66 throw new NotSupportedException(); 67 67 } -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests/AllArchitectureAlteringOperatorsTest.cs
r5686 r5733 110 110 Util.GetSizeDistributionString(trees, 200, 5) + Environment.NewLine + 111 111 Util.GetFunctionDistributionString(trees) + Environment.NewLine + 112 Util.GetNumberOfSub TreesDistributionString(trees) + Environment.NewLine +112 Util.GetNumberOfSubtreesDistributionString(trees) + Environment.NewLine + 113 113 Util.GetTerminalDistributionString(trees) + Environment.NewLine 114 114 ); -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests/ArgumentCreaterTest.cs
r5686 r5733 72 72 Util.GetSizeDistributionString(trees, 200, 20) + Environment.NewLine + 73 73 Util.GetFunctionDistributionString(trees) + Environment.NewLine + 74 Util.GetNumberOfSub TreesDistributionString(trees) + Environment.NewLine +74 Util.GetNumberOfSubtreesDistributionString(trees) + Environment.NewLine + 75 75 Util.GetTerminalDistributionString(trees) + Environment.NewLine 76 76 ); … … 78 78 79 79 private bool TreeHasAdfWithParameter(ISymbolicExpressionTree tree, int maxParameters) { 80 if (tree.Root.Sub Trees.Count() != 2) return false;81 var firstAdf = tree.Root.GetSub Tree(1);80 if (tree.Root.Subtrees.Count() != 2) return false; 81 var firstAdf = tree.Root.GetSubtree(1); 82 82 return firstAdf.Grammar.GetAllowedChildSymbols(firstAdf.Symbol, 0).Where(x => x is Argument).Count() < maxParameters; 83 83 } -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests/ArgumentDeleterTest.cs
r5686 r5733 67 67 Util.GetSizeDistributionString(trees, 105, 5) + Environment.NewLine + 68 68 Util.GetFunctionDistributionString(trees) + Environment.NewLine + 69 Util.GetNumberOfSub TreesDistributionString(trees) + Environment.NewLine +69 Util.GetNumberOfSubtreesDistributionString(trees) + Environment.NewLine + 70 70 Util.GetTerminalDistributionString(trees) + Environment.NewLine 71 71 ); 72 72 } 73 73 private bool TreeHasAdfWithArguments(ISymbolicExpressionTree tree) { 74 if (tree.Root.Sub Trees.Count() != 2) return false;75 var firstAdf = tree.Root.GetSub Tree(1);74 if (tree.Root.Subtrees.Count() != 2) return false; 75 var firstAdf = tree.Root.GetSubtree(1); 76 76 return firstAdf.Grammar.GetAllowedChildSymbols(firstAdf.Symbol, 0).Where(x => x is Argument).Count() >= 2; 77 77 } -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests/ArgumentDuplicaterTest.cs
r5686 r5733 67 67 Util.GetSizeDistributionString(trees, 200, 5) + Environment.NewLine + 68 68 Util.GetFunctionDistributionString(trees) + Environment.NewLine + 69 Util.GetNumberOfSub TreesDistributionString(trees) + Environment.NewLine +69 Util.GetNumberOfSubtreesDistributionString(trees) + Environment.NewLine + 70 70 Util.GetTerminalDistributionString(trees) + Environment.NewLine 71 71 ); … … 73 73 74 74 private bool HasAdfWithArguments(ISymbolicExpressionTree tree) { 75 if (tree.Root.Sub Trees.Count() != 2) return false;76 var firstAdf = tree.Root.GetSub Tree(1);75 if (tree.Root.Subtrees.Count() != 2) return false; 76 var firstAdf = tree.Root.GetSubtree(1); 77 77 return firstAdf.Grammar.GetAllowedChildSymbols(firstAdf.Symbol, 0).Where(x => x is Argument).Count() == 1; 78 78 } -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests/ChangeNodeTypeManipulationTest.cs
r5686 r5733 67 67 Util.GetSizeDistributionString(trees, 105, 5) + Environment.NewLine + 68 68 Util.GetFunctionDistributionString(trees) + Environment.NewLine + 69 Util.GetNumberOfSub TreesDistributionString(trees) + Environment.NewLine +69 Util.GetNumberOfSubtreesDistributionString(trees) + Environment.NewLine + 70 70 Util.GetTerminalDistributionString(trees) + Environment.NewLine 71 71 ); -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests/ProbabilisticTreeCreaterTest.cs
r5686 r5733 69 69 Util.GetSizeDistributionString(randomTrees, 105, 5) + Environment.NewLine + 70 70 Util.GetFunctionDistributionString(randomTrees) + Environment.NewLine + 71 Util.GetNumberOfSub TreesDistributionString(randomTrees) + Environment.NewLine +71 Util.GetNumberOfSubtreesDistributionString(randomTrees) + Environment.NewLine + 72 72 Util.GetTerminalDistributionString(randomTrees) + Environment.NewLine 73 73 ); -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests/ReplaceBranchManipulationTest.cs
r5686 r5733 66 66 Util.GetSizeDistributionString(trees, 105, 5) + Environment.NewLine + 67 67 Util.GetFunctionDistributionString(trees) + Environment.NewLine + 68 Util.GetNumberOfSub TreesDistributionString(trees) + Environment.NewLine +68 Util.GetNumberOfSubtreesDistributionString(trees) + Environment.NewLine + 69 69 Util.GetTerminalDistributionString(trees) + Environment.NewLine 70 70 ); -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests/SubroutineCreaterTest.cs
r5686 r5733 63 63 Util.GetSizeDistributionString(trees, 105, 5) + Environment.NewLine + 64 64 Util.GetFunctionDistributionString(trees) + Environment.NewLine + 65 Util.GetNumberOfSub TreesDistributionString(trees) + Environment.NewLine +65 Util.GetNumberOfSubtreesDistributionString(trees) + Environment.NewLine + 66 66 Util.GetTerminalDistributionString(trees) + Environment.NewLine 67 67 ); -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests/SubroutineDeleterTest.cs
r5686 r5733 68 68 Util.GetSizeDistributionString(trees, 105, 5) + Environment.NewLine + 69 69 Util.GetFunctionDistributionString(trees) + Environment.NewLine + 70 Util.GetNumberOfSub TreesDistributionString(trees) + Environment.NewLine +70 Util.GetNumberOfSubtreesDistributionString(trees) + Environment.NewLine + 71 71 Util.GetTerminalDistributionString(trees) + Environment.NewLine 72 72 ); … … 74 74 75 75 private bool HasAtLeastOneAdf(ISymbolicExpressionTree tree) { 76 return tree.Root.Sub Trees.Count() > 1;76 return tree.Root.Subtrees.Count() > 1; 77 77 } 78 78 } -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests/SubroutineDuplicaterTest.cs
r5686 r5733 68 68 Util.GetSizeDistributionString(trees, 105, 5) + Environment.NewLine + 69 69 Util.GetFunctionDistributionString(trees) + Environment.NewLine + 70 Util.GetNumberOfSub TreesDistributionString(trees) + Environment.NewLine +70 Util.GetNumberOfSubtreesDistributionString(trees) + Environment.NewLine + 71 71 Util.GetTerminalDistributionString(trees) + Environment.NewLine 72 72 ); … … 74 74 75 75 private bool HasOneAdf(ISymbolicExpressionTree tree) { 76 return tree.Root.Sub Trees.Count() == 2;76 return tree.Root.Subtrees.Count() == 2; 77 77 } 78 78 } -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests/SubtreeCrossoverTest.cs
r5686 r5733 81 81 Util.GetSizeDistributionString(trees, 105, 5) + Environment.NewLine + 82 82 Util.GetFunctionDistributionString(trees) + Environment.NewLine + 83 Util.GetNumberOfSub TreesDistributionString(trees) + Environment.NewLine +83 Util.GetNumberOfSubtreesDistributionString(trees) + Environment.NewLine + 84 84 Util.GetTerminalDistributionString(trees) + Environment.NewLine 85 85 ); -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests/Util.cs
r5686 r5733 53 53 for (int i = 0; i < trees.Count; i++) { 54 54 foreach (var node in trees[i].IterateNodesPrefix()) { 55 if (node.Sub Trees.Count() > 0) {55 if (node.Subtrees.Count() > 0) { 56 56 if (!occurances.ContainsKey(node.Symbol.Name)) 57 57 occurances[node.Symbol.Name] = 0; … … 70 70 } 71 71 72 public static string GetNumberOfSub TreesDistributionString(IList<ISymbolicExpressionTree> trees) {72 public static string GetNumberOfSubtreesDistributionString(IList<ISymbolicExpressionTree> trees) { 73 73 Dictionary<int, int> occurances = new Dictionary<int, int>(); 74 74 double n = 0.0; 75 75 for (int i = 0; i < trees.Count; i++) { 76 76 foreach (var node in trees[i].IterateNodesPrefix()) { 77 if (!occurances.ContainsKey(node.Sub Trees.Count()))78 occurances[node.Sub Trees.Count()] = 0;79 occurances[node.Sub Trees.Count()]++;77 if (!occurances.ContainsKey(node.Subtrees.Count())) 78 occurances[node.Subtrees.Count()] = 0; 79 occurances[node.Subtrees.Count()]++; 80 80 n++; 81 81 } … … 96 96 for (int i = 0; i < trees.Count; i++) { 97 97 foreach (var node in trees[i].IterateNodesPrefix()) { 98 if (node.Sub Trees.Count() == 0) {98 if (node.Subtrees.Count() == 0) { 99 99 if (!occurances.ContainsKey(node.Symbol.Name)) 100 100 occurances[node.Symbol.Name] = 0; … … 118 118 Assert.AreEqual(actualSize, reportedSize); 119 119 120 foreach (var defunTreeNode in tree.Root.Sub Trees.OfType<DefunTreeNode>()) {120 foreach (var defunTreeNode in tree.Root.Subtrees.OfType<DefunTreeNode>()) { 121 121 int arity = defunTreeNode.NumberOfArguments; 122 122 … … 133 133 134 134 var invoke = new InvokeFunction(defunTreeNode.FunctionName); 135 foreach (var otherRootNode in tree.Root.Sub Trees) {135 foreach (var otherRootNode in tree.Root.Subtrees) { 136 136 if (otherRootNode.Grammar.ContainsSymbol(invoke)) { 137 137 Assert.IsTrue(otherRootNode.Grammar.GetMinimumSubtreeCount(invoke) == arity); … … 141 141 142 142 } 143 foreach (var subtree in tree.Root.Sub Trees) {143 foreach (var subtree in tree.Root.Subtrees) { 144 144 Assert.AreNotSame(subtree.Grammar, tree.Root.Grammar); 145 145 IsValid(subtree.Grammar); … … 165 165 where symb.Name == treeNode.Symbol.Name 166 166 select symb).SingleOrDefault(); 167 Assert.IsTrue(treeNode.Sub Trees.Count() >= treeNode.Grammar.GetMinimumSubtreeCount(matchingSymbol));168 Assert.IsTrue(treeNode.Sub Trees.Count() <= treeNode.Grammar.GetMaximumSubtreeCount(matchingSymbol));167 Assert.IsTrue(treeNode.Subtrees.Count() >= treeNode.Grammar.GetMinimumSubtreeCount(matchingSymbol)); 168 Assert.IsTrue(treeNode.Subtrees.Count() <= treeNode.Grammar.GetMaximumSubtreeCount(matchingSymbol)); 169 169 Assert.AreNotEqual(0.0, matchingSymbol.InitialFrequency); // check that no deactivated symbols occur in the tree 170 for (int i = 0; i < treeNode.Sub Trees.Count(); i++) {171 Assert.IsTrue(treeNode.Grammar.GetAllowedChildSymbols(treeNode.Symbol, i).Select(x => x.Name).Contains(treeNode.GetSub Tree(i).Symbol.Name));172 IsValid(treeNode.GetSub Tree(i));170 for (int i = 0; i < treeNode.Subtrees.Count(); i++) { 171 Assert.IsTrue(treeNode.Grammar.GetAllowedChildSymbols(treeNode.Symbol, i).Select(x => x.Name).Contains(treeNode.GetSubtree(i).Symbol.Name)); 172 IsValid(treeNode.GetSubtree(i)); 173 173 } 174 174 } -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.ArtificialAnt/3.4/AntInterpreter.cs
r5517 r5733 51 51 52 52 private SymbolicExpressionTreeNode FindMatchingFunction(string name) { 53 foreach (var defunBranch in expression.Root.Sub Trees.OfType<DefunTreeNode>()) {53 foreach (var defunBranch in expression.Root.Subtrees.OfType<DefunTreeNode>()) { 54 54 if (defunBranch.FunctionName == name) return defunBranch; 55 55 } … … 93 93 // expression evaluated completly => start at root again 94 94 if (nodeStack.Count == 0) { 95 nodeStack.Push(Expression.Root.GetSub Tree(0).GetSubTree(0));95 nodeStack.Push(Expression.Root.GetSubtree(0).GetSubtree(0)); 96 96 } 97 97 … … 114 114 NextField(out nextAntLocationRow, out nextAntLocationColumn); 115 115 if (World[nextAntLocationRow, nextAntLocationColumn]) { 116 nodeStack.Push(currentNode.GetSub Tree(0));116 nodeStack.Push(currentNode.GetSubtree(0)); 117 117 } else { 118 nodeStack.Push(currentNode.GetSub Tree(1));118 nodeStack.Push(currentNode.GetSubtree(1)); 119 119 } 120 120 } else if (currentNode.Symbol is Prog2) { 121 nodeStack.Push(currentNode.GetSub Tree(1));122 nodeStack.Push(currentNode.GetSub Tree(0));121 nodeStack.Push(currentNode.GetSubtree(1)); 122 nodeStack.Push(currentNode.GetSubtree(0)); 123 123 return; 124 124 } else if (currentNode.Symbol is Prog3) { 125 nodeStack.Push(currentNode.GetSub Tree(2));126 nodeStack.Push(currentNode.GetSub Tree(1));127 nodeStack.Push(currentNode.GetSub Tree(0));125 nodeStack.Push(currentNode.GetSubtree(2)); 126 nodeStack.Push(currentNode.GetSubtree(1)); 127 nodeStack.Push(currentNode.GetSubtree(0)); 128 128 return; 129 129 } else if (currentNode.Symbol is InvokeFunction) { … … 131 131 var functionDefinition = (SymbolicExpressionTreeNode)FindMatchingFunction(invokeNode.Symbol.FunctionName).Clone(); 132 132 var argumentCutPoints = (from node in functionDefinition.IterateNodesPrefix() 133 where node.Sub Trees.Count() > 0134 from subtree in node.Sub Trees133 where node.Subtrees.Count() > 0 134 from subtree in node.Subtrees 135 135 where subtree is ArgumentTreeNode 136 select new { Parent = node, Argument = subtree.Symbol as Argument, ChildIndex = node.IndexOfSub Tree(subtree) }).ToList();136 select new { Parent = node, Argument = subtree.Symbol as Argument, ChildIndex = node.IndexOfSubtree(subtree) }).ToList(); 137 137 foreach (var cutPoint in argumentCutPoints) { 138 cutPoint.Parent.RemoveSub Tree(cutPoint.ChildIndex);139 cutPoint.Parent.InsertSub Tree(cutPoint.ChildIndex, (SymbolicExpressionTreeNode)invokeNode.GetSubTree(cutPoint.Argument.ArgumentIndex).Clone());138 cutPoint.Parent.RemoveSubtree(cutPoint.ChildIndex); 139 cutPoint.Parent.InsertSubtree(cutPoint.ChildIndex, (SymbolicExpressionTreeNode)invokeNode.GetSubtree(cutPoint.Argument.ArgumentIndex).Clone()); 140 140 } 141 nodeStack.Push(functionDefinition.GetSub Tree(0));141 nodeStack.Push(functionDefinition.GetSubtree(0)); 142 142 } else { 143 143 throw new InvalidOperationException(currentNode.Symbol.ToString()); -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectiveProblem.cs
r5722 r5733 30 30 [StorableClass] 31 31 [Creatable("Problems")] 32 public class SymbolicClassificationMultiObjectiveProblem : SymbolicDataAnalysisMultiObjectiveProblem<IClassificationProblemData, ISymbolicClassificationMultiObjectiveEvaluator, ISymbolicDataAnalysisSolutionCreator> {32 public class SymbolicClassificationMultiObjectiveProblem : SymbolicDataAnalysisMultiObjectiveProblem<IClassificationProblemData, ISymbolicClassificationMultiObjectiveEvaluator, ISymbolicDataAnalysisSolutionCreator>, IClassificationProblem { 33 33 private const double PunishmentFactor = 10; 34 34 private const int InitialMaximumTreeDepth = 8; -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveProblem.cs
r5722 r5733 30 30 [StorableClass] 31 31 [Creatable("Problems")] 32 public class SymbolicClassificationSingleObjectiveProblem : SymbolicDataAnalysisSingleObjectiveProblem<IClassificationProblemData, ISymbolicClassificationSingleObjectiveEvaluator, ISymbolicDataAnalysisSolutionCreator> {32 public class SymbolicClassificationSingleObjectiveProblem : SymbolicDataAnalysisSingleObjectiveProblem<IClassificationProblemData, ISymbolicClassificationSingleObjectiveEvaluator, ISymbolicDataAnalysisSolutionCreator>, IClassificationProblem { 33 33 private const double PunishmentFactor = 10; 34 34 private const int InitialMaximumTreeDepth = 8; -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4.csproj
r5729 r5733 111 111 <Compile Include="SymbolicRegressionModel.cs" /> 112 112 <Compile Include="Interfaces\ISymbolicRegressionModel.cs" /> 113 <Compile Include="Interfaces\ISymbolicRegressionProblem.cs" />114 <Compile Include="Interfaces\ISymbolicRegressionSingleObjectiveProblem.cs" />115 113 <Compile Include="Interfaces\ISymbolicRegressionSolution.cs" /> 116 114 <Compile Include="Interfaces\ISymbolicRegressionEvaluator.cs" /> -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveProblem.cs
r5722 r5733 31 31 [StorableClass] 32 32 [Creatable("Problems")] 33 public class SymbolicRegressionMultiObjectiveProblem : SymbolicDataAnalysisMultiObjectiveProblem<IRegressionProblemData, ISymbolicRegressionMultiObjectiveEvaluator, ISymbolicDataAnalysisSolutionCreator> {33 public class SymbolicRegressionMultiObjectiveProblem : SymbolicDataAnalysisMultiObjectiveProblem<IRegressionProblemData, ISymbolicRegressionMultiObjectiveEvaluator, ISymbolicDataAnalysisSolutionCreator>, IRegressionProblem { 34 34 private const double PunishmentFactor = 10; 35 35 private const int InitialMaximumTreeDepth = 8; -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveProblem.cs
r5722 r5733 31 31 [StorableClass] 32 32 [Creatable("Problems")] 33 public class SymbolicRegressionSingleObjectiveProblem : SymbolicDataAnalysisSingleObjectiveProblem<IRegressionProblemData, ISymbolicRegressionSingleObjectiveEvaluator, ISymbolicDataAnalysisSolutionCreator> {33 public class SymbolicRegressionSingleObjectiveProblem : SymbolicDataAnalysisSingleObjectiveProblem<IRegressionProblemData, ISymbolicRegressionSingleObjectiveEvaluator, ISymbolicDataAnalysisSolutionCreator>,IRegressionProblem { 34 34 private const double PunishmentFactor = 10; 35 35 private const int InitialMaximumTreeDepth = 8; -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionSolution.cs
r5729 r5733 73 73 ConstantTreeNode betaTreeNode = null; 74 74 // check if model has been scaled previously by analyzing the structure of the tree 75 var startNode = Model.SymbolicExpressionTree.Root.GetSub Tree(0);76 if (startNode.GetSub Tree(0).Symbol is Addition) {77 var addNode = startNode.GetSub Tree(0);78 if (addNode.SubtreesCount == 2 && addNode.GetSub Tree(0).Symbol is Multiplication && addNode.GetSubTree(1).Symbol is Constant) {79 alphaTreeNode = addNode.GetSub Tree(1) as ConstantTreeNode;80 var mulNode = addNode.GetSub Tree(0);81 if (mulNode.SubtreesCount == 2 && mulNode.GetSub Tree(1).Symbol is Constant) {82 betaTreeNode = mulNode.GetSub Tree(1) as ConstantTreeNode;75 var startNode = Model.SymbolicExpressionTree.Root.GetSubtree(0); 76 if (startNode.GetSubtree(0).Symbol is Addition) { 77 var addNode = startNode.GetSubtree(0); 78 if (addNode.SubtreesCount == 2 && addNode.GetSubtree(0).Symbol is Multiplication && addNode.GetSubtree(1).Symbol is Constant) { 79 alphaTreeNode = addNode.GetSubtree(1) as ConstantTreeNode; 80 var mulNode = addNode.GetSubtree(0); 81 if (mulNode.SubtreesCount == 2 && mulNode.GetSubtree(1).Symbol is Constant) { 82 betaTreeNode = mulNode.GetSubtree(1) as ConstantTreeNode; 83 83 } 84 84 } … … 90 90 alphaTreeNode.Value += alpha; 91 91 } else { 92 var mainBranch = startNode.GetSub Tree(0);93 startNode.RemoveSub Tree(0);92 var mainBranch = startNode.GetSubtree(0); 93 startNode.RemoveSubtree(0); 94 94 var scaledMainBranch = MakeSum(MakeProduct(beta, mainBranch), alpha); 95 startNode.AddSub Tree(scaledMainBranch);95 startNode.AddSubtree(scaledMainBranch); 96 96 } 97 97 … … 105 105 var node = (new Addition()).CreateTreeNode(); 106 106 var alphaConst = MakeConstant(alpha); 107 node.AddSub Tree(treeNode);108 node.AddSub Tree(alphaConst);107 node.AddSubtree(treeNode); 108 node.AddSubtree(alphaConst); 109 109 return node; 110 110 } … … 117 117 var node = (new Multiplication()).CreateTreeNode(); 118 118 var betaConst = MakeConstant(beta); 119 node.AddSub Tree(treeNode);120 node.AddSub Tree(betaConst);119 node.AddSubtree(treeNode); 120 node.AddSubtree(betaConst); 121 121 return node; 122 122 } -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisVariableFrequencyAnalyzer.cs
r5732 r5733 153 153 var varCondNode = node as VariableConditionTreeNode; 154 154 IncReferenceCount(references, varCondNode.VariableName, currentLag); 155 GetVariableReferences(references, node.GetSub Tree(0), currentLag);156 GetVariableReferences(references, node.GetSub Tree(1), currentLag);155 GetVariableReferences(references, node.GetSubtree(0), currentLag); 156 GetVariableReferences(references, node.GetSubtree(1), currentLag); 157 157 } else if (node.Symbol is Integral) { 158 158 var laggedNode = node as LaggedTreeNode; 159 159 for (int l = laggedNode.Lag; l <= 0; l++) { 160 GetVariableReferences(references, node.GetSub Tree(0), currentLag + l);160 GetVariableReferences(references, node.GetSubtree(0), currentLag + l); 161 161 } 162 162 } else if (node.Symbol is Derivative) { 163 163 var laggedNode = node as LaggedTreeNode; 164 164 for (int l = laggedNode.Lag; l <= 0; l++) { 165 GetVariableReferences(references, node.GetSub Tree(0), currentLag + l);165 GetVariableReferences(references, node.GetSubtree(0), currentLag + l); 166 166 } 167 167 } else if (node.Symbol is TimeLag) { 168 168 var laggedNode = node as LaggedTreeNode; 169 GetVariableReferences(references, node.GetSub Tree(0), currentLag + laggedNode.Lag);169 GetVariableReferences(references, node.GetSubtree(0), currentLag + laggedNode.Lag); 170 170 } 171 171 } -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj
r5720 r5733 185 185 <Compile Include="Interfaces\ISymbolicDataAnalysisSolution.cs" /> 186 186 <Compile Include="Interfaces\ISymbolicDataAnalysisSolutionCreator.cs" /> 187 <Compile Include="Interfaces\ISymbolicDataAnalysisProblem.cs" />188 187 <Compile Include="Properties\AssemblyInfo.cs" /> 189 188 </ItemGroup> -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionTreeSimplifier.cs
r5574 r5733 55 55 var clone = (ISymbolicExpressionTreeNode)originalTree.Root.Clone(); 56 56 // macro expand (initially no argument trees) 57 var macroExpandedTree = MacroExpand(clone, clone.GetSub Tree(0), new List<ISymbolicExpressionTreeNode>());57 var macroExpandedTree = MacroExpand(clone, clone.GetSubtree(0), new List<ISymbolicExpressionTreeNode>()); 58 58 ISymbolicExpressionTreeNode rootNode = (new ProgramRootSymbol()).CreateTreeNode(); 59 rootNode.AddSub Tree(GetSimplifiedTree(macroExpandedTree));59 rootNode.AddSubtree(GetSimplifiedTree(macroExpandedTree)); 60 60 return new SymbolicExpressionTree(rootNode); 61 61 } … … 63 63 // the argumentTrees list contains already expanded trees used as arguments for invocations 64 64 private ISymbolicExpressionTreeNode MacroExpand(ISymbolicExpressionTreeNode root, ISymbolicExpressionTreeNode node, IList<ISymbolicExpressionTreeNode> argumentTrees) { 65 List<ISymbolicExpressionTreeNode> subtrees = new List<ISymbolicExpressionTreeNode>(node.Sub Trees);66 while (node.Sub Trees.Count() > 0) node.RemoveSubTree(0);65 List<ISymbolicExpressionTreeNode> subtrees = new List<ISymbolicExpressionTreeNode>(node.Subtrees); 66 while (node.SubtreesCount > 0) node.RemoveSubtree(0); 67 67 if (node.Symbol is InvokeFunction) { 68 68 var invokeSym = node.Symbol as InvokeFunction; … … 80 80 // recursive application 81 81 foreach (var subtree in subtrees) { 82 node.AddSub Tree(MacroExpand(root, subtree, argumentTrees));82 node.AddSubtree(MacroExpand(root, subtree, argumentTrees)); 83 83 } 84 84 return node; … … 87 87 88 88 private ISymbolicExpressionTreeNode FindFunctionDefinition(ISymbolicExpressionTreeNode root, string functionName) { 89 foreach (var subtree in root.Sub Trees.OfType<DefunTreeNode>()) {90 if (subtree.FunctionName == functionName) return subtree.GetSub Tree(0);89 foreach (var subtree in root.Subtrees.OfType<DefunTreeNode>()) { 90 if (subtree.FunctionName == functionName) return subtree.GetSubtree(0); 91 91 } 92 92 … … 232 232 private ISymbolicExpressionTreeNode SimplifyAny(ISymbolicExpressionTreeNode original) { 233 233 // can't simplify this function but simplify all subtrees 234 List<ISymbolicExpressionTreeNode> sub Trees = new List<ISymbolicExpressionTreeNode>(original.SubTrees);235 while (original.Sub Trees.Count() > 0) original.RemoveSubTree(0);234 List<ISymbolicExpressionTreeNode> subtrees = new List<ISymbolicExpressionTreeNode>(original.Subtrees); 235 while (original.Subtrees.Count() > 0) original.RemoveSubtree(0); 236 236 var clone = (SymbolicExpressionTreeNode)original.Clone(); 237 List<ISymbolicExpressionTreeNode> simplifiedSub Trees = new List<ISymbolicExpressionTreeNode>();238 foreach (var sub Tree in subTrees) {239 simplifiedSub Trees.Add(GetSimplifiedTree(subTree));240 original.AddSub Tree(subTree);241 } 242 foreach (var simplifiedSubtree in simplifiedSub Trees) {243 clone.AddSub Tree(simplifiedSubtree);244 } 245 if (simplifiedSub Trees.TrueForAll(t => IsConstant(t))) {237 List<ISymbolicExpressionTreeNode> simplifiedSubtrees = new List<ISymbolicExpressionTreeNode>(); 238 foreach (var subtree in subtrees) { 239 simplifiedSubtrees.Add(GetSimplifiedTree(subtree)); 240 original.AddSubtree(subtree); 241 } 242 foreach (var simplifiedSubtree in simplifiedSubtrees) { 243 clone.AddSubtree(simplifiedSubtree); 244 } 245 if (simplifiedSubtrees.TrueForAll(t => IsConstant(t))) { 246 246 SimplifyConstantExpression(clone); 247 247 } … … 255 255 256 256 private ISymbolicExpressionTreeNode SimplifyAverage(ISymbolicExpressionTreeNode original) { 257 if (original.Sub Trees.Count() == 1) {258 return GetSimplifiedTree(original.GetSub Tree(0));257 if (original.Subtrees.Count() == 1) { 258 return GetSimplifiedTree(original.GetSubtree(0)); 259 259 } else { 260 260 // simplify expressions x0..xn 261 261 // make sum(x0..xn) / n 262 Trace.Assert(original.Sub Trees.Count() > 1);263 var sum = original.Sub Trees262 Trace.Assert(original.Subtrees.Count() > 1); 263 var sum = original.Subtrees 264 264 .Select(x => GetSimplifiedTree(x)) 265 265 .Aggregate((a, b) => MakeSum(a, b)); 266 return MakeFraction(sum, MakeConstant(original.Sub Trees.Count()));266 return MakeFraction(sum, MakeConstant(original.Subtrees.Count())); 267 267 } 268 268 } 269 269 270 270 private ISymbolicExpressionTreeNode SimplifyDivision(ISymbolicExpressionTreeNode original) { 271 if (original.Sub Trees.Count() == 1) {272 return Invert(GetSimplifiedTree(original.GetSub Tree(0)));271 if (original.Subtrees.Count() == 1) { 272 return Invert(GetSimplifiedTree(original.GetSubtree(0))); 273 273 } else { 274 274 // simplify expressions x0..xn 275 275 // make multiplication (x0 * 1/(x1 * x1 * .. * xn)) 276 Trace.Assert(original.Sub Trees.Count() > 1);277 var simplifiedTrees = original.Sub Trees.Select(x => GetSimplifiedTree(x));276 Trace.Assert(original.Subtrees.Count() > 1); 277 var simplifiedTrees = original.Subtrees.Select(x => GetSimplifiedTree(x)); 278 278 return 279 279 MakeProduct(simplifiedTrees.First(), Invert(simplifiedTrees.Skip(1).Aggregate((a, b) => MakeProduct(a, b)))); … … 282 282 283 283 private ISymbolicExpressionTreeNode SimplifyMultiplication(ISymbolicExpressionTreeNode original) { 284 if (original.Sub Trees.Count() == 1) {285 return GetSimplifiedTree(original.GetSub Tree(0));286 } else { 287 Trace.Assert(original.Sub Trees.Count() > 1);288 return original.Sub Trees284 if (original.Subtrees.Count() == 1) { 285 return GetSimplifiedTree(original.GetSubtree(0)); 286 } else { 287 Trace.Assert(original.Subtrees.Count() > 1); 288 return original.Subtrees 289 289 .Select(x => GetSimplifiedTree(x)) 290 290 .Aggregate((a, b) => MakeProduct(a, b)); … … 293 293 294 294 private ISymbolicExpressionTreeNode SimplifySubtraction(ISymbolicExpressionTreeNode original) { 295 if (original.Sub Trees.Count() == 1) {296 return Negate(GetSimplifiedTree(original.GetSub Tree(0)));295 if (original.Subtrees.Count() == 1) { 296 return Negate(GetSimplifiedTree(original.GetSubtree(0))); 297 297 } else { 298 298 // simplify expressions x0..xn 299 299 // make addition (x0,-x1..-xn) 300 Trace.Assert(original.Sub Trees.Count() > 1);301 var simplifiedTrees = original.Sub Trees.Select(x => GetSimplifiedTree(x));300 Trace.Assert(original.Subtrees.Count() > 1); 301 var simplifiedTrees = original.Subtrees.Select(x => GetSimplifiedTree(x)); 302 302 return simplifiedTrees.Take(1) 303 303 .Concat(simplifiedTrees.Skip(1).Select(x => Negate(x))) … … 307 307 308 308 private ISymbolicExpressionTreeNode SimplifyAddition(ISymbolicExpressionTreeNode original) { 309 if (original.Sub Trees.Count() == 1) {310 return GetSimplifiedTree(original.GetSub Tree(0));309 if (original.Subtrees.Count() == 1) { 310 return GetSimplifiedTree(original.GetSubtree(0)); 311 311 } else { 312 312 // simplify expression x0..xn 313 313 // make addition (x0..xn) 314 Trace.Assert(original.Sub Trees.Count() > 1);315 return original.Sub Trees314 Trace.Assert(original.Subtrees.Count() > 1); 315 return original.Subtrees 316 316 .Select(x => GetSimplifiedTree(x)) 317 317 .Aggregate((a, b) => MakeSum(a, b)); … … 320 320 321 321 private ISymbolicExpressionTreeNode SimplifyNot(ISymbolicExpressionTreeNode original) { 322 return MakeNot(GetSimplifiedTree(original.GetSub Tree(0)));322 return MakeNot(GetSimplifiedTree(original.GetSubtree(0))); 323 323 } 324 324 private ISymbolicExpressionTreeNode SimplifyOr(ISymbolicExpressionTreeNode original) { 325 return original.Sub Trees325 return original.Subtrees 326 326 .Select(x => GetSimplifiedTree(x)) 327 327 .Aggregate((a, b) => MakeOr(a, b)); 328 328 } 329 329 private ISymbolicExpressionTreeNode SimplifyAnd(ISymbolicExpressionTreeNode original) { 330 return original.Sub Trees330 return original.Subtrees 331 331 .Select(x => GetSimplifiedTree(x)) 332 332 .Aggregate((a, b) => MakeAnd(a, b)); 333 333 } 334 334 private ISymbolicExpressionTreeNode SimplifyLessThan(ISymbolicExpressionTreeNode original) { 335 return MakeLessThan(GetSimplifiedTree(original.GetSub Tree(0)), GetSimplifiedTree(original.GetSubTree(1)));335 return MakeLessThan(GetSimplifiedTree(original.GetSubtree(0)), GetSimplifiedTree(original.GetSubtree(1))); 336 336 } 337 337 private ISymbolicExpressionTreeNode SimplifyGreaterThan(ISymbolicExpressionTreeNode original) { 338 return MakeGreaterThan(GetSimplifiedTree(original.GetSub Tree(0)), GetSimplifiedTree(original.GetSubTree(1)));338 return MakeGreaterThan(GetSimplifiedTree(original.GetSubtree(0)), GetSimplifiedTree(original.GetSubtree(1))); 339 339 } 340 340 private ISymbolicExpressionTreeNode SimplifyIfThenElse(ISymbolicExpressionTreeNode original) { 341 return MakeIfThenElse(GetSimplifiedTree(original.GetSub Tree(0)), GetSimplifiedTree(original.GetSubTree(1)), GetSimplifiedTree(original.GetSubTree(2)));341 return MakeIfThenElse(GetSimplifiedTree(original.GetSubtree(0)), GetSimplifiedTree(original.GetSubtree(1)), GetSimplifiedTree(original.GetSubtree(2))); 342 342 } 343 343 private ISymbolicExpressionTreeNode SimplifyTangent(ISymbolicExpressionTreeNode original) { 344 return MakeTangent(GetSimplifiedTree(original.GetSub Tree(0)));344 return MakeTangent(GetSimplifiedTree(original.GetSubtree(0))); 345 345 } 346 346 private ISymbolicExpressionTreeNode SimplifyCosine(ISymbolicExpressionTreeNode original) { 347 return MakeCosine(GetSimplifiedTree(original.GetSub Tree(0)));347 return MakeCosine(GetSimplifiedTree(original.GetSubtree(0))); 348 348 } 349 349 private ISymbolicExpressionTreeNode SimplifySine(ISymbolicExpressionTreeNode original) { 350 return MakeSine(GetSimplifiedTree(original.GetSub Tree(0)));350 return MakeSine(GetSimplifiedTree(original.GetSubtree(0))); 351 351 } 352 352 private ISymbolicExpressionTreeNode SimplifyExp(ISymbolicExpressionTreeNode original) { 353 return MakeExp(GetSimplifiedTree(original.GetSub Tree(0)));353 return MakeExp(GetSimplifiedTree(original.GetSubtree(0))); 354 354 } 355 355 356 356 private ISymbolicExpressionTreeNode SimplifyLog(ISymbolicExpressionTreeNode original) { 357 return MakeLog(GetSimplifiedTree(original.GetSub Tree(0)));357 return MakeLog(GetSimplifiedTree(original.GetSubtree(0))); 358 358 } 359 359 private ISymbolicExpressionTreeNode SimplifyRoot(ISymbolicExpressionTreeNode original) { 360 return MakeRoot(GetSimplifiedTree(original.GetSub Tree(0)), GetSimplifiedTree(original.GetSubTree(1)));360 return MakeRoot(GetSimplifiedTree(original.GetSubtree(0)), GetSimplifiedTree(original.GetSubtree(1))); 361 361 } 362 362 363 363 private ISymbolicExpressionTreeNode SimplifyPower(ISymbolicExpressionTreeNode original) { 364 return MakePower(GetSimplifiedTree(original.GetSub Tree(0)), GetSimplifiedTree(original.GetSubTree(1)));364 return MakePower(GetSimplifiedTree(original.GetSubtree(0)), GetSimplifiedTree(original.GetSubtree(1))); 365 365 } 366 366 #endregion … … 373 373 else return MakeConstant(1.0); 374 374 } else if (IsNot(t)) { 375 return t.GetSub Tree(0);375 return t.GetSubtree(0); 376 376 } else if (!IsBoolean(t)) { 377 377 var gtNode = gtSymbol.CreateTreeNode(); 378 gtNode.AddSub Tree(t); gtNode.AddSubTree(MakeConstant(0.0));378 gtNode.AddSubtree(t); gtNode.AddSubtree(MakeConstant(0.0)); 379 379 var notNode = notSymbol.CreateTreeNode(); 380 notNode.AddSub Tree(gtNode);380 notNode.AddSubtree(gtNode); 381 381 return notNode; 382 382 } else { 383 383 var notNode = notSymbol.CreateTreeNode(); 384 notNode.AddSub Tree(t);384 notNode.AddSubtree(t); 385 385 return notNode; 386 386 } … … 406 406 // the constant value has no effect on the result of the boolean condition so we can drop the constant term 407 407 var orNode = orSymbol.CreateTreeNode(); 408 orNode.AddSub Tree(a);408 orNode.AddSubtree(a); 409 409 return orNode; 410 410 } 411 411 } else { 412 412 var orNode = orSymbol.CreateTreeNode(); 413 orNode.AddSub Tree(a);414 orNode.AddSub Tree(b);413 orNode.AddSubtree(a); 414 orNode.AddSubtree(b); 415 415 return orNode; 416 416 } … … 432 432 // the constant value has no effect on the result of the boolean condition so we can drop the constant term 433 433 var andNode = andSymbol.CreateTreeNode(); 434 andNode.AddSub Tree(a);434 andNode.AddSubtree(a); 435 435 return andNode; 436 436 } else { … … 440 440 } else { 441 441 var andNode = andSymbol.CreateTreeNode(); 442 andNode.AddSub Tree(a);443 andNode.AddSub Tree(b);442 andNode.AddSubtree(a); 443 andNode.AddSubtree(b); 444 444 return andNode; 445 445 } … … 453 453 } else { 454 454 var ltNode = ltSymbol.CreateTreeNode(); 455 ltNode.AddSub Tree(leftSide);456 ltNode.AddSub Tree(rightSide);455 ltNode.AddSubtree(leftSide); 456 ltNode.AddSubtree(rightSide); 457 457 return ltNode; 458 458 } … … 466 466 } else { 467 467 var gtNode = gtSymbol.CreateTreeNode(); 468 gtNode.AddSub Tree(leftSide);469 gtNode.AddSub Tree(rightSide);468 gtNode.AddSubtree(leftSide); 469 gtNode.AddSubtree(rightSide); 470 470 return gtNode; 471 471 } … … 479 479 var ifNode = ifThenElseSymbol.CreateTreeNode(); 480 480 if (IsBoolean(condition)) { 481 ifNode.AddSub Tree(condition);481 ifNode.AddSubtree(condition); 482 482 } else { 483 483 var gtNode = gtSymbol.CreateTreeNode(); 484 gtNode.AddSub Tree(condition); gtNode.AddSubTree(MakeConstant(0.0));485 ifNode.AddSub Tree(gtNode);486 } 487 ifNode.AddSub Tree(trueBranch);488 ifNode.AddSub Tree(falseBranch);484 gtNode.AddSubtree(condition); gtNode.AddSubtree(MakeConstant(0.0)); 485 ifNode.AddSubtree(gtNode); 486 } 487 ifNode.AddSubtree(trueBranch); 488 ifNode.AddSubtree(falseBranch); 489 489 return ifNode; 490 490 } … … 497 497 } else { 498 498 var sineNode = sineSymbol.CreateTreeNode(); 499 sineNode.AddSub Tree(node);499 sineNode.AddSubtree(node); 500 500 return sineNode; 501 501 } … … 507 507 } else { 508 508 var tanNode = tanSymbol.CreateTreeNode(); 509 tanNode.AddSub Tree(node);509 tanNode.AddSubtree(node); 510 510 return tanNode; 511 511 } … … 517 517 } else { 518 518 var cosNode = cosineSymbol.CreateTreeNode(); 519 cosNode.AddSub Tree(node);519 cosNode.AddSubtree(node); 520 520 return cosNode; 521 521 } … … 526 526 return MakeConstant(Math.Exp(constT.Value)); 527 527 } else if (IsLog(node)) { 528 return node.GetSub Tree(0);528 return node.GetSubtree(0); 529 529 } else if (IsAddition(node)) { 530 return node.Sub Trees.Select(s => MakeExp(s)).Aggregate((s, t) => MakeProduct(s, t));530 return node.Subtrees.Select(s => MakeExp(s)).Aggregate((s, t) => MakeProduct(s, t)); 531 531 } else if (IsSubtraction(node)) { 532 return node.Sub Trees.Select(s => MakeExp(s)).Aggregate((s, t) => MakeProduct(s, Negate(t)));532 return node.Subtrees.Select(s => MakeExp(s)).Aggregate((s, t) => MakeProduct(s, Negate(t))); 533 533 } else { 534 534 var expNode = expSymbol.CreateTreeNode(); 535 expNode.AddSub Tree(node);535 expNode.AddSubtree(node); 536 536 return expNode; 537 537 } … … 542 542 return MakeConstant(Math.Log(constT.Value)); 543 543 } else if (IsExp(node)) { 544 return node.GetSub Tree(0);544 return node.GetSubtree(0); 545 545 } else if (IsMultiplication(node)) { 546 return node.Sub Trees.Select(s => MakeLog(s)).Aggregate((x, y) => MakeSum(x, y));546 return node.Subtrees.Select(s => MakeLog(s)).Aggregate((x, y) => MakeSum(x, y)); 547 547 } else if (IsDivision(node)) { 548 548 var subtractionNode = subSymbol.CreateTreeNode(); 549 foreach (var sub Tree in node.SubTrees) {550 subtractionNode.AddSub Tree(MakeLog(subTree));549 foreach (var subtree in node.Subtrees) { 550 subtractionNode.AddSubtree(MakeLog(subtree)); 551 551 } 552 552 return subtractionNode; 553 553 } else { 554 554 var logNode = logSymbol.CreateTreeNode(); 555 logNode.AddSub Tree(node);555 logNode.AddSubtree(node); 556 556 return logNode; 557 557 } … … 573 573 } else if (constBValue < 0) { 574 574 var rootNode = rootSymbol.CreateTreeNode(); 575 rootNode.AddSub Tree(a);576 rootNode.AddSub Tree(MakeConstant(-1.0 * constBValue));575 rootNode.AddSubtree(a); 576 rootNode.AddSubtree(MakeConstant(-1.0 * constBValue)); 577 577 return MakeFraction(MakeConstant(1.0), rootNode); 578 578 } else { 579 579 var rootNode = rootSymbol.CreateTreeNode(); 580 rootNode.AddSub Tree(a);581 rootNode.AddSub Tree(MakeConstant(constBValue));580 rootNode.AddSubtree(a); 581 rootNode.AddSubtree(MakeConstant(constBValue)); 582 582 return rootNode; 583 583 } 584 584 } else { 585 585 var rootNode = rootSymbol.CreateTreeNode(); 586 rootNode.AddSub Tree(a);587 rootNode.AddSub Tree(b);586 rootNode.AddSubtree(a); 587 rootNode.AddSubtree(b); 588 588 return rootNode; 589 589 } … … 605 605 } else if (exponent < 0) { 606 606 var powNode = powSymbol.CreateTreeNode(); 607 powNode.AddSub Tree(a);608 powNode.AddSub Tree(MakeConstant(-1.0 * exponent));607 powNode.AddSubtree(a); 608 powNode.AddSubtree(MakeConstant(-1.0 * exponent)); 609 609 return MakeFraction(MakeConstant(1.0), powNode); 610 610 } else { 611 611 var powNode = powSymbol.CreateTreeNode(); 612 powNode.AddSub Tree(a);613 powNode.AddSub Tree(MakeConstant(exponent));612 powNode.AddSubtree(a); 613 powNode.AddSubtree(MakeConstant(exponent)); 614 614 return powNode; 615 615 } 616 616 } else { 617 617 var powNode = powSymbol.CreateTreeNode(); 618 powNode.AddSub Tree(a);619 powNode.AddSub Tree(b);618 powNode.AddSubtree(a); 619 powNode.AddSubtree(b); 620 620 return powNode; 621 621 } … … 641 641 return MakeConstant(aVar.Weight / bVar.Weight); 642 642 } else if (IsAddition(a) && IsConstant(b)) { 643 return a.Sub Trees643 return a.Subtrees 644 644 .Select(x => GetSimplifiedTree(x)) 645 645 .Select(x => MakeFraction(x, b)) … … 649 649 } else if (IsDivision(a) && IsConstant(b)) { 650 650 // (a1 / a2) / c => (a1 / (a2 * c)) 651 Trace.Assert(a.Sub Trees.Count() == 2);652 return MakeFraction(a.GetSub Tree(0), MakeProduct(a.GetSubTree(1), b));651 Trace.Assert(a.Subtrees.Count() == 2); 652 return MakeFraction(a.GetSubtree(0), MakeProduct(a.GetSubtree(1), b)); 653 653 } else if (IsDivision(a) && IsDivision(b)) { 654 654 // (a1 / a2) / (b1 / b2) => 655 Trace.Assert(a.Sub Trees.Count() == 2);656 Trace.Assert(b.Sub Trees.Count() == 2);657 return MakeFraction(MakeProduct(a.GetSub Tree(0), b.GetSubTree(1)), MakeProduct(a.GetSubTree(1), b.GetSubTree(0)));655 Trace.Assert(a.Subtrees.Count() == 2); 656 Trace.Assert(b.Subtrees.Count() == 2); 657 return MakeFraction(MakeProduct(a.GetSubtree(0), b.GetSubtree(1)), MakeProduct(a.GetSubtree(1), b.GetSubtree(0))); 658 658 } else if (IsDivision(a)) { 659 659 // (a1 / a2) / b => (a1 / (a2 * b)) 660 Trace.Assert(a.Sub Trees.Count() == 2);661 return MakeFraction(a.GetSub Tree(0), MakeProduct(a.GetSubTree(1), b));660 Trace.Assert(a.Subtrees.Count() == 2); 661 return MakeFraction(a.GetSubtree(0), MakeProduct(a.GetSubtree(1), b)); 662 662 } else if (IsDivision(b)) { 663 663 // a / (b1 / b2) => (a * b2) / b1 664 Trace.Assert(b.Sub Trees.Count() == 2);665 return MakeFraction(MakeProduct(a, b.GetSub Tree(1)), b.GetSubTree(0));664 Trace.Assert(b.Subtrees.Count() == 2); 665 return MakeFraction(MakeProduct(a, b.GetSubtree(1)), b.GetSubtree(0)); 666 666 } else { 667 667 var div = divSymbol.CreateTreeNode(); 668 div.AddSub Tree(a);669 div.AddSub Tree(b);668 div.AddSubtree(a); 669 div.AddSubtree(b); 670 670 return div; 671 671 } … … 688 688 var add = addSymbol.CreateTreeNode(); 689 689 // add all sub trees except for the last 690 for (int i = 0; i < a.Sub Trees.Count() - 1; i++) add.AddSubTree(a.GetSubTree(i));691 for (int i = 0; i < b.Sub Trees.Count() - 1; i++) add.AddSubTree(b.GetSubTree(i));692 if (IsConstant(a.Sub Trees.Last()) && IsConstant(b.SubTrees.Last())) {693 add.AddSub Tree(MakeSum(a.SubTrees.Last(), b.SubTrees.Last()));694 } else if (IsConstant(a.Sub Trees.Last())) {695 add.AddSub Tree(b.SubTrees.Last());696 add.AddSub Tree(a.SubTrees.Last());697 } else { 698 add.AddSub Tree(a.SubTrees.Last());699 add.AddSub Tree(b.SubTrees.Last());690 for (int i = 0; i < a.Subtrees.Count() - 1; i++) add.AddSubtree(a.GetSubtree(i)); 691 for (int i = 0; i < b.Subtrees.Count() - 1; i++) add.AddSubtree(b.GetSubtree(i)); 692 if (IsConstant(a.Subtrees.Last()) && IsConstant(b.Subtrees.Last())) { 693 add.AddSubtree(MakeSum(a.Subtrees.Last(), b.Subtrees.Last())); 694 } else if (IsConstant(a.Subtrees.Last())) { 695 add.AddSubtree(b.Subtrees.Last()); 696 add.AddSubtree(a.Subtrees.Last()); 697 } else { 698 add.AddSubtree(a.Subtrees.Last()); 699 add.AddSubtree(b.Subtrees.Last()); 700 700 } 701 701 MergeVariablesInSum(add); 702 if (add.Sub Trees.Count() == 1) {703 return add.GetSub Tree(0);702 if (add.Subtrees.Count() == 1) { 703 return add.GetSubtree(0); 704 704 } else { 705 705 return add; … … 711 711 var add = addSymbol.CreateTreeNode(); 712 712 // add all sub trees except for the last 713 for (int i = 0; i < a.Sub Trees.Count() - 1; i++) add.AddSubTree(a.GetSubTree(i));714 if (IsConstant(a.Sub Trees.Last()))715 add.AddSub Tree(MakeSum(a.SubTrees.Last(), b));713 for (int i = 0; i < a.Subtrees.Count() - 1; i++) add.AddSubtree(a.GetSubtree(i)); 714 if (IsConstant(a.Subtrees.Last())) 715 add.AddSubtree(MakeSum(a.Subtrees.Last(), b)); 716 716 else { 717 add.AddSub Tree(a.SubTrees.Last());718 add.AddSub Tree(b);717 add.AddSubtree(a.Subtrees.Last()); 718 add.AddSubtree(b); 719 719 } 720 720 return add; … … 722 722 // a is already an addition => append b 723 723 var add = addSymbol.CreateTreeNode(); 724 add.AddSub Tree(b);725 foreach (var sub Tree in a.SubTrees) {726 add.AddSub Tree(subTree);724 add.AddSubtree(b); 725 foreach (var subtree in a.Subtrees) { 726 add.AddSubtree(subtree); 727 727 } 728 728 MergeVariablesInSum(add); 729 if (add.Sub Trees.Count() == 1) {730 return add.GetSub Tree(0);729 if (add.Subtrees.Count() == 1) { 730 return add.GetSubtree(0); 731 731 } else { 732 732 return add; … … 734 734 } else { 735 735 var add = addSymbol.CreateTreeNode(); 736 add.AddSub Tree(a);737 add.AddSub Tree(b);736 add.AddSubtree(a); 737 add.AddSubtree(b); 738 738 MergeVariablesInSum(add); 739 if (add.Sub Trees.Count() == 1) {740 return add.GetSub Tree(0);739 if (add.Subtrees.Count() == 1) { 740 return add.GetSubtree(0); 741 741 } else { 742 742 return add; … … 748 748 // possible improvement: combine sums of products where the products only reference the same variable 749 749 private void MergeVariablesInSum(ISymbolicExpressionTreeNode sum) { 750 var subtrees = new List<ISymbolicExpressionTreeNode>(sum.Sub Trees);751 while (sum.Sub Trees.Count() > 0) sum.RemoveSubTree(0);750 var subtrees = new List<ISymbolicExpressionTreeNode>(sum.Subtrees); 751 while (sum.Subtrees.Count() > 0) sum.RemoveSubtree(0); 752 752 var groupedVarNodes = from node in subtrees.OfType<VariableTreeNode>() 753 753 let lag = (node is LaggedVariableTreeNode) ? ((LaggedVariableTreeNode)node).Lag : 0 754 754 group node by node.VariableName + lag into g 755 755 select g; 756 var unchangedSub Trees = subtrees.Where(t => !(t is VariableTreeNode));756 var unchangedSubtrees = subtrees.Where(t => !(t is VariableTreeNode)); 757 757 758 758 foreach (var variableNodeGroup in groupedVarNodes) { … … 760 760 var representative = variableNodeGroup.First(); 761 761 representative.Weight = weightSum; 762 sum.AddSub Tree(representative);763 } 764 foreach (var unchangedSubtree in unchangedSub Trees)765 sum.AddSub Tree(unchangedSubtree);762 sum.AddSubtree(representative); 763 } 764 foreach (var unchangedSubtree in unchangedSubtrees) 765 sum.AddSubtree(unchangedSubtree); 766 766 } 767 767 … … 784 784 } else if (IsConstant(b) && IsAddition(a)) { 785 785 // multiply constants into additions 786 return a.Sub Trees.Select(x => MakeProduct(x, b)).Aggregate((c, d) => MakeSum(c, d));786 return a.Subtrees.Select(x => MakeProduct(x, b)).Aggregate((c, d) => MakeSum(c, d)); 787 787 } else if (IsDivision(a) && IsDivision(b)) { 788 788 // (a1 / a2) * (b1 / b2) => (a1 * b1) / (a2 * b2) 789 Trace.Assert(a.Sub Trees.Count() == 2);790 Trace.Assert(b.Sub Trees.Count() == 2);791 return MakeFraction(MakeProduct(a.GetSub Tree(0), b.GetSubTree(0)), MakeProduct(a.GetSubTree(1), b.GetSubTree(1)));789 Trace.Assert(a.Subtrees.Count() == 2); 790 Trace.Assert(b.Subtrees.Count() == 2); 791 return MakeFraction(MakeProduct(a.GetSubtree(0), b.GetSubtree(0)), MakeProduct(a.GetSubtree(1), b.GetSubtree(1))); 792 792 } else if (IsDivision(a)) { 793 793 // (a1 / a2) * b => (a1 * b) / a2 794 Trace.Assert(a.Sub Trees.Count() == 2);795 return MakeFraction(MakeProduct(a.GetSub Tree(0), b), a.GetSubTree(1));794 Trace.Assert(a.Subtrees.Count() == 2); 795 return MakeFraction(MakeProduct(a.GetSubtree(0), b), a.GetSubtree(1)); 796 796 } else if (IsDivision(b)) { 797 797 // a * (b1 / b2) => (b1 * a) / b2 798 Trace.Assert(b.Sub Trees.Count() == 2);799 return MakeFraction(MakeProduct(b.GetSub Tree(0), a), b.GetSubTree(1));798 Trace.Assert(b.Subtrees.Count() == 2); 799 return MakeFraction(MakeProduct(b.GetSubtree(0), a), b.GetSubtree(1)); 800 800 } else if (IsMultiplication(a) && IsMultiplication(b)) { 801 801 // merge multiplications (make sure constants are merged) 802 802 var mul = mulSymbol.CreateTreeNode(); 803 for (int i = 0; i < a.Sub Trees.Count(); i++) mul.AddSubTree(a.GetSubTree(i));804 for (int i = 0; i < b.Sub Trees.Count(); i++) mul.AddSubTree(b.GetSubTree(i));803 for (int i = 0; i < a.Subtrees.Count(); i++) mul.AddSubtree(a.GetSubtree(i)); 804 for (int i = 0; i < b.Subtrees.Count(); i++) mul.AddSubtree(b.GetSubtree(i)); 805 805 MergeVariablesAndConstantsInProduct(mul); 806 806 return mul; … … 809 809 } else if (IsMultiplication(a)) { 810 810 // a is already an multiplication => append b 811 a.AddSub Tree(b);811 a.AddSubtree(b); 812 812 MergeVariablesAndConstantsInProduct(a); 813 813 return a; 814 814 } else { 815 815 var mul = mulSymbol.CreateTreeNode(); 816 mul.AddSub Tree(a);817 mul.AddSub Tree(b);816 mul.AddSubtree(a); 817 mul.AddSubtree(b); 818 818 MergeVariablesAndConstantsInProduct(mul); 819 819 return mul; … … 842 842 // helper to combine the constant factors in products and to combine variables (powers of 2, 3...) 843 843 private void MergeVariablesAndConstantsInProduct(ISymbolicExpressionTreeNode prod) { 844 var subtrees = new List<ISymbolicExpressionTreeNode>(prod.Sub Trees);845 while (prod.Sub Trees.Count() > 0) prod.RemoveSubTree(0);844 var subtrees = new List<ISymbolicExpressionTreeNode>(prod.Subtrees); 845 while (prod.Subtrees.Count() > 0) prod.RemoveSubtree(0); 846 846 var groupedVarNodes = from node in subtrees.OfType<VariableTreeNode>() 847 847 let lag = (node is LaggedVariableTreeNode) ? ((LaggedVariableTreeNode)node).Lag : 0 … … 856 856 .Aggregate((c1, c2) => c1 * c2); 857 857 858 var unchangedSub Trees = from tree in subtrees858 var unchangedSubtrees = from tree in subtrees 859 859 where !(tree is VariableTreeNode) 860 860 where !(tree is ConstantTreeNode) … … 867 867 var poly = mulSymbol.CreateTreeNode(); 868 868 for (int p = 0; p < variableNodeGroup.Count(); p++) { 869 poly.AddSub Tree((ISymbolicExpressionTreeNode)representative.Clone());869 poly.AddSubtree((ISymbolicExpressionTreeNode)representative.Clone()); 870 870 } 871 prod.AddSub Tree(poly);872 } else { 873 prod.AddSub Tree(representative);874 } 875 } 876 877 foreach (var unchangedSubtree in unchangedSub Trees)878 prod.AddSub Tree(unchangedSubtree);871 prod.AddSubtree(poly); 872 } else { 873 prod.AddSubtree(representative); 874 } 875 } 876 877 foreach (var unchangedSubtree in unchangedSubtrees) 878 prod.AddSubtree(unchangedSubtree); 879 879 880 880 if (!constantProduct.IsAlmost(1.0)) { 881 prod.AddSub Tree(MakeConstant(constantProduct));881 prod.AddSubtree(MakeConstant(constantProduct)); 882 882 } 883 883 } … … 898 898 } else if (IsAddition(x)) { 899 899 // (x0 + x1 + .. + xn) * -1 => (-x0 + -x1 + .. + -xn) 900 List<ISymbolicExpressionTreeNode> sub Trees = new List<ISymbolicExpressionTreeNode>(x.SubTrees);901 while (x.Sub Trees.Count() > 0) x.RemoveSubTree(0);902 foreach (var sub Tree in subTrees) {903 x.AddSub Tree(Negate(subTree));900 List<ISymbolicExpressionTreeNode> subtrees = new List<ISymbolicExpressionTreeNode>(x.Subtrees); 901 while (x.Subtrees.Count() > 0) x.RemoveSubtree(0); 902 foreach (var subtree in subtrees) { 903 x.AddSubtree(Negate(subtree)); 904 904 } 905 905 } else if (IsMultiplication(x) || IsDivision(x)) { 906 906 // x0 * x1 * .. * xn * -1 => x0 * x1 * .. * -xn 907 x.RemoveSub Tree(x.SubTrees.Count() - 1);908 x.AddSub Tree(Negate(x.SubTrees.Last())); // last is maybe a constant, prefer to negate the constant907 x.RemoveSubtree(x.Subtrees.Count() - 1); 908 x.AddSubtree(Negate(x.Subtrees.Last())); // last is maybe a constant, prefer to negate the constant 909 909 } else { 910 910 // any other function … … 924 924 return MakeConstant(1.0 / ((ConstantTreeNode)x).Value); 925 925 } else if (IsDivision(x)) { 926 Trace.Assert(x.Sub Trees.Count() == 2);927 return MakeFraction(x.GetSub Tree(1), x.GetSubTree(0));926 Trace.Assert(x.Subtrees.Count() == 2); 927 return MakeFraction(x.GetSubtree(1), x.GetSubtree(0)); 928 928 } else { 929 929 // any other function -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisProblem.cs
r5726 r5733 38 38 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 39 39 [StorableClass] 40 public abstract class SymbolicDataAnalysisProblem<T, U, V> : HeuristicOptimizationProblem<U, V>, I SymbolicDataAnalysisProblem, IStorableContent40 public abstract class SymbolicDataAnalysisProblem<T, U, V> : HeuristicOptimizationProblem<U, V>, IDataAnalysisProblem, IStorableContent 41 41 where T : class,IDataAnalysisProblemData 42 42 where U : class, ISymbolicDataAnalysisEvaluator<T> … … 50 50 private const string MaximumFunctionDefinitionsParameterName = "MaximumFunctionDefinitions"; 51 51 private const string MaximumFunctionArgumentsParameterName = "MaximumFunctionArguments"; 52 private const string RelativeNumberOfEvaluatedSamples = "RelativeNumberOfEvaluatedSamples"; 53 private const string FitnessCalculationPartitionParameterName = "FitnessCalculationPartition"; 54 private const string ModelSelectionPartitionParamterName = "ModelSelectionPartition"; 52 55 53 56 private const string ProblemDataParameterDescription = ""; -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tests/SymbolicExpressionImporter.cs
r5574 r5733 76 76 } else { 77 77 // only a main branch was given => insert the main branch into the default tree template 78 root.AddSub Tree(start);79 start.AddSub Tree(mainBranch);78 root.AddSubtree(start); 79 start.AddSubtree(mainBranch); 80 80 } 81 81 return new SymbolicExpressionTree(root); … … 99 99 tree = ParseDefun(tokens); 100 100 while (!tokens.Peek().Equals(Token.RPAR)) { 101 tree.AddSub Tree(ParseSexp(tokens));101 tree.AddSubtree(ParseSexp(tokens)); 102 102 } 103 103 } else if (tokens.Peek().StringValue.StartsWith(ARGSTART)) { … … 106 106 tree = ParseInvoke(tokens); 107 107 while (!tokens.Peek().Equals(Token.RPAR)) { 108 tree.AddSub Tree(ParseSexp(tokens));108 tree.AddSubtree(ParseSexp(tokens)); 109 109 } 110 110 } else { … … 112 112 tree = CreateTree(curToken); 113 113 while (!tokens.Peek().Equals(Token.RPAR)) { 114 tree.AddSub Tree(ParseSexp(tokens));114 tree.AddSubtree(ParseSexp(tokens)); 115 115 } 116 116 }
Note: See TracChangeset
for help on using the changeset viewer.