Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10280


Ignore:
Timestamp:
01/05/14 12:53:58 (10 years ago)
Author:
sawinkle
Message:

#2109: Fetched random number generator in Evaluator implementations from scope, so that the same results are produced using the same seed.

Location:
branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution
Files:
8 edited

Legend:

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

    r10071 r10280  
    6363      get { return (ILookupParameter<IGenotypeToPhenotypeMapper>)Parameters["GenotypeToPhenotypeMapper"]; }
    6464    }
     65    public ILookupParameter<IRandom> RandomParameter {
     66      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
     67    }
    6568    #endregion
    6669
     
    7881      Parameters.Add(new ValueLookupParameter<ISymbolicExpressionGrammar>("SymbolicExpressionTreeGrammar", "The tree grammar that defines the correct syntax of symbolic expression trees that should be created."));
    7982      Parameters.Add(new LookupParameter<IGenotypeToPhenotypeMapper>("GenotypeToPhenotypeMapper", "Maps the genotype (an integer vector) to the phenotype (a symbolic expression tree)."));
     83      Parameters.Add(new LookupParameter<IRandom>("Random", "Random number generator for the genotype creation and the genotype-to-phenotype mapping."));
    8084    }
    8185
    8286    public sealed override IOperation Apply() {
    83       SymbolicExpressionTree expression = GenotypeToPhenotypeMapperParameter.ActualValue.Map(
     87      SymbolicExpressionTree tree = GenotypeToPhenotypeMapperParameter.ActualValue.Map(
     88        RandomParameter.ActualValue,
    8489        SymbolicExpressionTreeGrammarParameter.ActualValue,
    8590        IntegerVectorParameter.ActualValue
    8691      );
    87       SymbolicExpressionTreeParameter.ActualValue = expression;
     92      SymbolicExpressionTreeParameter.ActualValue = tree;
    8893      BoolMatrix world = WorldParameter.ActualValue;
    8994      IntValue maxTimeSteps = MaxTimeStepsParameter.ActualValue;
     
    9297      interpreter.MaxTimeSteps = maxTimeSteps.Value;
    9398      interpreter.World = world;
    94       interpreter.Expression = expression;
     99      interpreter.Expression = tree;
    95100      interpreter.Run();
    96101
  • branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Mappers/BreathFirstMapper.cs

    r10277 r10280  
    2727using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2828using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    29 using HeuristicLab.Random;
    3029
    3130namespace HeuristicLab.Problems.GrammaticalEvolution {
     
    5150    /// Breath-first approach.
    5251    /// </summary>
     52    /// <param name="random">random number generator</param>
    5353    /// <param name="grammar">grammar definition</param>
    5454    /// <param name="genotype">integer vector, which should be mapped to a tree</param>
    5555    /// <returns>phenotype (a symbolic expression tree)</returns>
    56     public override SymbolicExpressionTree Map(ISymbolicExpressionGrammar grammar,
     56    public override SymbolicExpressionTree Map(IRandom random,
     57                                               ISymbolicExpressionGrammar grammar,
    5758                                               IntegerVector genotype) {
    5859
     
    6465
    6566      MapBreathFirstIteratively(startNode, genotype, grammar,
    66                                 genotype.Length, new MersenneTwister());
     67                                genotype.Length, random);
    6768
    6869      return tree;
  • branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Mappers/DepthFirstMapper.cs

    r10277 r10280  
    2727using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2828using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    29 using HeuristicLab.Random;
    3029
    3130namespace HeuristicLab.Problems.GrammaticalEvolution {
     
    5150    /// Depth-first approach.
    5251    /// </summary>
     52    /// <param name="random">random number generator</param>
    5353    /// <param name="grammar">grammar definition</param>
    5454    /// <param name="genotype">integer vector, which should be mapped to a tree</param>
    5555    /// <returns>phenotype (a symbolic expression tree)</returns>
    56     public override SymbolicExpressionTree Map(ISymbolicExpressionGrammar grammar,
     56    public override SymbolicExpressionTree Map(IRandom random,
     57                                               ISymbolicExpressionGrammar grammar,
    5758                                               IntegerVector genotype) {
    5859
    5960      SymbolicExpressionTree tree = new SymbolicExpressionTree();
    6061      var rootNode = (SymbolicExpressionTreeTopLevelNode)grammar.ProgramRootSymbol.CreateTreeNode();
    61       if (rootNode.HasLocalParameters) rootNode.ResetLocalParameters(new MersenneTwister());
     62      if (rootNode.HasLocalParameters) rootNode.ResetLocalParameters(random);
    6263      var startNode = (SymbolicExpressionTreeTopLevelNode)grammar.StartSymbol.CreateTreeNode();
    63       if (startNode.HasLocalParameters) startNode.ResetLocalParameters(new MersenneTwister());
     64      if (startNode.HasLocalParameters) startNode.ResetLocalParameters(random);
    6465      rootNode.AddSubtree(startNode);
    6566      tree.Root = rootNode;
    6667
    6768      MapDepthFirstIteratively(startNode, genotype, grammar,
    68                                genotype.Length, new MersenneTwister());
     69                               genotype.Length, random);
    6970      return tree;
    7071    }
  • branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Mappers/GenotypeToPhenotypeMapper.cs

    r10277 r10280  
    4040    protected GenotypeToPhenotypeMapper() : base() { }
    4141
    42     public abstract SymbolicExpressionTree Map(ISymbolicExpressionGrammar grammar,
     42    public abstract SymbolicExpressionTree Map(IRandom random,
     43                                               ISymbolicExpressionGrammar grammar,
    4344                                               IntegerVector genotype);
    4445
  • branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Mappers/IGenotypeToPhenotypeMapper.cs

    r10068 r10280  
    2020#endregion
    2121
     22using HeuristicLab.Core;
    2223using HeuristicLab.Encodings.IntegerVectorEncoding;
    2324using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    2829  /// </summary>
    2930  public interface IGenotypeToPhenotypeMapper : IIntegerVectorOperator {
    30     SymbolicExpressionTree Map(ISymbolicExpressionGrammar grammar,
     31    SymbolicExpressionTree Map(IRandom random,
     32                               ISymbolicExpressionGrammar grammar,
    3133                               IntegerVector genotype);
    3234  }
  • branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Mappers/PIGEMapper.cs

    r10068 r10280  
    4848    /// PIGE approach.
    4949    /// </summary>
     50    /// <param name="random">random number generator</param>
    5051    /// <param name="grammar">grammar definition</param>
    5152    /// <param name="genotype">integer vector, which should be mapped to a tree</param>
    5253    /// <returns>phenotype (a symbolic expression tree)</returns>
    53     public override SymbolicExpressionTree Map(ISymbolicExpressionGrammar grammar,
     54    public override SymbolicExpressionTree Map(IRandom random,
     55                                               ISymbolicExpressionGrammar grammar,
    5456                                               IntegerVector genotype) {
    5557
  • branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Mappers/RandomMapper.cs

    r10068 r10280  
    4848    /// Random approach.
    4949    /// </summary>
     50    /// <param name="random">random number generator</param>
    5051    /// <param name="grammar">grammar definition</param>
    5152    /// <param name="genotype">integer vector, which should be mapped to a tree</param>
    5253    /// <returns>phenotype (a symbolic expression tree)</returns>
    53     public override SymbolicExpressionTree Map(ISymbolicExpressionGrammar grammar,
     54    public override SymbolicExpressionTree Map(IRandom random,
     55                                               ISymbolicExpressionGrammar grammar,
    5456                                               IntegerVector genotype) {
    5557
  • branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/GESymbolicRegressionSingleObjectiveEvaluator.cs

    r10276 r10280  
    3333
    3434    public const string EvaluatorParameterName = "Evaluator";
     35    public const string RandomParameterName = "Random";
     36
    3537    public IValueParameter<ISymbolicRegressionSingleObjectiveEvaluator> EvaluatorParameter {
    3638      get { return (IValueParameter<ISymbolicRegressionSingleObjectiveEvaluator>)Parameters[EvaluatorParameterName]; }
     39    }
     40    public ILookupParameter<IRandom> RandomParameter {
     41      get { return (ILookupParameter<IRandom>)Parameters[RandomParameterName]; }
    3742    }
    3843
     
    4045      get { return EvaluatorParameter.Value; }
    4146    }
     47
    4248
    4349    [StorableConstructor]
     
    6268      // translate to phenotype
    6369      var tree = GenotypeToPhenotypeMapperParameter.ActualValue.Map(
     70        RandomParameter.ActualValue,
    6471        SymbolicExpressionTreeGrammarParameter.ActualValue,
    6572        genotype
Note: See TracChangeset for help on using the changeset viewer.