Changeset 15289 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem
- Timestamp:
- 07/26/17 19:34:13 (7 years ago)
- Location:
- branches/PushGP/HeuristicLab.PushGP
- Files:
-
- 8 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP
-
Property
svn:ignore
set to
*.user
-
Property
svn:ignore
set to
-
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/BenchmarkSuite/IntegerVectorPushBenchmarkSuiteProblem.cs
r15275 r15289 7 7 using HeuristicLab.BenchmarkSuite; 8 8 using HeuristicLab.BenchmarkSuite.Problems; 9 using HeuristicLab.Problems.ProgramSynthesis.Push.Evaluator; 9 10 using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions; 11 using HeuristicLab.Problems.ProgramSynthesis.Push.Solution; 12 using HeuristicLab.Problems.ProgramSynthesis.Push.Solution.BenchmarkSuite; 10 13 11 14 using Instances; -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/BenchmarkSuite/PlushPushBenchmarkSuiteProblem.cs
r15275 r15289 7 7 using HeuristicLab.Problems.Instances; 8 8 using HeuristicLab.Problems.ProgramSynthesis.Push.Configuration; 9 using HeuristicLab.Problems.ProgramSynthesis.Push.Evaluator; 9 10 using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions; 11 using HeuristicLab.Problems.ProgramSynthesis.Push.Solution; 12 using HeuristicLab.Problems.ProgramSynthesis.Push.Solution.BenchmarkSuite; 10 13 using HeuristicLab.Problems.ProgramSynthesis.Push.Stack; 11 14 -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/IntegerVectorPushProblem.cs
r15275 r15289 4 4 using Common; 5 5 using Configuration; 6 using Core;7 using HeuristicLab.Data;8 6 using HeuristicLab.Encodings.IntegerVectorEncoding; 9 7 using HeuristicLab.Problems.ProgramSynthesis.Push.Analyzer; 8 using HeuristicLab.Problems.ProgramSynthesis.Push.Evaluator; 10 9 using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions; 11 10 using HeuristicLab.Problems.ProgramSynthesis.Push.Individual; 12 11 using HeuristicLab.Problems.ProgramSynthesis.Push.SolutionCreator; 12 13 13 using Optimization; 14 14 using Persistence.Default.CompositeSerializers.Storable; … … 54 54 // IndividualMapper.Clear(); 55 55 // RandomPool.Clear(); 56 // Config.Seed = 0;57 56 //} 58 57 … … 81 80 } 82 81 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); 85 84 86 85 return program; 87 86 } 88 87 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(); 93 90 94 //var rand = RandomPool.ResetAndAllocate(); 95 var program = MapIndividual(individual, random); 96 //RandomPool.Free(rand); 91 // var program = individual.ToPushProgram(Config); 97 92 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); 101 95 102 individual[CaseQualitiesScopeParameterName] = new DoubleArray(result.ExampleQualities); 96 // individual[CaseQualitiesScopeParameterName] = new DoubleArray(result.ExampleQualities); 97 // individual[SeedScopeParameterName] = new IntValue(seed); 103 98 104 return result.AvgQuality;105 }99 // return result.AvgQuality; 100 //} 106 101 } 107 102 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/PlushPushProblem.cs
r15275 r15289 9 9 using HeuristicLab.Problems.ProgramSynthesis.Push.Analyzer; 10 10 using HeuristicLab.Problems.ProgramSynthesis.Push.Encoding; 11 using HeuristicLab.Problems.ProgramSynthesis.Push.Evaluator; 11 12 using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions; 12 13 … … 43 44 } 44 45 45 protected override PushProgram MapIndividual(Individual individual , IRandom random) {46 protected override PushProgram MapIndividual(Individual individual) { 46 47 var plushVector = individual.PlushVector(); 47 48 var program = plushVector.PushProgram; … … 49 50 return program; 50 51 } 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 }60 52 } 61 53 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/PushProblemBase.cs
r15275 r15289 10 10 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 11 11 using HeuristicLab.Problems.ProgramSynthesis.Push.Configuration; 12 using HeuristicLab.Problems.ProgramSynthesis.Push.Evaluator; 12 13 using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions; 13 14 using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter; 14 15 using HeuristicLab.Problems.ProgramSynthesis.Push.ObjectPools.Random; 16 using HeuristicLab.Problems.ProgramSynthesis.Push.Solution; 17 using HeuristicLab.Random; 15 18 16 19 [StorableClass] … … 31 34 public const string CasesScopeParameterName = "CaseQualities"; 32 35 public const string CaseQualitiesScopeParameterName = "CaseQualities"; 36 public const string SeedScopeParameterName = "Seed"; 33 37 34 38 protected PushProblemBase(IPushEvaluator evaluator) { … … 88 92 var bestQuality = Maximization ? qualities.Max() : qualities.Min(); 89 93 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); 91 97 92 var isIndividualBetter = AnalyzeBestTrainingSolution(program, bestQuality, results, random); 98 var rand = new FastRandom(seed.Value); 99 var isIndividualBetter = AnalyzeBestTrainingSolution(program, bestQuality, results, rand); 93 100 94 101 if (isIndividualBetter) { 95 AnalyzeBestTestSolution(program, results, random); 102 rand.Reset(seed.Value); 103 AnalyzeBestTestSolution(program, results, rand); 96 104 } 97 105 } 98 106 99 107 protected void AnalyzeBestTestSolution(PushProgram program, ResultCollection results, IRandom random) { 100 var testResult = PushEvaluator.EvaluateT raining(Pool, program, random);108 var testResult = PushEvaluator.EvaluateTest(Pool, program, random); 101 109 102 110 if (!results.ContainsKey(TEST_QUALITY_RESULT_NAME)) { … … 108 116 109 117 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( 112 119 program, 113 120 bestQuality, 114 (IRandom)random.Clone(),121 random, // is already cloned 115 122 (IReadOnlyPushConfiguration)Config.Clone()); 116 123 124 if (!results.ContainsKey(BEST_TRAINING_SOLUTION_RESULT_NAME)) { 117 125 results.Add(new Result(BEST_TRAINING_SOLUTION_RESULT_NAME, solution)); 118 126 return true; … … 123 131 if ((!Maximization && currentBestQuality > bestQuality) || 124 132 (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; 130 134 return true; 131 135 } … … 135 139 136 140 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); 139 145 140 146 individual[CaseQualitiesScopeParameterName] = new DoubleArray(result.ExampleQualities); 147 individual[SeedScopeParameterName] = new IntValue(seed); 141 148 142 149 return result.AvgQuality; 143 150 } 144 151 145 protected abstract PushProgram MapIndividual(Individual individual , IRandom random);152 protected abstract PushProgram MapIndividual(Individual individual); 146 153 147 154 protected abstract PushSolution CreatePushSolution(
Note: See TracChangeset
for help on using the changeset viewer.