Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10328


Ignore:
Timestamp:
01/12/14 20:00:02 (10 years ago)
Author:
sawinkle
Message:

#2109:

  • Added method comments + refactoring.
  • Implemented RandomMapper.
  • Changed InitialTreeLength (genotype length) of Symbolic Regression problem from 25 to 30, equally to the Artificial Ant problem with also 30.
Location:
branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/ArtificialAnt/GEArtificialAntEvaluator.cs

    r10290 r10328  
    9090
    9191      Parameters.Add(new LookupParameter<IntMatrix>("Bounds", "The integer number range in which the single genomes of a genotype are created."));
    92       Parameters.Add(new LookupParameter<IntValue>("MaximumExpressionLength", "Maximal length of the expression to control the artificial ant."));
     92      Parameters.Add(new LookupParameter<IntValue>("MaximumExpressionLength", "Maximal length of the expression to control the artificial ant (genotype length)."));
    9393    }
    9494
  • branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/ArtificialAnt/GEArtificialAntProblem.cs

    r10071 r10328  
    158158      : base(new GEArtificialAntEvaluator(), new UniformRandomIntegerVectorCreator()) {
    159159      BoolMatrix world = new BoolMatrix(santaFeAntTrail);
    160       Parameters.Add(new ValueParameter<IntValue>("MaximumExpressionLength", "Maximal length of the expression to control the artificial ant.", new IntValue(30)));
     160      Parameters.Add(new ValueParameter<IntValue>("MaximumExpressionLength", "Maximal length of the expression to control the artificial ant (genotype length).", new IntValue(30)));
    161161      Parameters.Add(new ValueParameter<ISymbolicExpressionGrammar>("ArtificialAntExpressionGrammar", "The grammar that should be used for artificial ant expressions.", new ArtificialAntExpressionGrammar()));
    162162      Parameters.Add(new ValueParameter<BoolMatrix>("World", "The world for the artificial ant with scattered food items.", world));
  • branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Mappers/BreathFirstMapper.cs

    r10290 r10328  
    5252    /// </summary>
    5353    /// <param name="random">random number generator</param>
     54    /// <param name="bounds">only used for PIGEMapper (ignore here)</param>
     55    /// <param name="length">only used for PIGEMapper (ignore here)</param>
    5456    /// <param name="grammar">grammar definition</param>
    5557    /// <param name="genotype">integer vector, which should be mapped to a tree</param>
  • branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Mappers/DepthFirstMapper.cs

    r10290 r10328  
    5252    /// </summary>
    5353    /// <param name="random">random number generator</param>
     54    /// <param name="bounds">only used for PIGEMapper (ignore here)</param>
     55    /// <param name="length">only used for PIGEMapper (ignore here)</param>
    5456    /// <param name="grammar">grammar definition</param>
    5557    /// <param name="genotype">integer vector, which should be mapped to a tree</param>
  • branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Mappers/GenotypeToPhenotypeMapper.cs

    r10290 r10328  
    9797      if (prodRuleCount < 1) return null;
    9898
    99       // genotypeIndex % genotype.Length
     99      // genotypeIndex % genotype.Length, if wrapping is allowed
    100100      int prodRuleIndex = genotype[genotypeIndex] % prodRuleCount;
    101101
  • branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Mappers/PIGEMapper.cs

    r10290 r10328  
    9797    /// </summary>
    9898    /// <param name="random">random number generator</param>
     99    /// <param name="bounds">integer number range for genomes (codons) of the nont vector</param>
     100    /// <param name="length">length of the nont vector to create</param>
    99101    /// <param name="grammar">grammar definition</param>
    100102    /// <param name="genotype">integer vector, which should be mapped to a tree</param>
     
    121123
    122124
     125    /// <summary>
     126    /// Genotype-to-Phenotype mapper (iterative 𝜋GE approach, using a list of not expanded nonTerminals).
     127    /// </summary>
     128    /// <param name="startNode">first node of the tree with arity 1</param>
     129    /// <param name="genotype">integer vector, which should be mapped to a tree</param>
     130    /// <param name="grammar">grammar to determine the allowed child symbols for each node</param>
     131    /// <param name="maxSubtreeCount">maximum allowed subtrees (= number of used genomes)</param>
     132    /// <param name="random">random number generator</param>
    123133    private void MapPIGEIteratively(ISymbolicExpressionTreeNode startNode,
    124134                                    IntegerVector genotype,
  • branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Mappers/RandomMapper.cs

    r10290 r10328  
    2020#endregion
    2121
     22using System.Collections.Generic;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
     
    3132  /// RandomMapper
    3233  /// </summary>
    33   [Item("RandomMapper", "")]
     34  [Item("RandomMapper", "Randomly determines the next non-terminal symbol to expand.")]
    3435  [StorableClass]
    3536  public class RandomMapper : GenotypeToPhenotypeMapper {
     
    5051    /// </summary>
    5152    /// <param name="random">random number generator</param>
     53    /// <param name="bounds">only used for PIGEMapper (ignore here)</param>
     54    /// <param name="length">only used for PIGEMapper (ignore here)</param>
    5255    /// <param name="grammar">grammar definition</param>
    5356    /// <param name="genotype">integer vector, which should be mapped to a tree</param>
     
    6366      tree.Root = rootNode;
    6467
    65       // TODO
     68      MapRandomIteratively(startNode, genotype, grammar,
     69                           genotype.Length, random);
    6670
    6771      return tree;
    6872    }
     73
     74
     75    /// <summary>
     76    /// Genotype-to-Phenotype mapper (iterative random approach, where the next non-terminal
     77    /// symbol to expand is randomly determined).
     78    /// </summary>
     79    /// <param name="startNode">first node of the tree with arity 1</param>
     80    /// <param name="genotype">integer vector, which should be mapped to a tree</param>
     81    /// <param name="grammar">grammar to determine the allowed child symbols for each node</param>
     82    /// <param name="maxSubtreeCount">maximum allowed subtrees (= number of used genomes)</param>
     83    /// <param name="random">random number generator</param>
     84    private void MapRandomIteratively(ISymbolicExpressionTreeNode startNode,
     85                                     IntegerVector genotype,
     86                                     ISymbolicExpressionGrammar grammar,
     87                                     int maxSubtreeCount, IRandom random) {
     88
     89      List<ISymbolicExpressionTreeNode> nonTerminals = new List<ISymbolicExpressionTreeNode>();
     90
     91      int genotypeIndex = 0;
     92      nonTerminals.Add(startNode);
     93
     94      while (nonTerminals.Count > 0) {
     95        if (genotypeIndex >= maxSubtreeCount) {
     96          // if all genomes were used, only add terminal nodes to the remaining subtrees
     97          ISymbolicExpressionTreeNode current = nonTerminals[0];
     98          nonTerminals.RemoveAt(0);
     99          current.AddSubtree(GetRandomTerminalNode(current, grammar, random));
     100        } else {
     101          // similar to PIGEMapper, but here the current node is determined randomly ...
     102          ISymbolicExpressionTreeNode current = nonTerminals.SelectRandom(random);
     103          nonTerminals.Remove(current);
     104
     105          ISymbolicExpressionTreeNode newNode = GetNewChildNode(current, genotype, grammar, genotypeIndex, random);
     106          int arity = SampleArity(random, newNode, grammar);
     107
     108          current.AddSubtree(newNode);
     109          genotypeIndex++;
     110          // new node has subtrees, so add "arity" number of copies of this node to the nonTerminals list
     111          for (int i = 0; i < arity; ++i) {
     112            nonTerminals.Add(newNode);
     113          }
     114        }
     115      }
     116    }
    69117  }
    70118}
  • branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/GESymbolicRegressionSingleObjectiveProblem.cs

    r10276 r10328  
    3838                                                            IRegressionProblem {
    3939    private const double PunishmentFactor = 10;
    40     private const int InitialMaximumTreeLength = 25;
     40    private const int InitialMaximumTreeLength = 30;
    4141    private const string EstimationLimitsParameterName = "EstimationLimits";
    4242    private const string EstimationLimitsParameterDescription
Note: See TracChangeset for help on using the changeset viewer.