Changeset 3237 for trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Creators/ProbabilisticTreeCreator.cs
- Timestamp:
- 03/30/10 19:38:22 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Creators/ProbabilisticTreeCreator.cs
r3223 r3237 51 51 do { 52 52 try { 53 // determine possible root symbols to create a tree of the target size 54 var possibleRootSymbols = from symbol in grammar.AllowedSymbols(grammar.StartSymbol, 0) 55 where treeSize <= grammar.MaximalExpressionLength(symbol) 56 where treeSize >= grammar.MinimalExpressionLength(symbol) 57 select symbol; 58 Symbol rootSymbol = SelectRandomSymbol(random, possibleRootSymbols); 59 tree.Root = PTC2(random, grammar, rootSymbol, treeSize, maxTreeHeight); 53 tree.Root = PTC2(random, grammar, grammar.StartSymbol, treeSize+1, maxTreeHeight+1); 54 //// determine possible root symbols to create a tree of the target size 55 //var possibleRootSymbols = from symbol in grammar.AllowedSymbols(grammar.StartSymbol, 0) 56 // where treeSize <= grammar.MaximalExpressionLength(symbol) 57 // where treeSize >= grammar.MinimalExpressionLength(symbol) 58 // select symbol; 59 //Symbol rootSymbol = SelectRandomSymbol(random, possibleRootSymbols); 60 //tree.Root = PTC2(random, grammar, rootSymbol, treeSize, maxTreeHeight); 60 61 } 61 62 catch (ArgumentException) { … … 149 150 int minArity = grammar.MinSubTrees(symbol); 150 151 int maxArity = grammar.MaxSubTrees(symbol); 151 if (maxArity > =targetSize) {152 if (maxArity > targetSize) { 152 153 maxArity = targetSize; 153 154 } 154 155 // the min number of sub-trees has to be set to a value that is large enough so that the largest possible tree is at least tree size 155 156 // if 1..3 trees are possible and the largest possible first sub-tree is smaller larger than the target size then minArity should be at least 2 156 int aggregatedLongestExpressionLength = 1;157 long aggregatedLongestExpressionLength = 0; 157 158 for (int i = 0; i < maxArity; i++) { 158 159 aggregatedLongestExpressionLength += (from s in grammar.AllowedSymbols(symbol, i) 159 select grammar.MaximalExpressionLength(s ymbol)).Max();160 select grammar.MaximalExpressionLength(s)).Max(); 160 161 if (aggregatedLongestExpressionLength < targetSize) minArity = i; 161 162 else break; … … 164 165 // the max number of sub-trees has to be set to a value that is small enough so that the smallest possible tree is at most tree size 165 166 // if 1..3 trees are possible and the smallest possible first sub-tree is already larger than the target size then maxArity should be at most 0 166 int aggregatedShortestExpressionLength = 1;167 long aggregatedShortestExpressionLength = 0; 167 168 for (int i = 0; i < maxArity; i++) { 168 169 aggregatedShortestExpressionLength += (from s in grammar.AllowedSymbols(symbol, i) 169 select grammar.MinimalExpressionLength(s ymbol)).Min();170 select grammar.MinimalExpressionLength(s)).Min(); 170 171 if (aggregatedShortestExpressionLength > targetSize) { 171 172 maxArity = i;
Note: See TracChangeset
for help on using the changeset viewer.