Changeset 10075


Ignore:
Timestamp:
10/21/13 11:29:55 (6 years ago)
Author:
sawinkle
Message:

#2109:

  • For each newly created node, ResetLocalParameters() has to be called, if possible. Otherwise 'Variable' symbols won't be initialized correctly. (E.g. internal ValueName is null and causes exceptions.)
  • Method MapDepthFirstRecursively() of DepthFirstMapper.cs checks subtree boundaries by using the MinimumArity instead of the MaximumArity. Otherwise e.g. adding the 'Addition' symbol will cause very short trees, because this symbol has got a MaximumArity of 255! This would cause, that the tree is immediately full, after insertion of one 'Addition' symbol, if the genotype length is e.g. just 100.
  • Several bug fixes.
  • Unresolved issues:
    • Changes in the selected grammar are not taken into account during a run (e.g. 'Addition' symbols will be inserted into the tree, although its checkbox was unchecked previously).
    • Exception, if a division by zero is tried.
    • Wrapping mechanism.
Location:
branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Mappers/DepthFirstMapper.cs

    r10068 r10075  
    2525using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2626using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     27using HeuristicLab.Random;
    2728
    2829namespace HeuristicLab.Problems.GrammaticalEvolution {
     
    5657      SymbolicExpressionTree tree = new SymbolicExpressionTree();
    5758      var rootNode = (SymbolicExpressionTreeTopLevelNode)grammar.ProgramRootSymbol.CreateTreeNode();
     59      if (rootNode.HasLocalParameters) rootNode.ResetLocalParameters(new MersenneTwister());
    5860      var startNode = (SymbolicExpressionTreeTopLevelNode)grammar.StartSymbol.CreateTreeNode();
     61      if (startNode.HasLocalParameters) startNode.ResetLocalParameters(new MersenneTwister());
    5962      rootNode.AddSubtree(startNode);
    6063      tree.Root = rootNode;
     
    9699        var newNode = GetNewChildNode(currentNode, genotype, grammar, genotypeIndex);
    97100
    98         if ((currSubtreeCount + newNode.Symbol.MaximumArity) > maxSubtreeCount) {
     101        if ((currSubtreeCount + newNode.Symbol.MinimumArity) > maxSubtreeCount) {
    99102          // TODO: maybe check, if there is any node, which fits in the tree yet
    100103          currentNode.AddSubtree(GetRandomTerminalNode(currentNode, grammar));
     
    102105          currentNode.AddSubtree(newNode);
    103106          genotypeIndex++;
    104           currSubtreeCount += newNode.Symbol.MaximumArity;
     107          currSubtreeCount += newNode.Symbol.MinimumArity;
    105108
    106           while (newNode.Symbol.MaximumArity > newNode.SubtreeCount) {
     109          while (newNode.Symbol.MinimumArity > newNode.SubtreeCount) {
    107110            MapDepthFirstRecursively(newNode, genotype,
    108111                                     grammar, maxSubtreeCount,
     
    112115
    113116      } else {
    114         while (currentNode.Symbol.MaximumArity > currentNode.SubtreeCount) {
     117        while (currentNode.Symbol.MinimumArity > currentNode.SubtreeCount) {
    115118          var newNode = GetNewChildNode(currentNode, genotype, grammar, genotypeIndex);
    116119          currentNode.AddSubtree(newNode);
    117120          genotypeIndex++;
    118           while (newNode.Symbol.MaximumArity > newNode.SubtreeCount) {
     121          while (newNode.Symbol.MinimumArity > newNode.SubtreeCount) {
    119122            newNode.AddSubtree(GetRandomTerminalNode(newNode, grammar));
    120123          }
  • branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Mappers/GenotypeToPhenotypeMapper.cs

    r10068 r10075  
    5252    protected ISymbolicExpressionTreeNode GetRandomTerminalNode(ISymbolicExpressionTreeNode parentNode,
    5353                                                              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;
    6064    }
    6165
     
    7478                                                          int genotypeIndex) {
    7579
    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();
    7784      int prodRuleCount = symbolList.Count();
    7885      int prodRuleIndex = genotype[genotypeIndex % genotype.Length] % prodRuleCount;
    7986
    80       return symbolList.ElementAt(prodRuleIndex).CreateTreeNode();
     87      var newNode = symbolList.ElementAt(prodRuleIndex).CreateTreeNode();
     88      if (newNode.HasLocalParameters) newNode.ResetLocalParameters(new MersenneTwister());
     89      return newNode;
    8190    }
    8291  }
  • branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/GESymbolicDataAnalysisProblem.cs

    r10073 r10075  
    4141  [StorableClass]
    4242  // 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>
    4546    where T : class, IDataAnalysisProblemData
    4647    where U : class, IGESymbolicDataAnalysisEvaluator<T>
     
    244245    private void InitializeOperators() {
    245246      Operators.AddRange(ApplicationManager.Manager.GetInstances<IIntegerVectorOperator>().OfType<IOperator>());
    246       Operators.AddRange(ApplicationManager.Manager.GetInstances<ISymbolicDataAnalysisExpressionCrossover<T>>());
     247      // Operators.AddRange(ApplicationManager.Manager.GetInstances<ISymbolicDataAnalysisExpressionCrossover<T>>());
    247248      Operators.Add(new SymbolicExpressionSymbolFrequencyAnalyzer());
    248249      Operators.Add(new SymbolicDataAnalysisVariableFrequencyAnalyzer());
     
    338339        op.RelativeNumberOfEvaluatedSamplesParameter.ActualName = RelativeNumberOfEvaluatedSamplesParameter.Name;
    339340        op.ApplyLinearScalingParameter.ActualName = ApplyLinearScalingParameter.Name;
     341        op.IntegerVectorParameter.ActualName = SolutionCreator.IntegerVectorParameter.Name;
     342        op.GenotypeToPhenotypeMapperParameter.ActualName = GenotypeToPhenotypeMapperParameter.Name;
     343        op.SymbolicExpressionTreeGrammarParameter.ActualName = SymbolicExpressionTreeGrammarParameter.Name;
    340344      }
    341345      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;
    344348      }
    345349      foreach (var op in operators.OfType<IIntegerVectorManipulator>()) {
     
    369373        op.SymbolicDataAnalysisTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name;
    370374      }
     375      /*
    371376      foreach (var op in operators.OfType<ISymbolicDataAnalysisExpressionCrossover<T>>()) {
    372377        op.EvaluationPartitionParameter.ActualName = FitnessCalculationPartitionParameter.Name;
     
    376381        op.EvaluatorParameter.ActualName = EvaluatorParameter.Name;
    377382      }
     383      */
    378384    }
    379385
  • branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/GESymbolicDataAnalysisSingleObjectiveProblem.cs

    r10073 r10075  
    3434namespace HeuristicLab.Problems.GrammaticalEvolution {
    3535  [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
    3839    where U : class, IGESymbolicDataAnalysisSingleObjectiveEvaluator<T>
    3940    where V : class, IIntegerVectorCreator {
  • branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/GESymbolicRegressionSingleObjectiveEvaluator.cs

    r10073 r10075  
    2727namespace HeuristicLab.Problems.GrammaticalEvolution {
    2828  [StorableClass]
    29   public abstract class GESymbolicRegressionSingleObjectiveEvaluator : GESymbolicDataAnalysisSingleObjectiveEvaluator<IRegressionProblemData>, IGESymbolicRegressionSingleObjectiveEvaluator {
     29  public abstract class GESymbolicRegressionSingleObjectiveEvaluator : GESymbolicDataAnalysisSingleObjectiveEvaluator<IRegressionProblemData>,
     30                                                                       IGESymbolicRegressionSingleObjectiveEvaluator {
    3031    [StorableConstructor]
    3132    protected GESymbolicRegressionSingleObjectiveEvaluator(bool deserializing) : base(deserializing) { }
  • branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/GESymbolicRegressionSingleObjectiveProblem.cs

    r10073 r10075  
    3434  [StorableClass]
    3535  [Creatable("Problems")]
    36   public class GESymbolicRegressionSingleObjectiveProblem : GESymbolicDataAnalysisSingleObjectiveProblem<IRegressionProblemData, IGESymbolicRegressionSingleObjectiveEvaluator, IIntegerVectorCreator>, IRegressionProblem {
     36  public class GESymbolicRegressionSingleObjectiveProblem : GESymbolicDataAnalysisSingleObjectiveProblem<IRegressionProblemData, IGESymbolicRegressionSingleObjectiveEvaluator, IIntegerVectorCreator>,
     37                                                            IRegressionProblem {
    3738    private const double PunishmentFactor = 10;
    3839    private const int InitialMaximumTreeDepth = 8;
Note: See TracChangeset for help on using the changeset viewer.