Changeset 5529 for branches/DataAnalysis Refactoring
- Timestamp:
- 02/21/11 17:49:23 (14 years ago)
- Location:
- branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/ArgumentCreater.cs
r5510 r5529 180 180 subtree.Grammar.SetMinSubtreeCount(matchingSymbol, defunBranch.NumberOfArguments); 181 181 subtree.Grammar.SetMaxSubtreeCount(matchingSymbol, defunBranch.NumberOfArguments); 182 foreach (var child in subtree.G etAllowedSymbols(0)) {182 foreach (var child in subtree.Grammar.GetAllowedSymbols(subtree.Symbol, 0)) { 183 183 for (int i = 0; i < subtree.Grammar.GetMaxSubtreeCount(matchingSymbol); i++) { 184 184 subtree.Grammar.SetAllowedChild(matchingSymbol, child, i); -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/ArgumentDuplicater.cs
r5510 r5529 124 124 subtree.Grammar.SetMinSubtreeCount(matchingInvokeSymbol, selectedDefunBranch.NumberOfArguments); 125 125 subtree.Grammar.SetMaxSubtreeCount(matchingInvokeSymbol, selectedDefunBranch.NumberOfArguments); 126 foreach (var child in subtree.G etAllowedSymbols(0)) {126 foreach (var child in subtree.Grammar.GetAllowedSymbols(subtree.Symbol, 0)) { 127 127 for (int i = 0; i < subtree.Grammar.GetMaxSubtreeCount(matchingInvokeSymbol); i++) { 128 128 subtree.Grammar.SetAllowedChild(matchingInvokeSymbol, child, i); -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/SubroutineDeleter.cs
r5510 r5529 91 91 // deletion by random regeneration 92 92 ISymbolicExpressionTreeNode replacementTree = null; 93 var allowedSymbolsList = invocationCutPoint.Parent.G etAllowedSymbols(invocationCutPoint.ReplacedChildIndex).ToList();93 var allowedSymbolsList = invocationCutPoint.Parent.Grammar.GetAllowedSymbols(invocationCutPoint.Parent.Symbol, invocationCutPoint.ReplacedChildIndex).ToList(); 94 94 var weights = allowedSymbolsList.Select(s => s.InitialFrequency); 95 95 var selectedSymbol = allowedSymbolsList.SelectRandom(weights, random); -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/ProbabilisticTreeCreator.cs
r5521 r5529 216 216 int argumentIndex, int maxFunctionDefinitions, int maxFunctionArguments) { 217 217 // determine possible symbols that will lead to the smallest possible tree 218 var possibleSymbols = (from s in parent.G etAllowedSymbols(argumentIndex)218 var possibleSymbols = (from s in parent.Grammar.GetAllowedSymbols(parent.Symbol, argumentIndex) 219 219 group s by parent.Grammar.GetMinExpressionLength(s) into g 220 220 orderby g.Key … … 227 227 parent.InsertSubTree(argumentIndex, tree); 228 228 InitializeNewTreeNode(random, root, tree, maxFunctionDefinitions, maxFunctionArguments); 229 for (int i = 0; i < tree.G etMinSubtreeCount(); i++) {229 for (int i = 0; i < tree.Grammar.GetMinSubtreeCount(tree.Symbol); i++) { 230 230 // insert a dummy sub-tree and add the pending extension to the list 231 231 var dummy = new SymbolicExpressionTreeNode(); … … 285 285 private static int SampleArity(IRandom random, ISymbolicExpressionTreeNode node, int targetSize) { 286 286 // select actualArity randomly with the constraint that the sub-trees in the minimal arity can become large enough 287 int minArity = node.G etMinSubtreeCount();288 int maxArity = node.G etMaxSubtreeCount();287 int minArity = node.Grammar.GetMinSubtreeCount(node.Symbol); 288 int maxArity = node.Grammar.GetMaxSubtreeCount(node.Symbol); 289 289 if (maxArity > targetSize) { 290 290 maxArity = targetSize; … … 294 294 long aggregatedLongestExpressionLength = 0; 295 295 for (int i = 0; i < maxArity; i++) { 296 aggregatedLongestExpressionLength += (from s in node.G etAllowedSymbols(i)296 aggregatedLongestExpressionLength += (from s in node.Grammar.GetAllowedSymbols(node.Symbol, i) 297 297 select node.Grammar.GetMaxExpressionLength(s)).Max(); 298 298 if (aggregatedLongestExpressionLength < targetSize) minArity = i; … … 304 304 long aggregatedShortestExpressionLength = 0; 305 305 for (int i = 0; i < maxArity; i++) { 306 aggregatedShortestExpressionLength += (from s in node.G etAllowedSymbols(i)306 aggregatedShortestExpressionLength += (from s in node.Grammar.GetAllowedSymbols(node.Symbol, i) 307 307 select node.Grammar.GetMinExpressionLength(s)).Min(); 308 308 if (aggregatedShortestExpressionLength > targetSize) { -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/DefaultSymbolicExpressionGrammar.cs
r5510 r5529 229 229 } 230 230 231 public IEnumerable<ISymbol> GetAllowedSymbols(ISymbol parent, int argumentIndex) { 232 return allowedChildSymbols[parent.Name][argumentIndex].Select(x => allSymbols[x]); 233 } 234 231 235 private Dictionary<string, int> cachedMinExpressionLength; 232 236 public int GetMinExpressionLength(ISymbol symbol) { -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/ISymbolicExpressionTreeGrammar.cs
r5519 r5529 34 34 bool IsAllowedChild(ISymbol parent, ISymbol child, int argumentIndex); 35 35 36 IEnumerable<ISymbol> GetAllowedSymbols(ISymbol parent, int argumentIndex); 37 36 38 int GetMinExpressionLength(ISymbol start); 37 39 int GetMaxExpressionLength(ISymbol start); -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/ISymbolicExpressionTreeNode.cs
r5510 r5529 29 29 ISymbol Symbol { get; } 30 30 bool HasLocalParameters { get; } 31 IEnumerable<ISymbol> GetAllowedSymbols(int argumentIndex);32 31 33 32 int GetHeight(); 34 33 int GetSize(); 35 int GetMinSubtreeCount();36 int GetMaxSubtreeCount();37 34 38 35 IEnumerable<ISymbolicExpressionTreeNode> IterateNodesPostfix(); -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/ChangeNodeTypeManipulation.cs
r5510 r5529 54 54 int subTreeCount = manipulationPoint.Node.SubTrees.Count(); 55 55 // find possible symbols for the node (also considering the existing branches below it) 56 var allowedSymbols = from symbol in manipulationPoint.Parent.G etAllowedSymbols(manipulationPoint.Index)56 var allowedSymbols = from symbol in manipulationPoint.Parent.Grammar.GetAllowedSymbols(manipulationPoint.Parent.Symbol, manipulationPoint.Index) 57 57 where subTreeCount <= manipulationPoint.Node.Grammar.GetMaxSubtreeCount(symbol) 58 58 where subTreeCount >= manipulationPoint.Node.Grammar.GetMinSubtreeCount(symbol) -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/ReplaceBranchManipulation.cs
r5499 r5529 79 79 int maxDepth = maxTreeDepth - symbolicExpressionTree.Height + manipulationPoint.Node.GetHeight(); 80 80 // find possible symbols for the node (also considering the existing branches below it) 81 var allowedSymbols = (from symbol in manipulationPoint.Parent.G etAllowedSymbols(manipulationPoint.Index)81 var allowedSymbols = (from symbol in manipulationPoint.Parent.Grammar.GetAllowedSymbols(manipulationPoint.Parent.Symbol, manipulationPoint.Index) 82 82 where manipulationPoint.Node.Grammar.GetMinExpressionDepth(symbol) <= maxDepth 83 83 where manipulationPoint.Node.Grammar.GetMinExpressionLength(symbol) <= maxLength -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeNode.cs
r5510 r5529 178 178 } 179 179 180 public IEnumerable<ISymbol> GetAllowedSymbols(int argumentIndex) {181 return Grammar.Symbols.Where(s => Grammar.IsAllowedChild(Symbol, s, argumentIndex));182 }183 184 public int GetMinSubtreeCount() {185 return Grammar.GetMinSubtreeCount(Symbol);186 }187 public int GetMaxSubtreeCount() {188 return Grammar.GetMaxSubtreeCount(Symbol);189 }190 180 public override string ToString() { 191 181 return Symbol.Name;
Note: See TracChangeset
for help on using the changeset viewer.