Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/30/17 19:16:09 (7 years ago)
Author:
pkimmesw
Message:

#2665 Improved random walk tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Tests/Benchmark/RandomWalkTests.cs

    r14897 r14900  
    11namespace HeuristicLab.Tests.Benchmark {
    22  using System;
    3   using System.Threading.Tasks;
     3  using System.Linq;
    44  using BenchmarkSuite;
    55
     
    88  using Microsoft.VisualStudio.TestTools.UnitTesting;
    99  using Problems.ProgramSynthesis.Push.Configuration;
    10   using Problems.ProgramSynthesis.Push.Expressions;
    1110  using Problems.ProgramSynthesis.Push.Generators.CodeGenerator;
    1211  using Problems.ProgramSynthesis.Push.Interpreter;
    1312  using Problems.ProgramSynthesis.Push.Problem.BenchmarkSuite;
    14   using Problems.ProgramSynthesis.Push.Simplifier;
    1513  using Problems.ProgramSynthesis.Push.Stack;
    1614  using Random;
     
    2119      var iterations = 2;
    2220      var best = double.MaxValue;
    23       var lockObj = new object();
    2421      var random = new MersenneTwister(1337);
    2522
     
    3734
    3835      var pool = new PushInterpreterPool(config);
    39       PushProgram bestProgram = null;
    40 
    41       Parallel.For(0u, iterations, i => {
    42         var program = RecursiveCodeGenerator.RandomProgram(data.MaxSize, random, config);
    43         var avg = evaluator.EvaluateTraining(pool, program, random);
    44 
    45         lock (lockObj) {
    46           if (avg.TotalQuality < best) {
    47             best = avg.TotalQuality;
    48             bestProgram = program;
    49           }
    50         }
    51       });
     36      var bestProgram = Enumerable
     37        .Range(0, iterations)
     38        .AsParallel()
     39        .Select(_ => {
     40          var program = LinearCodeGenerator.RandomProgram(data.MaxSize, random, config);
     41          var result = evaluator.EvaluateTraining(pool, program, random);
     42
     43          return new {
     44            Quality = result.TotalQuality,
     45            Program = program
     46          };
     47        })
     48        .OrderBy(x => x.Quality)
     49        .Select(x => x.Program)
     50        .First();
     51      //  var program = RecursiveCodeGenerator.RandomProgram(data.MaxSize, random, config);
     52      //  var avg = evaluator.EvaluateTraining(pool, program, random);
     53
     54      //  lock (lockObj) {
     55      //    if (avg.TotalQuality < best) {
     56      //      best = avg.TotalQuality;
     57      //      bestProgram = program;
     58      //    }
     59      //  }
     60      //});
    5261
    5362      var averageTestResult = evaluator.EvaluateTest(pool, bestProgram, random);
    54       var simplifiedProgram = Simplifier.Simplify(
    55         bestProgram,
    56         p => evaluator.EvaluateTraining(pool, p, random).TotalQuality);
     63      //var simplifiedProgram = Simplifier.Simplify(
     64      //  bestProgram,
     65      //  p => evaluator.EvaluateTraining(pool, p, random).TotalQuality);
    5766
    5867      Console.WriteLine("Training: {0}", best);
    5968      Console.WriteLine("RandomWalk: {0}", averageTestResult.TotalQuality);
    60       Console.WriteLine("Best program (simplified): {0}", simplifiedProgram);
     69      //Console.WriteLine("Best program (simplified): {0}", simplifiedProgram);
    6170    }
    6271
Note: See TracChangeset for help on using the changeset viewer.