Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/21/17 11:33:53 (7 years ago)
Author:
pkimmesw
Message:

#2665 Testet Problems, Testet error functions, Small fixes, Created HL files

Location:
branches/PushGP/HeuristicLab.PushGP
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/PushGP/HeuristicLab.PushGP

    • Property svn:ignore
      •  

        old new  
        11*.user
         2packages
         3TestResults
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Manipulator/UniformMutation.cs

    r15289 r15334  
    1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Manipulator {
     1// ReSharper disable CompareOfFloatsByEqualityOperator
     2namespace HeuristicLab.Problems.ProgramSynthesis.Push.Manipulator {
    23
    34  using HeuristicLab.Common;
     
    910  using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    1011  using HeuristicLab.Problems.ProgramSynthesis.Base.Erc;
     12  using HeuristicLab.Problems.ProgramSynthesis.Base.Extensions;
    1113  using HeuristicLab.Problems.ProgramSynthesis.Push.Configuration;
    1214  using HeuristicLab.Problems.ProgramSynthesis.Push.Encoding;
     15  using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions;
    1316  using HeuristicLab.Problems.ProgramSynthesis.Push.Generators.CodeGenerator;
    1417
     
    2730      Parameters.Add(new ValueLookupParameter<PercentValue>("InInstructionProbability", "The probability of IN Instructions"));
    2831
    29       Parameters.Add(new FixedValueParameter<PercentValue>("InstructionMutationProbability", "The probability an instruction gets mutated", new PercentValue(0.02)));
    30       Parameters.Add(new FixedValueParameter<PercentValue>("CloseMutationProbability", "The probability close gets mutated", new PercentValue(0.02)));
    31       Parameters.Add(new FixedValueParameter<PercentValue>("CloseIncrementRate", "When mutating individual, the increment rate specifies if close should be increased or decreased by 1.", new PercentValue(0.5)));
     32      Parameters.Add(new FixedValueParameter<PercentValue>("InstructionMutationProbability", "The probability instructions get mutated", new PercentValue(0.8)));
     33      Parameters.Add(new FixedValueParameter<PercentValue>("InstructionMutationRate", "The probability an instruction gets mutated", new PercentValue(0.01)));
     34      Parameters.Add(new FixedValueParameter<PercentValue>("InstructionConstantTweakRate", "When mutating an instruction, this parameter specifies if mutation is related to the current type (e.g. INTEGER, FLOAT) or not. ", new PercentValue(0)));
     35      Parameters.Add(new FixedValueParameter<PercentValue>("CloseMutationProbability", "The probability close gets mutated", new PercentValue(0.2)));
     36      Parameters.Add(new FixedValueParameter<PercentValue>("CloseIncrementRate", "When mutating individual, the increment rate specifies if close should be increased or decreased by 1.", new PercentValue(0.1)));
    3237    }
    3338
     
    4752      get { return InstructionMutationProbabilityParameter.Value.Value; }
    4853      set { InstructionMutationProbabilityParameter.Value.Value = value; }
     54    }
     55
     56    public IValueParameter<PercentValue> InstructionMutationRateParameter
     57    {
     58      get { return (IValueParameter<PercentValue>)Parameters["InstructionMutationRate"]; }
     59    }
     60
     61    public double InstructionMutationRate
     62    {
     63      get { return InstructionMutationRateParameter.Value.Value; }
     64      set { InstructionMutationRateParameter.Value.Value = value; }
     65    }
     66
     67    public IValueParameter<PercentValue> InstructionConstantTweakRateParameter
     68    {
     69      get { return (IValueParameter<PercentValue>)Parameters["InstructionConstantTweakRate"]; }
     70    }
     71
     72    public double InstructionConstantTweakRate
     73    {
     74      get { return InstructionConstantTweakRateParameter.Value.Value; }
     75      set { InstructionConstantTweakRateParameter.Value.Value = value; }
    4976    }
    5077
     
    104131        RandomParameter.ActualValue,
    105132        PlushVectorParameter.ActualValue,
    106         CloseIncrementRate,
    107133        ErcOptionsParameter.ActualValue,
    108134        InstructionsParameter.ActualValue,
    109135        InInstructionProbabilityParameter.ActualValue.Value,
    110136        CloseMutationProbability,
    111         InstructionMutationProbability);
     137        CloseIncrementRate,
     138        InstructionMutationProbability,
     139        InstructionMutationRate,
     140        InstructionConstantTweakRate);
    112141      return base.InstrumentedApply();
    113142    }
     
    116145      IRandom random,
    117146      PlushVector plushVector,
    118       double closeIncrementRate,
    119147      IReadOnlyErcOptions ercOptions,
    120148      IReadOnlyExpressionsConfiguration instructions,
    121149      double inInstructionProbability,
    122150      double closeMutationProbability,
    123       double instructionMutationProbability
     151      double closeIncrementRate,
     152      double instructionMutationProbability,
     153      double instructionMutationRate,
     154      double constantTweakRate
    124155      ) {
    125156
    126       for (var i = 0; i < plushVector.Entries.Count; i++) {
    127         var entry = plushVector[i];
    128         var x = random.NextDouble();
    129 
    130         if (x < instructionMutationProbability) {
    131           var instruction = CodeGeneratorUtils.GetRandomExpression(
    132             random,
    133             ercOptions,
    134             instructions,
    135             inInstructionProbability);
    136           entry.Instruction = instruction;
     157      var x = random.NextDouble();
     158
     159      // instruction manipulation
     160      if (x < instructionMutationProbability) {
     161        if (instructionMutationRate == 0) return;
     162        for (var i = 0; i < plushVector.Entries.Count; i++) {
     163          MutateInstruction(random, ercOptions, instructions, inInstructionProbability, instructionMutationRate, constantTweakRate, plushVector[i]);
    137164        }
    138165
    139         x = random.NextDouble();
    140 
    141         if (x < closeMutationProbability) {
    142           x = random.NextDouble();
    143           entry.Close += x < closeIncrementRate ? 1 : -1;
    144 
    145           if (entry.Close < 0)
    146             entry.Close = 0;
     166        plushVector.UpdatePushProgram();
     167        return;
     168      }
     169
     170      // close manipulation
     171      if (x < instructionMutationProbability + closeMutationProbability) {
     172        if (closeIncrementRate == 0) return;
     173        for (var i = 0; i < plushVector.Entries.Count; i++) {
     174          MutateClose(random, closeIncrementRate, plushVector[i]);
    147175        }
     176
     177        plushVector.UpdatePushProgram();
     178        return;
    148179      }
    149 
    150       // specifies that the program cached within entry must be updated before reuse
    151       plushVector.UpdatePushProgram();
     180    }
     181
     182    private static void MutateClose(IRandom random, double closeIncrementRate, PlushEntry entry) {
     183      entry.Close += random.NextDouble() < closeIncrementRate ? 1 : -1;
     184
     185      if (entry.Close < 0)
     186        entry.Close = 0;
     187    }
     188
     189    private static void MutateInstruction(
     190      IRandom random,
     191      IReadOnlyErcOptions ercOptions,
     192      IReadOnlyExpressionsConfiguration instructions,
     193      double inInstructionProbability,
     194      double instructionMutationRate,
     195      double constantTweakRate,
     196      PlushEntry entry) {
     197
     198      if (random.NextDouble() >= instructionMutationRate)
     199        return;
     200
     201      var entryType = entry.Instruction.GetType();
     202
     203      if (constantTweakRate > 0 && random.NextDouble() < constantTweakRate &&
     204          entryType.IsSubclass(typeof(PushExpression<>))) {
     205        var attribute = ExpressionTable.TypeToAttributeTable[entryType];
     206        entry.Instruction = CodeGeneratorUtils.CreateRandomErcExpression(attribute.StackType, random, ercOptions);
     207        return;
     208      }
     209
     210      entry.Instruction = CodeGeneratorUtils.GetRandomExpression(
     211        random,
     212        ercOptions,
     213        instructions,
     214        inInstructionProbability);
    152215    }
    153216  }
Note: See TracChangeset for help on using the changeset viewer.