Changeset 17871


Ignore:
Timestamp:
03/09/21 11:24:27 (18 months ago)
Author:
gkronber
Message:

#3067 changed CrossoverProbabilityParameter to PercentValue and return parent0 when no crossover is performed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Crossovers/SubtreeCrossover.cs

    r17491 r17871  
    5555      get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeDepthParameterName]; }
    5656    }
    57     public IFixedValueParameter<DoubleValue> CrossoverProbabilityParameter {
    58       get { return (IFixedValueParameter<DoubleValue>)Parameters[CrossoverProbabilityParameterName]; }
     57    public IFixedValueParameter<PercentValue> CrossoverProbabilityParameter {
     58      get { return (IFixedValueParameter<PercentValue>)Parameters[CrossoverProbabilityParameterName]; }
    5959    }
    6060    #endregion
     
    8181      Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName, "The maximal length (number of nodes) of the symbolic expression tree."));
    8282      Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName, "The maximal depth of the symbolic expression tree (a tree with one node has depth = 0)."));
    83       Parameters.Add(new ValueLookupParameter<PercentValue>(InternalCrossoverPointProbabilityParameterName, "The probability to select an internal crossover point (instead of a leaf node).", new PercentValue(0.9)));
    84       Parameters.Add(new FixedValueParameter<DoubleValue>(CrossoverProbabilityParameterName, "", new DoubleValue(1)));
     83      Parameters.Add(new ValueLookupParameter<PercentValue>(InternalCrossoverPointProbabilityParameterName, "The probability to select an internal crossover point (instead of a leaf node).", new PercentValue(0.9, true)));
     84      Parameters.Add(new FixedValueParameter<PercentValue>(CrossoverProbabilityParameterName, "The probability that a crossover is performed. Otherwise a copy of the first parent is returned.", new PercentValue(1, true)));
    8585    }
    8686
    8787    [StorableHook(HookType.AfterDeserialization)]
    8888    private void AfterDeserialization() {
     89      // replace with PercentValue for files which had CrossoverProbability as DoubleValue
     90      if (Parameters.ContainsKey(CrossoverProbabilityParameterName)) {
     91        var oldValue = ((IFixedValueParameter<DoubleValue>)Parameters[CrossoverProbabilityParameterName]).Value.Value;
     92        Parameters.Remove(CrossoverProbabilityParameterName);
     93        Parameters.Add(new FixedValueParameter<PercentValue>(CrossoverProbabilityParameterName, "The probability that a crossover is performed. Otherwise a copy of the first parent is returned.", new PercentValue(oldValue)));
     94      }
    8995      if (!Parameters.ContainsKey(CrossoverProbabilityParameterName)) {
    90         Parameters.Add(new FixedValueParameter<DoubleValue>(CrossoverProbabilityParameterName, "", new DoubleValue(1)));
     96        Parameters.Add(new FixedValueParameter<PercentValue>(CrossoverProbabilityParameterName, "The probability that a crossover is performed. Otherwise a copy of the first parent is returned.", new PercentValue(1, true)));
    9197      }
    9298    }
     
    106112      double probability,
    107113      double internalCrossoverPointProbability, int maxTreeLength, int maxTreeDepth) {
    108       if ((probability < 1) && (random.NextDouble() >= probability)) return random.NextDouble() < 0.5 ? parent0 : parent1;
     114      if ((probability < 1) && (random.NextDouble() >= probability)) return parent0;
    109115      // select a random crossover point in the first parent
    110116      CutPoint crossoverPoint0;
Note: See TracChangeset for help on using the changeset viewer.