Changeset 6888
- Timestamp:
- 10/07/11 21:25:02 (13 years ago)
- Location:
- trunk/sources
- Files:
-
- 5 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/FullTreeCreator.cs
r6887 r6888 51 51 52 52 public IValueLookupParameter<ISymbolicExpressionGrammar> SymbolicExpressionTreeGrammarParameter { 53 get { 54 return 55 (IValueLookupParameter<ISymbolicExpressionGrammar>) 56 Parameters[SymbolicExpressionTreeGrammarParameterName]; 57 } 53 get { return (IValueLookupParameter<ISymbolicExpressionGrammar>)Parameters[SymbolicExpressionTreeGrammarParameterName]; } 58 54 } 59 55 60 56 public ILookupParameter<ISymbolicExpressionGrammar> ClonedSymbolicExpressionTreeGrammarParameter { 61 get { 62 return 63 (ILookupParameter<ISymbolicExpressionGrammar>) 64 Parameters[ClonedSymbolicExpressionTreeGrammarParameterName]; 65 } 57 get { return (ILookupParameter<ISymbolicExpressionGrammar>)Parameters[ClonedSymbolicExpressionTreeGrammarParameterName]; } 66 58 } 67 59 … … 144 136 145 137 int arity = seedNode.Grammar.GetMaximumSubtreeCount(seedNode.Symbol); 146 if (arity <= 0) return; // should never happen 138 // Throw an exception if the seedNode happens to be a terminal, since in this case we cannot grow a tree. 139 if (arity <= 0) 140 throw new ArgumentException("Cannot grow tree. Seed node shouldn't have arity zero."); 147 141 148 142 for (var i = 0; i != arity; ++i) { … … 153 147 } 154 148 155 foreach (var subTree in seedNode.Subtrees) { 156 RecursiveGrowFull(random, subTree, 0, maxDepth); 157 } 149 // Only iterate over the non-terminal nodes (those which have arity > 0) 150 // Start from depth 2 since the first two levels are formed by the rootNode and the seedNode 151 foreach (var subTree in seedNode.Subtrees.Where(subTree => subTree.Grammar.GetMaximumSubtreeCount(subTree.Symbol) != 0)) 152 RecursiveGrowFull(random, subTree, 2, maxDepth); 158 153 } 159 154 160 155 public static void RecursiveGrowFull(IRandom random, ISymbolicExpressionTreeNode root, int currentDepth, int maxDepth) { 161 156 var arity = root.Grammar.GetMaximumSubtreeCount(root.Symbol); 162 if (arity <= 0) return; 157 // In the 'Full' grow method, we cannot have terminals on the intermediate tree levels. 158 if (arity <= 0) 159 throw new ArgumentException("Cannot grow node of arity zero. Expected a function node."); 163 160 164 161 var possibleSymbols = currentDepth < maxDepth ? … … 173 170 } 174 171 175 foreach (var tree in root.Subtrees)176 RecursiveGrowFull(random, tree, currentDepth + 1, maxDepth);172 foreach (var subTree in root.Subtrees.Where(subTree => subTree.Grammar.GetMaximumSubtreeCount(subTree.Symbol) != 0)) 173 RecursiveGrowFull(random, subTree, currentDepth + 1, maxDepth); 177 174 } 178 175 } -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/GrowTreeCreator.cs
r6887 r6888 55 55 56 56 public ILookupParameter<ISymbolicExpressionGrammar> ClonedSymbolicExpressionTreeGrammarParameter { 57 get { 58 return 59 (ILookupParameter<ISymbolicExpressionGrammar>) 60 Parameters[ClonedSymbolicExpressionTreeGrammarParameterName]; 61 } 57 get { return (ILookupParameter<ISymbolicExpressionGrammar>)Parameters[ClonedSymbolicExpressionTreeGrammarParameterName]; } 62 58 } 63 59 … … 137 133 138 134 var arity = SampleArity(random, seedNode); 139 if (arity <= 0) return; // maybe throw an exception here? But this should never happen. 135 // throw an exception if the seedNode happens to be a terminal, since in this case we cannot grow a tree 136 if (arity <= 0) 137 throw new ArgumentException("Cannot grow tree. Seed node shouldn't have arity zero."); 140 138 141 139 var possibleSymbols = seedNode.Grammar.GetAllowedChildSymbols(seedNode.Symbol).Where(s => s.InitialFrequency > 0.0).ToList(); … … 148 146 } 149 147 150 foreach (var subTree in seedNode.Subtrees) { 151 RecursiveGrow(random, subTree, 0, maxDepth); 152 } 148 // Only iterate over the non-terminal nodes (those which have arity > 0) 149 // Start from depth 2 since the first two levels are formed by the rootNode and the seedNode 150 foreach (var subTree in seedNode.Subtrees.Where(subTree => subTree.Grammar.GetMaximumSubtreeCount(subTree.Symbol) != 0)) 151 RecursiveGrow(random, subTree, 2, maxDepth); 153 152 } 154 153 155 154 public static void RecursiveGrow(IRandom random, ISymbolicExpressionTreeNode root, int currentDepth, int maxDepth) { 156 155 var arity = SampleArity(random, root); 157 if (arity <= 0) return; 156 if (arity <= 0) 157 throw new ArgumentException("Cannot grow node of arity zero. Expected a function node."); 158 158 159 159 var possibleSymbols = currentDepth < maxDepth ? … … 168 168 } 169 169 170 foreach (var subTree in root.Subtrees ) {170 foreach (var subTree in root.Subtrees.Where(subTree => subTree.Grammar.GetMaximumSubtreeCount(subTree.Symbol) != 0)) 171 171 RecursiveGrow(random, subTree, currentDepth + 1, maxDepth); 172 }173 172 } 174 173 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj
r6866 r6888 121 121 <Compile Include="Analyzers\SymbolicDataAnalysisVariableFrequencyAnalyzer.cs" /> 122 122 <Compile Include="Analyzers\SymbolicDataAnalysisAlleleFrequencyAnalyzer.cs" /> 123 <Compile Include="SymbolicDataAnalysisExpressionFullTreeCreator.cs" /> 123 124 <Compile Include="Plugin.cs" /> 125 <Compile Include="SymbolicDataAnalysisExpressionGrowTreeCreator.cs" /> 126 <Compile Include="SymbolicDataAnalysisExpressionRampedHalfAndHalfTreeCreator.cs" /> 124 127 <Compile Include="SymbolicDataAnalysisExpressionTreeILEmittingInterpreter.cs" /> 125 128 <Compile Include="Formatters\SymbolicDataAnalysisExpressionLatexFormatter.cs" /> -
trunk/sources/HeuristicLab.Tests/HeuristicLab.Tests.csproj
r6882 r6888 236 236 <Compile Include="HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4\ArgumentDuplicaterTest.cs" /> 237 237 <Compile Include="HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4\ChangeNodeTypeManipulationTest.cs" /> 238 <Compile Include="HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4\FullTreeCreatorTest.cs" /> 238 239 <Compile Include="HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4\Grammars.cs" /> 240 <Compile Include="HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4\GrowTreeCreatorTest.cs" /> 239 241 <Compile Include="HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4\ProbabilisticTreeCreaterTest.cs" /> 240 242 <Compile Include="HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4\ReplaceBranchManipulationTest.cs" />
Note: See TracChangeset
for help on using the changeset viewer.