- Timestamp:
- 07/20/17 11:39:53 (7 years ago)
- Location:
- branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push
- Files:
-
- 14 added
- 2 deleted
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Analyzer/IndividualZeroErrorAnalyzer.cs
r15273 r15275 22 22 private const string RESULT_PARAMETER_NAME = "Zero Error Individuals Per Case"; 23 23 private const string RESULT_PARAMETER_DESCRIPTION = "Relative frequency of instructions aggregated over the whole population."; 24 private const string Y_AXIS_TITLE = "Count if zero error individuals";24 private const string Y_AXIS_TITLE = "Count of zero error individuals"; 25 25 private const string X_AXIS_TITLE = "Case Index"; 26 26 private const string ROW_NAME = "Cases"; … … 36 36 37 37 Parameters.Add(new ScopeTreeLookupParameter<DoubleArray>( 38 PushProblem.CaseQualitiesScopeParameterName,38 IntegerVectorPushProblem.CaseQualitiesScopeParameterName, 39 39 "The quality of every single training case for each individual.")); 40 40 } … … 63 63 public ILookupParameter<ItemArray<DoubleArray>> CaseQualitiesParameter 64 64 { 65 get { return (ILookupParameter<ItemArray<DoubleArray>>)Parameters[ PushProblem.CaseQualitiesScopeParameterName]; }65 get { return (ILookupParameter<ItemArray<DoubleArray>>)Parameters[IntegerVectorPushProblem.CaseQualitiesScopeParameterName]; } 66 66 } 67 67 -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Encoding/PlushEncoding.cs
r15273 r15275 2 2 3 3 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Encoding { 4 using System; 5 using System.Linq; 4 6 5 7 using HeuristicLab.Common; 6 8 using HeuristicLab.Core; 9 using HeuristicLab.Data; 7 10 using HeuristicLab.Optimization; 11 using HeuristicLab.Parameters; 8 12 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 13 using HeuristicLab.PluginInfrastructure; 14 using HeuristicLab.Problems.ProgramSynthesis.Base.Erc; 15 using HeuristicLab.Problems.ProgramSynthesis.Push.Configuration; 16 using HeuristicLab.Problems.ProgramSynthesis.Push.Crossover; 17 using HeuristicLab.Problems.ProgramSynthesis.Push.Manipulator; 9 18 using HeuristicLab.Problems.ProgramSynthesis.Push.SolutionCreator; 10 19 … … 12 21 [StorableClass] 13 22 public class PlushEncoding : Encoding<IPlushCreator> { 23 24 public PlushEncoding() : this("Plush") { } 25 26 public PlushEncoding(string name) : base(name) { 27 minLengthParameter = new FixedValueParameter<IntValue>(Name + ".MinLength", new IntValue(25)); 28 maxLengthParameter = new FixedValueParameter<IntValue>(Name + ".MaxLength", new IntValue(100)); 29 minCloseParameter = new FixedValueParameter<IntValue>(Name + ".MinClose", new IntValue(0)); 30 maxCloseParameter = new FixedValueParameter<IntValue>(Name + ".MaxClose", new IntValue(3)); 31 closeBiasLevelParameter = new FixedValueParameter<DoubleValue>(Name + ".CloseBiasLevel", new DoubleValue(3d)); 32 instructionsParameter = new ValueParameter<IExpressionsConfiguration>(Name + ".Instructions"); 33 ercOptionsParameter = new ValueParameter<ErcOptions>(Name + ".ErcOptions"); 34 inInstructionProbabilityParameter = new FixedValueParameter<PercentValue>(Name + ".InInstructionProbability"); 35 36 Parameters.Add(instructionsParameter); 37 Parameters.Add(ercOptionsParameter); 38 Parameters.Add(inInstructionProbabilityParameter); 39 40 SolutionCreator = new PlushCreator(); 41 RegisterParameterEvents(); 42 DiscoverOperators(); 43 } 44 14 45 public PlushEncoding(bool deserializing) 15 46 : base(deserializing) { 16 47 } 17 48 18 public PlushEncoding( Encoding<IPlushCreator>original, Cloner cloner)49 public PlushEncoding(PlushEncoding original, Cloner cloner) 19 50 : base(original, cloner) { 20 } 21 22 public PlushEncoding(string name) 23 : base(name) { 51 minLengthParameter = cloner.Clone(original.minLengthParameter); 52 maxLengthParameter = cloner.Clone(original.maxLengthParameter); 53 } 54 55 [StorableHook(HookType.AfterDeserialization)] 56 private void AfterDeserialization() { 57 RegisterParameterEvents(); 58 DiscoverOperators(); 24 59 } 25 60 … … 28 63 } 29 64 65 #region events 66 67 private void OnMinLengthParameterChanged() { 68 RegisterMinLengthParameterEvents(); 69 ConfigureOperators(Operators); 70 } 71 private void OnMaxLengthParameterChanged() { 72 RegisterMaxLengthParameterEvents(); 73 ConfigureOperators(Operators); 74 } 75 private void OnMinCloseParameterChanged() { 76 RegisterMinCloseParameterEvents(); 77 ConfigureOperators(Operators); 78 } 79 private void OnMaxCloseParameterChanged() { 80 RegisterMaxCloseParameterEvents(); 81 ConfigureOperators(Operators); 82 } 83 private void OnCloseBiasLevelParameterChanged() { 84 RegisterCloseBiasLevelParameterEvents(); 85 ConfigureOperators(Operators); 86 } 87 private void OnErcOptionsParameterChanged() { 88 RegisterErcOptionsParameterEvents(); 89 ConfigureOperators(Operators); 90 } 91 private void OnInstructionsParameterChanged() { 92 RegisterInstructionsParameterEvents(); 93 ConfigureOperators(Operators); 94 } 95 private void OnInInstructionProbabilityParameterChanged() { 96 RegisterInInstructionProbabilityParameterEvents(); 97 ConfigureOperators(Operators); 98 } 99 100 private void RegisterParameterEvents() { 101 RegisterMinLengthParameterEvents(); 102 RegisterMaxLengthParameterEvents(); 103 RegisterMinCloseParameterEvents(); 104 RegisterMaxCloseParameterEvents(); 105 RegisterCloseBiasLevelParameterEvents(); 106 RegisterErcOptionsParameterEvents(); 107 RegisterInstructionsParameterEvents(); 108 RegisterInInstructionProbabilityParameterEvents(); 109 } 110 111 private void RegisterMinLengthParameterEvents() { 112 MinLengthParameter.ValueChanged += (o, s) => ConfigureOperators(Operators); 113 MinLengthParameter.Value.ValueChanged += (o, s) => ConfigureOperators(Operators); 114 } 115 116 private void RegisterMaxLengthParameterEvents() { 117 MaxLengthParameter.ValueChanged += (o, s) => ConfigureOperators(Operators); 118 MaxLengthParameter.Value.ValueChanged += (o, s) => ConfigureOperators(Operators); 119 } 120 121 private void RegisterMinCloseParameterEvents() { 122 MinCloseParameter.ValueChanged += (o, s) => ConfigureOperators(Operators); 123 MinCloseParameter.Value.ValueChanged += (o, s) => ConfigureOperators(Operators); 124 } 125 126 private void RegisterMaxCloseParameterEvents() { 127 MaxCloseParameter.ValueChanged += (o, s) => ConfigureOperators(Operators); 128 MaxCloseParameter.Value.ValueChanged += (o, s) => ConfigureOperators(Operators); 129 } 130 131 private void RegisterCloseBiasLevelParameterEvents() { 132 CloseBiasLevelParameter.ValueChanged += (o, s) => ConfigureOperators(Operators); 133 CloseBiasLevelParameter.Value.ValueChanged += (o, s) => ConfigureOperators(Operators); 134 } 135 136 private void RegisterInInstructionProbabilityParameterEvents() { 137 InInstructionProbabilityParameter.ValueChanged += (o, s) => ConfigureOperators(Operators); 138 InInstructionProbabilityParameter.Value.ValueChanged += (o, s) => ConfigureOperators(Operators); 139 } 140 141 private void RegisterErcOptionsParameterEvents() { 142 ErcOptionsParameter.ValueChanged += (o, s) => ConfigureOperators(Operators); 143 } 144 145 private void RegisterInstructionsParameterEvents() { 146 InstructionsParameter.ValueChanged += (o, s) => ConfigureOperators(Operators); 147 } 148 149 #endregion 150 151 #region Encoding Parameters 152 [Storable] 153 private IFixedValueParameter<IntValue> minLengthParameter; 154 public IFixedValueParameter<IntValue> MinLengthParameter 155 { 156 get { return minLengthParameter; } 157 set 158 { 159 if (value == null) throw new ArgumentNullException("Min length parameter must not be null."); 160 if (value.Value == null) throw new ArgumentNullException("Min length parameter value must not be null."); 161 if (minLengthParameter == value) return; 162 163 if (minLengthParameter != null) Parameters.Remove(minLengthParameter); 164 minLengthParameter = value; 165 Parameters.Add(minLengthParameter); 166 OnMinLengthParameterChanged(); 167 } 168 } 169 170 [Storable] 171 private IFixedValueParameter<IntValue> maxLengthParameter; 172 public IFixedValueParameter<IntValue> MaxLengthParameter 173 { 174 get { return maxLengthParameter; } 175 set 176 { 177 if (value == null) throw new ArgumentNullException("Max length parameter must not be null."); 178 if (value.Value == null) throw new ArgumentNullException("Max length parameter value must not be null."); 179 if (maxLengthParameter == value) return; 180 181 if (maxLengthParameter != null) Parameters.Remove(maxLengthParameter); 182 maxLengthParameter = value; 183 Parameters.Add(maxLengthParameter); 184 OnMaxLengthParameterChanged(); 185 } 186 } 187 188 [Storable] 189 private IFixedValueParameter<IntValue> minCloseParameter; 190 public IFixedValueParameter<IntValue> MinCloseParameter 191 { 192 get { return minCloseParameter; } 193 set 194 { 195 if (value == null) throw new ArgumentNullException("Min close parameter must not be null."); 196 if (value.Value == null) throw new ArgumentNullException("Min close parameter value must not be null."); 197 if (minCloseParameter == value) return; 198 199 if (minCloseParameter != null) Parameters.Remove(minCloseParameter); 200 minCloseParameter = value; 201 Parameters.Add(minCloseParameter); 202 OnMinCloseParameterChanged(); 203 } 204 } 205 206 [Storable] 207 private IFixedValueParameter<IntValue> maxCloseParameter; 208 public IFixedValueParameter<IntValue> MaxCloseParameter 209 { 210 get { return maxCloseParameter; } 211 set 212 { 213 if (value == null) throw new ArgumentNullException("Max close parameter must not be null."); 214 if (value.Value == null) throw new ArgumentNullException("Max close parameter value must not be null."); 215 if (maxCloseParameter == value) return; 216 217 if (maxCloseParameter != null) Parameters.Remove(maxCloseParameter); 218 maxCloseParameter = value; 219 Parameters.Add(maxCloseParameter); 220 OnMaxCloseParameterChanged(); 221 } 222 } 223 224 [Storable] 225 private IFixedValueParameter<DoubleValue> closeBiasLevelParameter; 226 public IFixedValueParameter<DoubleValue> CloseBiasLevelParameter 227 { 228 get { return closeBiasLevelParameter; } 229 set 230 { 231 if (value == null) throw new ArgumentNullException("Close bias level parameter must not be null."); 232 if (value.Value == null) throw new ArgumentNullException("Close bias level parameter value must not be null."); 233 if (closeBiasLevelParameter == value) return; 234 235 if (closeBiasLevelParameter != null) Parameters.Remove(closeBiasLevelParameter); 236 closeBiasLevelParameter = value; 237 Parameters.Add(closeBiasLevelParameter); 238 OnCloseBiasLevelParameterChanged(); 239 } 240 } 241 242 [Storable] 243 private IFixedValueParameter<PercentValue> inInstructionProbabilityParameter; 244 public IFixedValueParameter<PercentValue> InInstructionProbabilityParameter 245 { 246 get { return inInstructionProbabilityParameter; } 247 set 248 { 249 if (value == null) throw new ArgumentNullException("In instruciton probability parameter must not be null."); 250 if (value.Value == null) throw new ArgumentNullException("In instruciton probability parameter value must not be null."); 251 if (inInstructionProbabilityParameter == value) return; 252 253 if (inInstructionProbabilityParameter != null) Parameters.Remove(inInstructionProbabilityParameter); 254 inInstructionProbabilityParameter = value; 255 Parameters.Add(inInstructionProbabilityParameter); 256 OnInInstructionProbabilityParameterChanged(); 257 } 258 } 259 260 [Storable] 261 private IValueParameter<IExpressionsConfiguration> instructionsParameter; 262 public IValueParameter<IExpressionsConfiguration> InstructionsParameter 263 { 264 get { return instructionsParameter; } 265 set 266 { 267 if (value == null) throw new ArgumentNullException("Instructions paramter must not be null"); 268 if (instructionsParameter == value) return; 269 270 if (instructionsParameter != null) Parameters.Remove(instructionsParameter); 271 instructionsParameter = value; 272 Parameters.Add(instructionsParameter); 273 OnInstructionsParameterChanged(); 274 } 275 } 276 277 [Storable] 278 private IValueParameter<ErcOptions> ercOptionsParameter; 279 public IValueParameter<ErcOptions> ErcOptionsParameter 280 { 281 get { return ercOptionsParameter; } 282 set 283 { 284 if (value == null) throw new ArgumentNullException("ErcOptions paramter must not be null"); 285 if (ercOptionsParameter == value) return; 286 287 if (ercOptionsParameter != null) Parameters.Remove(ercOptionsParameter); 288 ercOptionsParameter = value; 289 Parameters.Add(ercOptionsParameter); 290 OnErcOptionsParameterChanged(); 291 } 292 } 293 294 public IExpressionsConfiguration Instructions 295 { 296 get { return InstructionsParameter.Value; } 297 set { InstructionsParameter.Value = value; } 298 } 299 300 public ErcOptions ErcOptions 301 { 302 get { return ErcOptionsParameter.Value; } 303 set { ErcOptionsParameter.Value = value; } 304 } 305 306 public int MinLength 307 { 308 get { return MinLengthParameter.Value.Value; } 309 set { MinLengthParameter.Value.Value = value; } 310 } 311 312 public int MaxLength 313 { 314 get { return MaxLengthParameter.Value.Value; } 315 set { MaxLengthParameter.Value.Value = value; } 316 } 317 318 public int MinClose 319 { 320 get { return MinCloseParameter.Value.Value; } 321 set { MinCloseParameter.Value.Value = value; } 322 } 323 324 public int MaxClose 325 { 326 get { return MaxCloseParameter.Value.Value; } 327 set { MaxCloseParameter.Value.Value = value; } 328 } 329 330 public double InInstructionProbability 331 { 332 get { return InInstructionProbabilityParameter.Value.Value; } 333 set { InInstructionProbabilityParameter.Value.Value = value; } 334 } 335 #endregion 336 337 #region Operator Discovery 338 private static readonly IEnumerable<Type> encodingSpecificOperatorTypes; 339 static PlushEncoding() { 340 encodingSpecificOperatorTypes = new List<Type>() { 341 typeof (IPlushOperator), 342 typeof (IPlushCreator), 343 typeof (IPlushCrossover), 344 typeof (IPlushManipulator), 345 }; 346 } 347 348 private void DiscoverOperators() { 349 var assembly = typeof(IPlushOperator).Assembly; 350 var discoveredTypes = ApplicationManager.Manager.GetTypes(encodingSpecificOperatorTypes, assembly, true, false, false); 351 var operators = discoveredTypes.Select(t => (IOperator)Activator.CreateInstance(t)); 352 var newOperators = operators.Except(Operators, new TypeEqualityComparer<IOperator>()).ToList(); 353 354 ConfigureOperators(newOperators); 355 foreach (var @operator in newOperators) 356 AddOperator(@operator); 357 } 358 #endregion 359 30 360 public override void ConfigureOperators(IEnumerable<IOperator> operators) { 31 //ConfigureBoundedOperators(operators.OfType<IBoundedIntegerVectorOperator>()); 32 //ConfigureCreators(operators.OfType<IPlushCreator>()); 33 //ConfigureCrossovers(operators.OfType<IIntegerVectorCrossover>()); 34 //ConfigureManipulators(operators.OfType<IIntegerVectorManipulator>()); 35 //ConfigureShakingOperators(operators.OfType<IIntegerVectorMultiNeighborhoodShakingOperator>()); 36 //ConfigureStrategyVectorOperator(operators.OfType<IIntegerVectorStdDevStrategyParameterOperator>()); 37 } 38 39 //private void ConfigureCreators(IEnumerable<IPlushCreator> creators) { 40 // foreach (var creator in creators) { 41 // creator.IntegerVectorParameter.ActualName = Name; 42 // creator.BoundsParameter.ActualName = BoundsParameter.Name; 43 // creator.LengthParameter.ActualName = LengthParameter.Name; 44 // } 45 //} 361 ConfigureCreators(operators.OfType<IPlushCreator>()); 362 ConfigureCrossovers(operators.OfType<IPlushCrossover>()); 363 ConfigureManipulators(operators.OfType<IPlushManipulator>()); 364 } 365 366 private void ConfigureCreators(IEnumerable<IPlushCreator> creators) { 367 foreach (var creator in creators) { 368 creator.PlushVectorParameter.ActualName = Name; 369 creator.MinLengthParameter.ActualName = MinLengthParameter.Name; 370 creator.MaxLengthParameter.ActualName = MaxLengthParameter.Name; 371 creator.MinCloseParameter.ActualName = MinCloseParameter.Name; 372 creator.MaxCloseParameter.ActualName = MinCloseParameter.Name; 373 creator.ErcOptionsParameter.ActualName = ErcOptionsParameter.Name; 374 creator.InstructionsParameter.ActualName = InstructionsParameter.Name; 375 creator.InInstructionProbabilityParameter.ActualName = InInstructionProbabilityParameter.Name; 376 } 377 } 378 379 private void ConfigureCrossovers(IEnumerable<IPlushCrossover> crossovers) { 380 foreach (var crossover in crossovers) { 381 crossover.ChildParameter.ActualName = Name; 382 crossover.ParentsParameter.ActualName = Name; 383 } 384 } 385 386 private void ConfigureManipulators(IEnumerable<IPlushManipulator> manipulators) { 387 foreach (var manipulator in manipulators) { 388 manipulator.PlushVectorParameter.ActualName = Name; 389 manipulator.PlushVectorParameter.Hidden = true; 390 391 manipulator.ErcOptionsParameter.ActualName = ErcOptionsParameter.Name; 392 manipulator.InstructionsParameter.ActualName = InstructionsParameter.Name; 393 manipulator.InInstructionProbabilityParameter.ActualName = InInstructionProbabilityParameter.Name; 394 } 395 } 396 } 397 398 public static class IndividualExtensionMethods { 399 public static PlushVector PlushVector(this Individual individual) { 400 var encoding = individual.GetEncoding<PlushEncoding>(); 401 return individual.PlushVector(encoding.Name); 402 } 403 404 public static PlushVector PlushVector(this Individual individual, string name) { 405 return (PlushVector)individual[name]; 406 } 46 407 } 47 408 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Encoding/PlushEntry.cs
r15273 r15275 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Encoding { 2 using HeuristicLab.Common; 3 using HeuristicLab.Core; 4 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 2 5 using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions; 3 6 4 public class PlushEntry { 7 [StorableClass] 8 public class PlushEntry : Item { 9 public PlushEntry() { } 10 11 public PlushEntry(bool deserializing) : base(deserializing) { } 12 13 public PlushEntry(PlushEntry origin, Cloner cloner) : base(origin, cloner) { 14 Instruction = cloner.Clone(origin.Instruction); 15 Close = origin.Close; 16 } 17 18 [Storable] 5 19 public Expression Instruction { get; set; } 20 [Storable] 6 21 public int Close { get; set; } 22 23 public override IDeepCloneable Clone(Cloner cloner) { 24 return new PlushEntry(this, cloner); 25 } 7 26 } 8 27 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Encoding/PlushVector.cs
r15273 r15275 5 5 using HeuristicLab.Core; 6 6 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 7 using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes; 8 using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions; 7 9 8 10 [StorableClass] 9 11 public class PlushVector : Item { 10 12 11 private List<PlushEntry> entries; 13 [Storable] 14 private readonly List<PlushEntry> entries; 15 public IReadOnlyList<PlushEntry> Entries { get { return entries; } } 12 16 13 public PlushVector() : this(0) { 14 15 } 17 public PlushVector() : this(0) { } 16 18 17 19 public PlushVector(int length) { … … 29 31 return new PlushVector(this, cloner); 30 32 } 33 34 private PushProgram pushProgram; 35 36 public PushProgram PushProgram 37 { 38 get 39 { 40 if (pushProgram == null) CreatePushProgram(); 41 return pushProgram; 42 } 43 } 44 45 private void CreatePushProgram() { 46 var close = 0; 47 var currentIndex = 0; 48 49 pushProgram = FromPlush(ref currentIndex, ref close, 0); 50 } 51 52 private PushProgram FromPlush( 53 ref int currentIndex, 54 ref int close, 55 int depth) { 56 57 if (currentIndex >= entries.Count) 58 return PushProgram.Empty; 59 60 var instructions = new List<Expression>(); 61 62 for (var i = currentIndex; i < entries.Count; i++) { 63 var entry = entries[i]; 64 var instructionType = entry.Instruction.GetType(); 65 66 close += entry.Close; 67 68 PushExpressionAttribute attribute; 69 if (ExpressionTable.TypeToAttributeTable.TryGetValue(instructionType, out attribute)) { 70 for (var blockIdx = 0u; blockIdx < attribute.ExecIn && currentIndex < entries.Count; blockIdx++) { 71 if (close != 0) { 72 close--; 73 instructions.Add(PushProgram.Empty); 74 } else { 75 currentIndex++; 76 var subProgram = FromPlush(ref currentIndex, ref close, depth + 1); 77 var subExpression = subProgram.Count == 1 ? subProgram.Expressions[0] : subProgram; 78 79 instructions.Add(subExpression); 80 } 81 } 82 } 83 84 instructions.Add(entry.Instruction); 85 86 if (close > 0 && depth > 0) { 87 close--; 88 break; 89 } 90 91 if (depth == 0) { 92 close = 0; 93 } 94 } 95 96 return new PushProgram(instructions); 97 } 98 99 public void UpdatePushProgram() { 100 pushProgram = null; 101 } 102 103 public void Add(PlushEntry entry) { 104 entries.Add(entry); 105 } 106 107 public PlushEntry this[int key] 108 { 109 get 110 { 111 return entries[key]; 112 } 113 } 31 114 } 32 115 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Generators/CodeGenerator/CodeGeneratorUtils.cs
r15273 r15275 57 57 var name = config.EnabledExpressions[index]; 58 58 return ExpressionTable.GetExpression(name); 59 } 60 61 public static Expression GetRandomExpression(IRandom random, IReadOnlyErcOptions ercOptions, IReadOnlyExpressionsConfiguration instructions, double inInstructionProbability) { 62 var x = random.NextDouble(); 63 var inInstructionRelativeProbability = ercOptions.ErcProbability + inInstructionProbability; 64 65 Expression expression; 66 67 if (ercOptions.ErcProbability > 0 && x <= ercOptions.ErcProbability) { 68 var stackType = instructions.ExpressionsPerStackCount.RandomWeightedOrDefault(random, pair => pair.Value).Key; 69 70 expression = stackType == default(StackTypes) 71 ? GetRandomExpression(random, instructions) 72 : CreateRandomErcExpression(stackType, random, ercOptions); 73 } else if ( 74 inInstructionProbability > 0 && 75 x <= inInstructionRelativeProbability && 76 instructions.InExpressionCount > 0) { 77 78 var nr = random.Next(0, instructions.InExpressionCount) + 1; 79 expression = ExpressionTable.InExpressionTable[nr]; 80 } else { 81 expression = GetRandomExpression(random, instructions); 82 } 83 84 return expression; 85 } 86 87 private static Expression GetRandomExpression( 88 IRandom random, 89 IReadOnlyExpressionsConfiguration instructionsConfig) { 90 var index = random.Next(0, instructionsConfig.EnabledExpressions.Count); 91 var expressionName = instructionsConfig.EnabledExpressions[index]; 92 var expression = ExpressionTable.GetExpression(expressionName); 93 94 return expression; 59 95 } 60 96 -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Selector/LexicaseSelector.cs
r15189 r15275 37 37 /// <summary> 38 38 /// A lexicase selection operator which considers all successful evaluated training cases for selection. 39 ///40 /// ToDo: LexicaseSelector and ICaseSingleObjectiveSelector are ISingleObjectiveOperator, which contains Maximization and Qualities which is not needed41 39 /// </summary> 42 40 [Item("LexicaseSelector", "A lexicase selection operator which considers all successful evaluated training cases for selection.")] … … 45 43 public ILookupParameter<ItemArray<DoubleArray>> CaseQualitiesParameter 46 44 { 47 get { return (ILookupParameter<ItemArray<DoubleArray>>)Parameters[ PushProblem.CaseQualitiesScopeParameterName]; }45 get { return (ILookupParameter<ItemArray<DoubleArray>>)Parameters[IntegerVectorPushProblem.CaseQualitiesScopeParameterName]; } 48 46 } 49 47 … … 57 55 public LexicaseSelector() { 58 56 Parameters.Add(new ScopeTreeLookupParameter<DoubleArray>( 59 PushProblem.CaseQualitiesScopeParameterName,57 IntegerVectorPushProblem.CaseQualitiesScopeParameterName, 60 58 "The quality of every single training case for each individual.")); 61 59 } … … 68 66 var selected = new IScope[count]; 69 67 var caseQualities = CaseQualitiesParameter.ActualValue; 70 var repeats = Math.Ceiling(count / (double)population.Count);68 var repeats = (int)Math.Ceiling(count / (double)population.Count); 71 69 var caseCount = caseQualities[0].Length; 72 70 var source = Enumerable.Range(0, population.Count).ToList(); … … 77 75 78 76 // copy list if required 79 var pool = k == repeats -1 ? source : new List<int>(source);77 var pool = repeats == 1 ? source : new List<int>(source); 80 78 var countLimit = Math.Min(count - k * population.Count, population.Count); 81 79 82 80 for (var i = 0; i < countLimit; i++) { 83 var bestIndividuals = pool;81 var candidates = pool; 84 82 85 for (var j = 0; j < fitnessCaseIndexes.Count && bestIndividuals.Count > 1; j++) 86 bestIndividuals = GetBestIndividuals(maximization, caseQualities, bestIndividuals, fitnessCaseIndexes[j]); 83 for (var j = 0; j < fitnessCaseIndexes.Count && candidates.Count > 1; j++) { 84 candidates = GetBestIndividuals(maximization, caseQualities, candidates, fitnessCaseIndexes[j]); 85 } 87 86 88 87 /* If only one individual remains, it is the chosen parent. If no more fitness cases are left, a parent is 89 88 chosen randomly from the remaining individuals */ 90 var bestIndividualIndex = bestIndividuals.Count == 1 ? bestIndividuals[0] : bestIndividuals.Random(random);89 var bestIndividualIndex = candidates.Count == 1 ? candidates[0] : candidates.Random(random); 91 90 var bestIndividual = population[bestIndividualIndex]; 92 91 -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/SolutionCreator/IPlushCreator.cs
r15273 r15275 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.SolutionCreator { 2 using HeuristicLab.Core; 3 using HeuristicLab.Data; 2 4 using HeuristicLab.Optimization; 5 using HeuristicLab.Problems.ProgramSynthesis.Base.Erc; 6 using HeuristicLab.Problems.ProgramSynthesis.Push.Configuration; 3 7 using HeuristicLab.Problems.ProgramSynthesis.Push.Encoding; 4 8 5 9 public interface IPlushCreator : ISolutionCreator, IPlushOperator { 6 10 IValueLookupParameter<IntValue> MinLengthParameter { get; } 11 IValueLookupParameter<IntValue> MaxLengthParameter { get; } 12 IValueLookupParameter<IntValue> MinCloseParameter { get; } 13 IValueLookupParameter<IntValue> MaxCloseParameter { get; } 14 IValueLookupParameter<PercentValue> InInstructionProbabilityParameter { get; } 15 IValueLookupParameter<IReadOnlyErcOptions> ErcOptionsParameter { get; } 16 IValueLookupParameter<IReadOnlyExpressionsConfiguration> InstructionsParameter { get; } 17 ILookupParameter<PlushVector> PlushVectorParameter { get; } 7 18 } 8 19 }
Note: See TracChangeset
for help on using the changeset viewer.