Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/26/17 19:34:13 (7 years ago)
Author:
pkimmesw
Message:

#2665 Fixed analyzer, fixed Plush encoding + operators, adpated print evaluation according to McPhee

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

Legend:

Unmodified
Added
Removed
  • branches/PushGP/HeuristicLab.PushGP

    • Property svn:ignore set to
      *.user
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Manipulator/UniformMutation.cs

    r15275 r15289  
    11namespace HeuristicLab.Problems.ProgramSynthesis.Push.Manipulator {
     2
    23  using HeuristicLab.Common;
    34  using HeuristicLab.Core;
     
    1112  using HeuristicLab.Problems.ProgramSynthesis.Push.Encoding;
    1213  using HeuristicLab.Problems.ProgramSynthesis.Push.Generators.CodeGenerator;
    13   using HeuristicLab.Random;
    1414
    1515  /// <summary>
     
    2323      Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic manipulation operators."));
    2424      Parameters.Add(new LookupParameter<PlushVector>("PlushVector", "The vector which should be manipulated."));
    25       Parameters.Add(new ValueLookupParameter<IntValue>("MinLength", "The min length of the vector."));
    26       Parameters.Add(new ValueLookupParameter<IntValue>("MaxLength", "The max length of the vector."));
    2725      Parameters.Add(new ValueLookupParameter<IReadOnlyExpressionsConfiguration>("Instructions", "The enabled instructions"));
    2826      Parameters.Add(new ValueLookupParameter<IReadOnlyErcOptions>("ErcOptions", "ERC options"));
    2927      Parameters.Add(new ValueLookupParameter<PercentValue>("InInstructionProbability", "The probability of IN Instructions"));
    3028
    31       Parameters.Add(new FixedValueParameter<PercentValue>("InstructionMutationProbability", "The probability a value gets mutated", new PercentValue(0.02)));
    32       Parameters.Add(new FixedValueParameter<DoubleValue>("CloseMutationDeviation", "When mutating individual, the amount of which the close marker is incremented or decrement is based on a random sample from a normal distribution with mean 0 and standard deviation set by the close mutation deviation parameter", new DoubleValue(1.0)));
     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)));
    3332    }
    3433
     
    5049    }
    5150
    52     public IValueParameter<PercentValue> CloseMutationDeviationParameter
     51    public IValueParameter<PercentValue> CloseMutationProbabilityParameter
    5352    {
    54       get { return (IValueParameter<PercentValue>)Parameters["CloseMutationDeviation"]; }
     53      get { return (IValueParameter<PercentValue>)Parameters["CloseMutationProbability"]; }
    5554    }
    5655
    57     public double CloseMutationDeviation
     56    public double CloseMutationProbability
    5857    {
    59       get { return CloseMutationDeviationParameter.Value.Value; }
    60       set { CloseMutationDeviationParameter.Value.Value = value; }
     58      get { return CloseMutationProbabilityParameter.Value.Value; }
     59      set { CloseMutationProbabilityParameter.Value.Value = value; }
     60    }
     61
     62    public IValueParameter<PercentValue> CloseIncrementRateParameter
     63    {
     64      get { return (IValueParameter<PercentValue>)Parameters["CloseIncrementRate"]; }
     65    }
     66
     67    public double CloseIncrementRate
     68    {
     69      get { return CloseIncrementRateParameter.Value.Value; }
     70      set { CloseIncrementRateParameter.Value.Value = value; }
    6171    }
    6272
     
    7282    {
    7383      get { return (ILookupParameter<PlushVector>)Parameters["PlushVector"]; }
    74     }
    75     public IValueLookupParameter<IntValue> MinLengthParameter
    76     {
    77       get { return (IValueLookupParameter<IntValue>)Parameters["MinLength"]; }
    78     }
    79     public IValueLookupParameter<IntValue> MaxLengthParameter
    80     {
    81       get { return (IValueLookupParameter<IntValue>)Parameters["MaxLength"]; }
    8284    }
    8385    public IValueLookupParameter<IReadOnlyExpressionsConfiguration> InstructionsParameter
     
    99101
    100102    public sealed override IOperation InstrumentedApply() {
    101       Manipulate(RandomParameter.ActualValue, PlushVectorParameter.ActualValue);
     103      Manipulate(
     104        RandomParameter.ActualValue,
     105        PlushVectorParameter.ActualValue,
     106        CloseIncrementRate,
     107        ErcOptionsParameter.ActualValue,
     108        InstructionsParameter.ActualValue,
     109        InInstructionProbabilityParameter.ActualValue.Value,
     110        CloseMutationProbability,
     111        InstructionMutationProbability);
    102112      return base.InstrumentedApply();
    103113    }
    104114
    105     private void Manipulate(IRandom random, PlushVector plushVector) {
    106       var normalDistributedRandom = new NormalDistributedRandom(random, 0, CloseMutationDeviation);
    107       var ercOptions = ErcOptionsParameter.ActualValue;
    108       var instructions = InstructionsParameter.ActualValue;
    109       var inInstructionProbability = InInstructionProbabilityParameter.ActualValue.Value;
    110       var instructionMutationProbability = InstructionMutationProbability;
     115    private static void Manipulate(
     116      IRandom random,
     117      PlushVector plushVector,
     118      double closeIncrementRate,
     119      IReadOnlyErcOptions ercOptions,
     120      IReadOnlyExpressionsConfiguration instructions,
     121      double inInstructionProbability,
     122      double closeMutationProbability,
     123      double instructionMutationProbability
     124      ) {
    111125
    112126      for (var i = 0; i < plushVector.Entries.Count; i++) {
     
    123137        }
    124138
    125         entry.Close += normalDistributedRandom.Next();
     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;
     147        }
    126148      }
    127149
Note: See TracChangeset for help on using the changeset viewer.