Changeset 7108
- Timestamp:
- 12/01/11 16:53:12 (13 years ago)
- Location:
- trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/FullTreeCreator.cs
r7076 r7108 148 148 throw new ArgumentException("Cannot grow tree. Seed node shouldn't have arity zero."); 149 149 150 var allowedSymbols = seedNode.Grammar.AllowedSymbols.Where(s => s.InitialFrequency > 0.0 && seedNode.Grammar.GetMaximumSubtreeCount(s) > 0).ToList(); 151 150 152 for (var i = 0; i != arity; ++i) { 151 var possibleSymbols = seedNode.Grammar.GetAllowedChildSymbols(seedNode.Symbol, i).Where(s => s.InitialFrequency > 0.0 && seedNode.Grammar.GetMaximumSubtreeCount(s) > 0);153 var possibleSymbols = allowedSymbols.Where(s => seedNode.Grammar.IsAllowedChildSymbol(seedNode.Symbol, s, i)).ToList(); 152 154 var selectedSymbol = possibleSymbols.SelectRandom(random); 153 155 var tree = selectedSymbol.CreateTreeNode(); … … 158 160 // Only iterate over the non-terminal nodes (those which have arity > 0) 159 161 // Start from depth 2 since the first two levels are formed by the rootNode and the seedNode 160 foreach (var subTree in seedNode.Subtrees.Where(subTree => subTree.Grammar.GetMaximumSubtreeCount(subTree.Symbol) !=0))162 foreach (var subTree in seedNode.Subtrees.Where(subTree => subTree.Grammar.GetMaximumSubtreeCount(subTree.Symbol) > 0)) 161 163 RecursiveGrowFull(random, subTree, 2, maxDepth); 162 164 } … … 168 170 throw new ArgumentException("Cannot grow node of arity zero. Expected a function node."); 169 171 172 var allowedSymbols = root.Grammar.AllowedSymbols.Where(s => s.InitialFrequency > 0.0).ToList(); ; 173 170 174 for (var i = 0; i != arity; ++i) { 171 var possibleSymbols = root.Grammar.GetAllowedChildSymbols(root.Symbol, i); 172 possibleSymbols = possibleSymbols.Where(s => s.InitialFrequency > 0.0 && 173 root.Grammar.GetMinimumExpressionDepth(s) - 1 <= maxDepth - currentDepth && 174 root.Grammar.GetMaximumExpressionDepth(s) > maxDepth - currentDepth); 175 var possibleSymbols = allowedSymbols.Where(s => root.Grammar.IsAllowedChildSymbol(root.Symbol, s, i) && 176 root.Grammar.GetMinimumExpressionDepth(s) - 1 <= maxDepth - currentDepth && 177 root.Grammar.GetMaximumExpressionDepth(s) > maxDepth - currentDepth).ToList(); 178 if (!possibleSymbols.Any()) 179 throw new InvalidOperationException("No symbols are available for the tree."); 175 180 176 177 if (!possibleSymbols.Any()) throw new InvalidOperationException("No symbols are available for the tree.");178 181 var selectedSymbol = possibleSymbols.SelectRandom(random); 179 182 var tree = selectedSymbol.CreateTreeNode(); … … 182 185 } 183 186 184 foreach (var subTree in root.Subtrees.Where(subTree => subTree.Grammar.GetMaximumSubtreeCount(subTree.Symbol) !=0))187 foreach (var subTree in root.Subtrees.Where(subTree => subTree.Grammar.GetMaximumSubtreeCount(subTree.Symbol) > 0)) 185 188 RecursiveGrowFull(random, subTree, currentDepth + 1, maxDepth); 186 189 } -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/GrowTreeCreator.cs
r7076 r7108 146 146 throw new ArgumentException("Cannot grow tree. Seed node shouldn't have arity zero."); 147 147 148 var allowedSymbols = seedNode.Grammar.AllowedSymbols.Where(s => s.InitialFrequency > 0.0).ToList(); 148 149 149 150 for (var i = 0; i != arity; ++i) { 150 var possibleSymbols = seedNode.Grammar.GetAllowedChildSymbols(seedNode.Symbol, i).Where(s => s.InitialFrequency > 0.0);151 var possibleSymbols = allowedSymbols.Where(s => seedNode.Grammar.IsAllowedChildSymbol(seedNode.Symbol, s, i)).ToList(); 151 152 var selectedSymbol = possibleSymbols.SelectRandom(random); 152 153 var tree = selectedSymbol.CreateTreeNode(); … … 157 158 // Only iterate over the non-terminal nodes (those which have arity > 0) 158 159 // Start from depth 2 since the first two levels are formed by the rootNode and the seedNode 159 foreach (var subTree in seedNode.Subtrees.Where(subTree => subTree.Grammar.GetMaximumSubtreeCount(subTree.Symbol) !=0))160 foreach (var subTree in seedNode.Subtrees.Where(subTree => subTree.Grammar.GetMaximumSubtreeCount(subTree.Symbol) > 0)) 160 161 RecursiveGrow(random, subTree, 2, maxDepth); 161 162 } … … 166 167 throw new ArgumentException("Cannot grow node of arity zero. Expected a function node."); 167 168 169 var allowedSymbols = root.Grammar.AllowedSymbols.Where(s => s.InitialFrequency > 0.0).ToList(); 170 168 171 for (var i = 0; i != arity; ++i) { 169 var possibleSymbols = root.Grammar.GetAllowedChildSymbols(root.Symbol, i); 170 possibleSymbols = possibleSymbols.Where(s => s.InitialFrequency > 0.0 && 171 root.Grammar.GetMinimumExpressionDepth(s) - 1 <= maxDepth - currentDepth); 172 if (!possibleSymbols.Any()) throw new InvalidOperationException("No symbols are available for the tree."); 172 var possibleSymbols = allowedSymbols.Where(s => root.Grammar.IsAllowedChildSymbol(root.Symbol, s, i) && root.Grammar.GetMinimumExpressionDepth(s) - 1 <= maxDepth - currentDepth).ToList(); 173 if (!possibleSymbols.Any()) 174 throw new InvalidOperationException("No symbols are available for the tree."); 173 175 var selectedSymbol = possibleSymbols.SelectRandom(random); 174 176 var tree = selectedSymbol.CreateTreeNode();
Note: See TracChangeset
for help on using the changeset viewer.