Changeset 10075
- Timestamp:
- 10/21/13 11:29:55 (11 years ago)
- Location:
- branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Mappers/DepthFirstMapper.cs
r10068 r10075 25 25 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 26 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 using HeuristicLab.Random; 27 28 28 29 namespace HeuristicLab.Problems.GrammaticalEvolution { … … 56 57 SymbolicExpressionTree tree = new SymbolicExpressionTree(); 57 58 var rootNode = (SymbolicExpressionTreeTopLevelNode)grammar.ProgramRootSymbol.CreateTreeNode(); 59 if (rootNode.HasLocalParameters) rootNode.ResetLocalParameters(new MersenneTwister()); 58 60 var startNode = (SymbolicExpressionTreeTopLevelNode)grammar.StartSymbol.CreateTreeNode(); 61 if (startNode.HasLocalParameters) startNode.ResetLocalParameters(new MersenneTwister()); 59 62 rootNode.AddSubtree(startNode); 60 63 tree.Root = rootNode; … … 96 99 var newNode = GetNewChildNode(currentNode, genotype, grammar, genotypeIndex); 97 100 98 if ((currSubtreeCount + newNode.Symbol.M aximumArity) > maxSubtreeCount) {101 if ((currSubtreeCount + newNode.Symbol.MinimumArity) > maxSubtreeCount) { 99 102 // TODO: maybe check, if there is any node, which fits in the tree yet 100 103 currentNode.AddSubtree(GetRandomTerminalNode(currentNode, grammar)); … … 102 105 currentNode.AddSubtree(newNode); 103 106 genotypeIndex++; 104 currSubtreeCount += newNode.Symbol.M aximumArity;107 currSubtreeCount += newNode.Symbol.MinimumArity; 105 108 106 while (newNode.Symbol.M aximumArity > newNode.SubtreeCount) {109 while (newNode.Symbol.MinimumArity > newNode.SubtreeCount) { 107 110 MapDepthFirstRecursively(newNode, genotype, 108 111 grammar, maxSubtreeCount, … … 112 115 113 116 } else { 114 while (currentNode.Symbol.M aximumArity > currentNode.SubtreeCount) {117 while (currentNode.Symbol.MinimumArity > currentNode.SubtreeCount) { 115 118 var newNode = GetNewChildNode(currentNode, genotype, grammar, genotypeIndex); 116 119 currentNode.AddSubtree(newNode); 117 120 genotypeIndex++; 118 while (newNode.Symbol.M aximumArity > newNode.SubtreeCount) {121 while (newNode.Symbol.MinimumArity > newNode.SubtreeCount) { 119 122 newNode.AddSubtree(GetRandomTerminalNode(newNode, grammar)); 120 123 } -
branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Mappers/GenotypeToPhenotypeMapper.cs
r10068 r10075 52 52 protected ISymbolicExpressionTreeNode GetRandomTerminalNode(ISymbolicExpressionTreeNode parentNode, 53 53 ISymbolicExpressionGrammar grammar) { 54 var possibleSymbolsList = from s in grammar.GetAllowedChildSymbols(parentNode.Symbol) 55 where s.MaximumArity == 0 56 where s.MinimumArity == 0 57 select s; 58 // TODO: Check, if symbol list is empty (no terminal nodes found) - what should happen? 59 return possibleSymbolsList.SelectRandom(new MersenneTwister()).CreateTreeNode(); 54 // only select specific symbols, which can be interpreted ... 55 var possibleSymbolsList = (from s in grammar.GetAllowedChildSymbols(parentNode.Symbol) 56 where s.InitialFrequency > 0.0 57 where s.MaximumArity == 0 58 where s.MinimumArity == 0 59 select s).ToList(); 60 // TODO: Check, if symbol list is empty (no terminal nodes found) - what should happen? 61 var newNode = possibleSymbolsList.SelectRandom(new MersenneTwister()).CreateTreeNode(); 62 if (newNode.HasLocalParameters) newNode.ResetLocalParameters(new MersenneTwister()); 63 return newNode; 60 64 } 61 65 … … 74 78 int genotypeIndex) { 75 79 76 IEnumerable<ISymbol> symbolList = grammar.GetAllowedChildSymbols(parentNode.Symbol); 80 // only select specific symbols, which can be interpreted ... 81 IEnumerable<ISymbol> symbolList = (from s in grammar.GetAllowedChildSymbols(parentNode.Symbol) 82 where s.InitialFrequency > 0.0 83 select s).ToList(); 77 84 int prodRuleCount = symbolList.Count(); 78 85 int prodRuleIndex = genotype[genotypeIndex % genotype.Length] % prodRuleCount; 79 86 80 return symbolList.ElementAt(prodRuleIndex).CreateTreeNode(); 87 var newNode = symbolList.ElementAt(prodRuleIndex).CreateTreeNode(); 88 if (newNode.HasLocalParameters) newNode.ResetLocalParameters(new MersenneTwister()); 89 return newNode; 81 90 } 82 91 } -
branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/GESymbolicDataAnalysisProblem.cs
r10073 r10075 41 41 [StorableClass] 42 42 // TODO: ISymbolicDataAnalysisProblem -> IGESymbolicDataAnalysisProblem 43 public abstract class GESymbolicDataAnalysisProblem<T, U, V> : HeuristicOptimizationProblem<U, V>, IDataAnalysisProblem<T>, ISymbolicDataAnalysisProblem, IStorableContent, 44 IProblemInstanceConsumer<T>, IProblemInstanceExporter<T> 43 public abstract class GESymbolicDataAnalysisProblem<T, U, V> : HeuristicOptimizationProblem<U, V>, IDataAnalysisProblem<T>, 44 ISymbolicDataAnalysisProblem, IStorableContent, 45 IProblemInstanceConsumer<T>, IProblemInstanceExporter<T> 45 46 where T : class, IDataAnalysisProblemData 46 47 where U : class, IGESymbolicDataAnalysisEvaluator<T> … … 244 245 private void InitializeOperators() { 245 246 Operators.AddRange(ApplicationManager.Manager.GetInstances<IIntegerVectorOperator>().OfType<IOperator>()); 246 Operators.AddRange(ApplicationManager.Manager.GetInstances<ISymbolicDataAnalysisExpressionCrossover<T>>());247 // Operators.AddRange(ApplicationManager.Manager.GetInstances<ISymbolicDataAnalysisExpressionCrossover<T>>()); 247 248 Operators.Add(new SymbolicExpressionSymbolFrequencyAnalyzer()); 248 249 Operators.Add(new SymbolicDataAnalysisVariableFrequencyAnalyzer()); … … 338 339 op.RelativeNumberOfEvaluatedSamplesParameter.ActualName = RelativeNumberOfEvaluatedSamplesParameter.Name; 339 340 op.ApplyLinearScalingParameter.ActualName = ApplyLinearScalingParameter.Name; 341 op.IntegerVectorParameter.ActualName = SolutionCreator.IntegerVectorParameter.Name; 342 op.GenotypeToPhenotypeMapperParameter.ActualName = GenotypeToPhenotypeMapperParameter.Name; 343 op.SymbolicExpressionTreeGrammarParameter.ActualName = SymbolicExpressionTreeGrammarParameter.Name; 340 344 } 341 345 foreach (var op in operators.OfType<IIntegerVectorCrossover>()) { 342 op.ParentsParameter.ActualName = Evaluator.SymbolicExpressionTreeParameter.ActualName;343 op.ChildParameter.ActualName = Evaluator.SymbolicExpressionTreeParameter.ActualName;346 op.ParentsParameter.ActualName = SolutionCreator.IntegerVectorParameter.ActualName; 347 op.ChildParameter.ActualName = SolutionCreator.IntegerVectorParameter.ActualName; 344 348 } 345 349 foreach (var op in operators.OfType<IIntegerVectorManipulator>()) { … … 369 373 op.SymbolicDataAnalysisTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name; 370 374 } 375 /* 371 376 foreach (var op in operators.OfType<ISymbolicDataAnalysisExpressionCrossover<T>>()) { 372 377 op.EvaluationPartitionParameter.ActualName = FitnessCalculationPartitionParameter.Name; … … 376 381 op.EvaluatorParameter.ActualName = EvaluatorParameter.Name; 377 382 } 383 */ 378 384 } 379 385 -
branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/GESymbolicDataAnalysisSingleObjectiveProblem.cs
r10073 r10075 34 34 namespace HeuristicLab.Problems.GrammaticalEvolution { 35 35 [StorableClass] 36 public abstract class GESymbolicDataAnalysisSingleObjectiveProblem<T, U, V> : GESymbolicDataAnalysisProblem<T, U, V>, ISymbolicDataAnalysisSingleObjectiveProblem 37 where T : class,IDataAnalysisProblemData 36 public abstract class GESymbolicDataAnalysisSingleObjectiveProblem<T, U, V> : GESymbolicDataAnalysisProblem<T, U, V>, 37 ISymbolicDataAnalysisSingleObjectiveProblem 38 where T : class, IDataAnalysisProblemData 38 39 where U : class, IGESymbolicDataAnalysisSingleObjectiveEvaluator<T> 39 40 where V : class, IIntegerVectorCreator { -
branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/GESymbolicRegressionSingleObjectiveEvaluator.cs
r10073 r10075 27 27 namespace HeuristicLab.Problems.GrammaticalEvolution { 28 28 [StorableClass] 29 public abstract class GESymbolicRegressionSingleObjectiveEvaluator : GESymbolicDataAnalysisSingleObjectiveEvaluator<IRegressionProblemData>, IGESymbolicRegressionSingleObjectiveEvaluator { 29 public abstract class GESymbolicRegressionSingleObjectiveEvaluator : GESymbolicDataAnalysisSingleObjectiveEvaluator<IRegressionProblemData>, 30 IGESymbolicRegressionSingleObjectiveEvaluator { 30 31 [StorableConstructor] 31 32 protected GESymbolicRegressionSingleObjectiveEvaluator(bool deserializing) : base(deserializing) { } -
branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/GESymbolicRegressionSingleObjectiveProblem.cs
r10073 r10075 34 34 [StorableClass] 35 35 [Creatable("Problems")] 36 public class GESymbolicRegressionSingleObjectiveProblem : GESymbolicDataAnalysisSingleObjectiveProblem<IRegressionProblemData, IGESymbolicRegressionSingleObjectiveEvaluator, IIntegerVectorCreator>, IRegressionProblem { 36 public class GESymbolicRegressionSingleObjectiveProblem : GESymbolicDataAnalysisSingleObjectiveProblem<IRegressionProblemData, IGESymbolicRegressionSingleObjectiveEvaluator, IIntegerVectorCreator>, 37 IRegressionProblem { 37 38 private const double PunishmentFactor = 10; 38 39 private const int InitialMaximumTreeDepth = 8;
Note: See TracChangeset
for help on using the changeset viewer.