Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/26/17 19:34:13 (7 years ago)
Author:
pkimmesw
Message:

#2665 Fixed analyzer, fixed Plush encoding + operators, adpated print evaluation according to McPhee

Location:
branches/PushGP/HeuristicLab.PushGP
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/PushGP/HeuristicLab.PushGP

    • Property svn:ignore set to
      *.user
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/PushProblemBase.cs

    r15275 r15289  
    1010  using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    1111  using HeuristicLab.Problems.ProgramSynthesis.Push.Configuration;
     12  using HeuristicLab.Problems.ProgramSynthesis.Push.Evaluator;
    1213  using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions;
    1314  using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter;
    1415  using HeuristicLab.Problems.ProgramSynthesis.Push.ObjectPools.Random;
     16  using HeuristicLab.Problems.ProgramSynthesis.Push.Solution;
     17  using HeuristicLab.Random;
    1518
    1619  [StorableClass]
     
    3134    public const string CasesScopeParameterName = "CaseQualities";
    3235    public const string CaseQualitiesScopeParameterName = "CaseQualities";
     36    public const string SeedScopeParameterName = "Seed";
    3337
    3438    protected PushProblemBase(IPushEvaluator evaluator) {
     
    8892      var bestQuality = Maximization ? qualities.Max() : qualities.Min();
    8993      var bestIdx = Array.IndexOf(qualities, bestQuality);
    90       var program = MapIndividual(individuals[bestIdx], random);
     94      var bestIndividual = individuals[bestIdx];
     95      var seed = (IntValue)bestIndividual[SeedScopeParameterName];
     96      var program = MapIndividual(bestIndividual);
    9197
    92       var isIndividualBetter = AnalyzeBestTrainingSolution(program, bestQuality, results, random);
     98      var rand = new FastRandom(seed.Value);
     99      var isIndividualBetter = AnalyzeBestTrainingSolution(program, bestQuality, results, rand);
    93100
    94101      if (isIndividualBetter) {
    95         AnalyzeBestTestSolution(program, results, random);
     102        rand.Reset(seed.Value);
     103        AnalyzeBestTestSolution(program, results, rand);
    96104      }
    97105    }
    98106
    99107    protected void AnalyzeBestTestSolution(PushProgram program, ResultCollection results, IRandom random) {
    100       var testResult = PushEvaluator.EvaluateTraining(Pool, program, random);
     108      var testResult = PushEvaluator.EvaluateTest(Pool, program, random);
    101109
    102110      if (!results.ContainsKey(TEST_QUALITY_RESULT_NAME)) {
     
    108116
    109117    protected bool AnalyzeBestTrainingSolution(PushProgram program, double bestQuality, ResultCollection results, IRandom random) {
    110       if (!results.ContainsKey(BEST_TRAINING_SOLUTION_RESULT_NAME)) {
    111         var solution = CreatePushSolution(
     118      var solution = CreatePushSolution(
    112119            program,
    113120            bestQuality,
    114             (IRandom)random.Clone(),
     121            random, // is already cloned
    115122            (IReadOnlyPushConfiguration)Config.Clone());
    116123
     124      if (!results.ContainsKey(BEST_TRAINING_SOLUTION_RESULT_NAME)) {
    117125        results.Add(new Result(BEST_TRAINING_SOLUTION_RESULT_NAME, solution));
    118126        return true;
     
    123131      if ((!Maximization && currentBestQuality > bestQuality) ||
    124132           (Maximization && currentBestQuality < bestQuality)) {
    125         results[BEST_TRAINING_SOLUTION_RESULT_NAME].Value = CreatePushSolution(
    126             program,
    127             bestQuality,
    128             random,
    129             Config);
     133        results[BEST_TRAINING_SOLUTION_RESULT_NAME].Value = solution;
    130134        return true;
    131135      }
     
    135139
    136140    public override double Evaluate(Individual individual, IRandom random) {
    137       var program = MapIndividual(individual, random);
    138       var result = PushEvaluator.EvaluateTraining(Pool, program, random);
     141      var program = MapIndividual(individual);
     142      var seed = random.Next();
     143      var rand = new FastRandom(seed);
     144      var result = PushEvaluator.EvaluateTraining(Pool, program, rand);
    139145
    140146      individual[CaseQualitiesScopeParameterName] = new DoubleArray(result.ExampleQualities);
     147      individual[SeedScopeParameterName] = new IntValue(seed);
    141148
    142149      return result.AvgQuality;
    143150    }
    144151
    145     protected abstract PushProgram MapIndividual(Individual individual, IRandom random);
     152    protected abstract PushProgram MapIndividual(Individual individual);
    146153
    147154    protected abstract PushSolution CreatePushSolution(
Note: See TracChangeset for help on using the changeset viewer.