Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/05/15 11:09:38 (10 years ago)
Author:
abeham
Message:

#2253:

  • Changed parameter from fixedvalue to valuelookup to be consistent with other operators in binary encoding plugin
  • Added backwards compatibility region
  • Fixed several other inconsistencies
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Creators/RandomBinaryVectorCreator.cs

    r11411 r11909  
    2020#endregion
    2121
     22using System;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
     
    3536    private const string TrueProbabilityParameterName = "TruePropability";
    3637
    37     private IFixedValueParameter<DoubleValue> TrueProbabilityParameter {
    38       get { return (IFixedValueParameter<DoubleValue>)Parameters[TrueProbabilityParameterName]; }
     38    private IValueLookupParameter<DoubleValue> TrueProbabilityParameter {
     39      get { return (IValueLookupParameter<DoubleValue>)Parameters[TrueProbabilityParameterName]; }
    3940    }
    4041
    41     public double TrueProbability {
    42       get { return TrueProbabilityParameter.Value.Value; }
    43       set { TrueProbabilityParameter.Value.Value = value; }
     42    public DoubleValue TrueProbability {
     43      get { return TrueProbabilityParameter.Value; }
     44      set { TrueProbabilityParameter.Value = value; }
    4445    }
    4546
    4647    [StorableConstructor]
    4748    private RandomBinaryVectorCreator(bool deserializing) : base(deserializing) { }
    48 
    4949    private RandomBinaryVectorCreator(RandomBinaryVectorCreator original, Cloner cloner) : base(original, cloner) { }
    5050    public override IDeepCloneable Clone(Cloner cloner) { return new RandomBinaryVectorCreator(this, cloner); }
    51 
    5251    public RandomBinaryVectorCreator()
    5352      : base() {
    54       Parameters.Add(new FixedValueParameter<DoubleValue>(TrueProbabilityParameterName, "Probability of true value", new DoubleValue(0.5)));
     53      Parameters.Add(new ValueLookupParameter<DoubleValue>(TrueProbabilityParameterName, "Probability of true value", new DoubleValue(0.5)));
    5554    }
    5655
    5756    [StorableHook(HookType.AfterDeserialization)]
    5857    private void AfterDeserialization() {
     58      // BackwardsCompatibility3.3
     59      #region Backwards compatible code, remove with 3.4
     60      var defaultValue = 0.5;
     61      if (Parameters.ContainsKey(TrueProbabilityParameterName) && Parameters[TrueProbabilityParameterName] is IFixedValueParameter<DoubleValue>) {
     62        defaultValue = ((IFixedValueParameter<DoubleValue>)Parameters[TrueProbabilityParameterName]).Value.Value;
     63        Parameters.Remove(TrueProbabilityParameterName);
     64      }
    5965      if (!Parameters.ContainsKey(TrueProbabilityParameterName))
    60         Parameters.Add(new FixedValueParameter<DoubleValue>(TrueProbabilityParameterName, "Probability of true value", new DoubleValue(0.5)));
     66        Parameters.Add(new ValueLookupParameter<DoubleValue>(TrueProbabilityParameterName, "Probability of true value", new DoubleValue(defaultValue)));
     67      #endregion
    6168    }
    6269
     
    7481      //remove with HL 3.4
    7582      if (trueProbability.IsAlmost(0.5))
    76       result = new BinaryVector(length, random);
     83        result = new BinaryVector(length, random);
    7784      else {
    7885        var values = new bool[length];
     
    8592
    8693    protected override BinaryVector Create(IRandom random, IntValue length) {
    87       return Apply(random, length.Value, TrueProbability);
     94      if (TrueProbabilityParameter.ActualValue == null) throw new InvalidOperationException("RandomBinaryVectorCreator: Parameter " + TrueProbabilityParameter.ActualName + " could not be found.");
     95      return Apply(random, length.Value, TrueProbabilityParameter.ActualValue.Value);
    8896    }
    8997  }
Note: See TracChangeset for help on using the changeset viewer.