Changeset 14744 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem
- Timestamp:
- 03/10/17 21:42:09 (8 years ago)
- Location:
- branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/PushEncoding.cs
r14727 r14744 37 37 38 38 public static class IndividualExtensionMethods { 39 public static PushProgram PushProgram(this Individual individual, I List<string> enabledExpressions) {40 return MapToProgram(individual.IntegerVector(),enabledExpressions);39 public static PushProgram PushProgram(this Individual individual, IReadOnlyList<string> enabledExpressions) { 40 return individual.IntegerVector().MapToPushProgram(enabledExpressions); 41 41 } 42 42 43 p rivate static PushProgram MapToProgram(IntegerVector vector, IList<string> enabledExpressions) {43 public static PushProgram MapToPushProgram(this IntegerVector vector, IReadOnlyList<string> enabledExpressions) { 44 44 var expressions = vector 45 45 .Select(i => ExpressionTable.GetExpression(enabledExpressions[i])) 46 46 .ToArray(); 47 47 48 return new PushProgram(expressions);48 return new Expressions.PushProgram(expressions); 49 49 } 50 50 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/PushProblem.cs
r14733 r14744 4 4 using System.Collections.Generic; 5 5 using System.Linq; 6 using BenchmarkSuite.Problems;7 6 using Common; 8 7 using Configuration; … … 10 9 using Encodings.IntegerVectorEncoding; 11 10 using Expressions; 11 12 using HeuristicLab.BenchmarkSuite; 12 13 using HeuristicLab.Data; 13 14 using Instances; … … 21 22 [Creatable(CreatableAttribute.Categories.GeneticProgrammingProblems, Priority = 180)] 22 23 [Item("Push Problem", "")] 23 public class PushProblem : SingleObjectiveBasicProblem<IntegerVectorEncoding>, IProblemInstanceConsumer< Data> {24 public class PushProblem : SingleObjectiveBasicProblem<IntegerVectorEncoding>, IProblemInstanceConsumer<IBenchmarkSuiteDataDescriptor> { 24 25 [Storable] 25 26 private readonly PushConfiguration config; … … 49 50 this.InitEvents(); 50 51 } 51 52 52 53 53 [StorableHook(HookType.AfterDeserialization)] … … 102 102 var bounds = new IntMatrix(1, 3, new[] { "Training Start", "Training End | Test Start", "Test End" }); 103 103 bounds.ItemChanged += (s, e) => { 104 if ( Data== null)104 if (this.DataDescriptor == null) 105 105 return; 106 106 107 var max = Data.OriginalTestCount + Data.OriginalTrainingCount - 1;107 var max = this.DataDescriptor.OriginalTestCount + this.DataDescriptor.OriginalTrainingCount - 1; 108 108 bounds[0, 0] = Math.Min(Math.Max(bounds[0, 0], 0), max); 109 109 bounds[0, 2] = Math.Max(Math.Min(bounds[0, 2], max), 0); … … 174 174 new IntValue(config.MaxPointsInRandomExpression)) { Hidden = true }); 175 175 176 Parameters.Add(new ValueParameter< Data>(DataParameterName, DataParameterDescription));176 Parameters.Add(new ValueParameter<IBenchmarkSuiteDataDescriptor>(DataParameterName, DataParameterDescription)); 177 177 178 178 Encoding.Bounds[0, 0] = 0; … … 204 204 } 205 205 206 public IValueParameter< Data> DataParameter207 { 208 get { return (IValueParameter< Data>)Parameters[DataParameterName]; }209 } 210 211 public Data Data206 public IValueParameter<IBenchmarkSuiteDataDescriptor> DataParameter 207 { 208 get { return (IValueParameter<IBenchmarkSuiteDataDescriptor>)Parameters[DataParameterName]; } 209 } 210 211 public IBenchmarkSuiteDataDescriptor DataDescriptor 212 212 { 213 213 get { return DataParameter.Value; } … … 394 394 var bestIdx = Array.IndexOf(qualities, bestQuality); 395 395 var bestIndividual = individuals[bestIdx]; 396 var program = bestIndividual.PushProgram(config.EnabledExpressions); 397 var solution = new PushSolution(program, bestQuality, Data, random, pool); 396 var solution = new PushSolution(bestIndividual.IntegerVector(), bestQuality, DataDescriptor, random, config); 398 397 399 398 if (!results.ContainsKey(bestSolutionResultName)) { … … 405 404 406 405 public override double Evaluate(Individual individual, IRandom random) { 407 var program = individual.PushProgram(config.EnabledExpressions); 406 407 var program = individual.PushProgram(config.EnabledExpressions as IReadOnlyList<string>); 408 408 var expandExpression = new ExecExpandExpression(program); 409 409 var results = new List<double>(); … … 411 411 using (var interpreter = pool.GetInstance(random)) { 412 412 for (var i = DataBounds[0, 0]; i < DataBounds[0, 1]; i++) { 413 var example = Data.Examples[i];413 var example = this.DataDescriptor.Examples[i]; 414 414 415 415 interpreter.BooleanStack.Push(example.InputBoolean); … … 419 419 interpreter.Run(expandExpression); 420 420 421 var diff = GetDiff(example.OutputInt, interpreter.IntegerStack, Data.WorstResult, LongDiffer) +422 GetDiff(example.OutputFloat, interpreter.FloatStack, Data.WorstResult, DoubleDiffer) +423 GetDiff(example.OutputBoolean, interpreter.BooleanStack, Data.WorstResult, BooleanDiffer);421 var diff = GetDiff(example.OutputInt, interpreter.IntegerStack, this.DataDescriptor.WorstResult, LongDiffer) + 422 GetDiff(example.OutputFloat, interpreter.FloatStack, this.DataDescriptor.WorstResult, DoubleDiffer) + 423 GetDiff(example.OutputBoolean, interpreter.BooleanStack, this.DataDescriptor.WorstResult, BooleanDiffer); 424 424 425 425 results.Add(diff); … … 466 466 } 467 467 468 public void Load( Data data) {469 Data = data;470 BestKnownQuality = d ata.BestResult;468 public void Load(IBenchmarkSuiteDataDescriptor descriptor) { 469 this.DataDescriptor = descriptor; 470 BestKnownQuality = descriptor.BestResult; 471 471 472 472 DataBounds[0, 0] = 0; 473 DataBounds[0, 2] = Data.OriginalTrainingCount + Data.OriginalTestCount;474 DataBounds[0, 1] = Data.OriginalTrainingCount;473 DataBounds[0, 2] = this.DataDescriptor.OriginalTrainingCount + this.DataDescriptor.OriginalTestCount; 474 DataBounds[0, 1] = this.DataDescriptor.OriginalTrainingCount; 475 475 } 476 476 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/PushSolution.cs
r14733 r14744 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Problem { 2 using HeuristicLab.BenchmarkSuite .Problems;2 using HeuristicLab.BenchmarkSuite; 3 3 using HeuristicLab.Common; 4 4 using HeuristicLab.Core; 5 using HeuristicLab.Encodings.IntegerVectorEncoding; 6 using HeuristicLab.Optimization; 5 7 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 6 8 using HeuristicLab.Problems.ProgramSynthesis.Push.Configuration; 7 9 using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions; 8 using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter;9 10 10 11 [StorableClass] 11 12 public class PushSolution : NamedItem { 13 [Storable] 12 14 public readonly double Quality; 13 public readonly PushProgram Program; 14 public readonly Data Data; 15 [Storable] 16 public readonly IntegerVector IntegerVector; 17 [Storable] 18 public readonly IBenchmarkSuiteDataDescriptor DataDescriptor; 19 [Storable] 15 20 public readonly IRandom Random; 16 public readonly PushInterpreterPool Pool; 21 [Storable] 22 public readonly IReadonlyPushConfiguration Config; 17 23 18 public PushSolution(PushProgram program, double quality, Data data, 19 IRandom random, PushInterpreterPool pool) 24 public PushSolution(IntegerVector integerVector, double quality, IBenchmarkSuiteDataDescriptor dataDescriptor, IRandom random, IReadonlyPushConfiguration config) 20 25 : base("Solution", "A push solution.") { 21 Program = program;26 IntegerVector = integerVector; 22 27 Quality = quality; 23 Data = data;28 DataDescriptor = dataDescriptor; 24 29 Random = random; 25 Pool = pool;30 Config = config; 26 31 } 27 32 28 33 public PushSolution(PushSolution origin, Cloner cloner) : base(origin, cloner) { 29 Program = origin.Program;34 IntegerVector = origin.IntegerVector; 30 35 Quality = origin.Quality; 31 36 }
Note: See TracChangeset
for help on using the changeset viewer.