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/Crossover/AlternationCrossover.cs

    r15275 r15289  
    1010  using HeuristicLab.Parameters;
    1111  using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     12  using HeuristicLab.Problems.ProgramSynthesis.Base.Extensions;
    1213  using HeuristicLab.Problems.ProgramSynthesis.Push.Encoding;
    1314  using HeuristicLab.Random;
     
    2324    public AlternationCrossover() {
    2425      Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic crossover operators."));
     26
    2527      Parameters.Add(new ScopeTreeLookupParameter<PlushVector>("Parents", "The parent vectors which should be crossed."));
    2628      ParentsParameter.ActualName = "PlushVector";
     29
    2730      Parameters.Add(new LookupParameter<PlushVector>("Child", "The child vector resulting from the crossover."));
    2831      ChildParameter.ActualName = "PlushVector";
     32
    2933      Parameters.Add(new FixedValueParameter<PercentValue>("AlternationRate", "Specifies the probability of switching to another parent.", new PercentValue(0.5)));
    3034      Parameters.Add(new FixedValueParameter<DoubleValue>("AlignmentDeviation", "When alternating between parents, the index at which to continue copying may be offset backward or forward some amount based on a random sample from a normal distribution with mean 0 and standard deviation set by the alignment deviation parameter", new DoubleValue(1.0)));
     
    9094
    9195    public sealed override IOperation InstrumentedApply() {
    92       ChildParameter.ActualValue = Cross(RandomParameter.ActualValue, ParentsParameter.ActualValue);
     96      ChildParameter.ActualValue = Cross(
     97        RandomParameter.ActualValue,
     98        ParentsParameter.ActualValue,
     99        AlternationRate,
     100        MaxLength,
     101        AlignmentDeviation);
    93102      return base.InstrumentedApply();
    94103    }
    95104
    96     private PlushVector Cross(IRandom random, ItemArray<PlushVector> parents) {
    97       var normalDistributedRandom = new NormalDistributedRandom(random, Mean, AlignmentDeviation);
     105    private static PlushVector Cross(
     106      IRandom random,
     107      ItemArray<PlushVector> parents,
     108      double alternationRate,
     109      int maxChildLength,
     110      double alignmentDeviation) {
     111      var normalDistributedRandom = new NormalDistributedRandom(random, Mean, alignmentDeviation);
    98112      var maxLength = parents.Max(p => p.Entries.Count);
    99113      var parentIndex = random.Next(0, 2);
    100114      var parent = parents[parentIndex];
    101115      var child = new PlushVector(maxLength);
    102       var maxChildLength = MaxLength;
    103116
    104117      for (var i = 0; i < maxLength && child.Entries.Count <= maxChildLength; i++) {
     
    109122
    110123        // switch parent?
    111         if (random.NextDouble() < AlternationRate) {
     124        if (random.NextDouble() < alternationRate) {
    112125          parentIndex = parentIndex == 0 ? 1 : 0;
    113126          parent = parents[parentIndex];
    114           i += normalDistributedRandom.Next();
     127          i += normalDistributedRandom.NextRounded();
    115128          i = Math.Max(i, 0);
    116129        }
Note: See TracChangeset for help on using the changeset viewer.