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:
8 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • branches/PushGP/HeuristicLab.PushGP

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

    r15275 r15289  
    77  using HeuristicLab.BenchmarkSuite;
    88  using HeuristicLab.BenchmarkSuite.Problems;
     9  using HeuristicLab.Problems.ProgramSynthesis.Push.Evaluator;
    910  using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions;
     11  using HeuristicLab.Problems.ProgramSynthesis.Push.Solution;
     12  using HeuristicLab.Problems.ProgramSynthesis.Push.Solution.BenchmarkSuite;
    1013
    1114  using Instances;
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/BenchmarkSuite/PlushPushBenchmarkSuiteProblem.cs

    r15275 r15289  
    77  using HeuristicLab.Problems.Instances;
    88  using HeuristicLab.Problems.ProgramSynthesis.Push.Configuration;
     9  using HeuristicLab.Problems.ProgramSynthesis.Push.Evaluator;
    910  using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions;
     11  using HeuristicLab.Problems.ProgramSynthesis.Push.Solution;
     12  using HeuristicLab.Problems.ProgramSynthesis.Push.Solution.BenchmarkSuite;
    1013  using HeuristicLab.Problems.ProgramSynthesis.Push.Stack;
    1114
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/IntegerVectorPushProblem.cs

    r15275 r15289  
    44  using Common;
    55  using Configuration;
    6   using Core;
    7   using HeuristicLab.Data;
    86  using HeuristicLab.Encodings.IntegerVectorEncoding;
    97  using HeuristicLab.Problems.ProgramSynthesis.Push.Analyzer;
     8  using HeuristicLab.Problems.ProgramSynthesis.Push.Evaluator;
    109  using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions;
    1110  using HeuristicLab.Problems.ProgramSynthesis.Push.Individual;
    1211  using HeuristicLab.Problems.ProgramSynthesis.Push.SolutionCreator;
     12
    1313  using Optimization;
    1414  using Persistence.Default.CompositeSerializers.Storable;
     
    5454    //  IndividualMapper.Clear();
    5555    //  RandomPool.Clear();
    56     //  Config.Seed = 0;
    5756    //}
    5857
     
    8180    }
    8281
    83     protected override PushProgram MapIndividual(Individual individual, IRandom random) {
    84       var program = individual.ToPushProgram(Config, random);
     82    protected override PushProgram MapIndividual(Individual individual) {
     83      var program = individual.ToPushProgram(Config);
    8584
    8685      return program;
    8786    }
    8887
    89     public override double Evaluate(Individual individual, IRandom random) {
    90       // init seed of random pool
    91       //Interlocked.CompareExchange(ref RandomPool.Seed, random.Next(), 0);
    92       //Config.Seed = RandomPool.Seed;
     88    //public override double Evaluate(Individual individual, IRandom random) {
     89    //  var seed = random.Next();
    9390
    94       //var rand = RandomPool.ResetAndAllocate();
    95       var program = MapIndividual(individual, random);
    96       //RandomPool.Free(rand);
     91    //  var program = individual.ToPushProgram(Config);
    9792
    98       //rand = RandomPool.ResetAndAllocate();
    99       var result = PushEvaluator.EvaluateTraining(Pool, program, random);
    100       //RandomPool.Free(rand);
     93    //  var rand = new FastRandom(seed);
     94    //  var result = PushEvaluator.EvaluateTraining(Pool, program, rand);
    10195
    102       individual[CaseQualitiesScopeParameterName] = new DoubleArray(result.ExampleQualities);
     96    //  individual[CaseQualitiesScopeParameterName] = new DoubleArray(result.ExampleQualities);
     97    //  individual[SeedScopeParameterName] = new IntValue(seed);
    10398
    104       return result.AvgQuality;
    105     }
     99    //  return result.AvgQuality;
     100    //}
    106101  }
    107102}
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/PlushPushProblem.cs

    r15275 r15289  
    99  using HeuristicLab.Problems.ProgramSynthesis.Push.Analyzer;
    1010  using HeuristicLab.Problems.ProgramSynthesis.Push.Encoding;
     11  using HeuristicLab.Problems.ProgramSynthesis.Push.Evaluator;
    1112  using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions;
    1213
     
    4344    }
    4445
    45     protected override PushProgram MapIndividual(Individual individual, IRandom random) {
     46    protected override PushProgram MapIndividual(Individual individual) {
    4647      var plushVector = individual.PlushVector();
    4748      var program = plushVector.PushProgram;
     
    4950      return program;
    5051    }
    51 
    52     public override double Evaluate(Individual individual, IRandom random) {
    53       var program = MapIndividual(individual, random);
    54       var result = PushEvaluator.EvaluateTraining(Pool, program, random);
    55 
    56       individual[CaseQualitiesScopeParameterName] = new DoubleArray(result.ExampleQualities);
    57 
    58       return result.AvgQuality;
    59     }
    6052  }
    6153}
  • 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.