Changeset 15289 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/PushProblemBase.cs
- Timestamp:
- 07/26/17 19:34:13 (7 years ago)
- Location:
- branches/PushGP/HeuristicLab.PushGP
- Files:
-
- 2 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/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.