Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/18/17 10:36:37 (8 years ago)
Author:
gkronber
Message:

#2650 unified mutation behaviour for all variable tree nodes. Introduced parameter for probability of changing a variable.

Location:
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/BinaryFactorVariableTreeNode.cs

    r14554 r14758  
    5656
    5757    public override void ShakeLocalParameters(IRandom random, double shakingFactor) {
    58       // 50% additive & 50% multiplicative
    59       if (random.NextDouble() < 0.5) {
     58      // 50% additive & 50% multiplicative (override of functionality of base class because of a BUG)
     59      if(random.NextDouble() < 0.5) {
    6060        double x = NormalDistributedRandom.NextDouble(random, Symbol.WeightManipulatorMu, Symbol.WeightManipulatorSigma);
    6161        Weight = Weight + x * shakingFactor;
     
    6464        Weight = Weight * x;
    6565      }
    66       if (random.NextDouble() < 0.2) {
     66      if(random.NextDouble() < Symbol.VariableChangeProbability) {
     67        var oldName = VariableName;
    6768        VariableName = Symbol.VariableNames.SampleRandom(random);
     69        // reinitialize weights if variable has changed (similar to FactorVariableTreeNode)
     70        if(oldName != VariableName)
     71          Weight = NormalDistributedRandom.NextDouble(random, Symbol.WeightMu, Symbol.WeightSigma);
    6872      }
    6973      variableValue = Symbol.GetVariableValues(VariableName).SampleRandom(random);
  • branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/FactorVariableTreeNode.cs

    r14717 r14758  
    7575
    7676    public override void ShakeLocalParameters(IRandom random, double shakingFactor) {
    77       if(random.NextDouble() < 0.2) {
     77      // mutate only one randomly selected weight
     78      var idx = random.Next(weights.Length);
     79      // 50% additive & 50% multiplicative
     80      if(random.NextDouble() < 0.5) {
     81        double x = NormalDistributedRandom.NextDouble(random, Symbol.WeightManipulatorMu,
     82          Symbol.WeightManipulatorSigma);
     83        weights[idx] = weights[idx] + x * shakingFactor;
     84      } else {
     85        double x = NormalDistributedRandom.NextDouble(random, 1.0, Symbol.MultiplicativeWeightManipulatorSigma);
     86        weights[idx] = weights[idx] * x;
     87      }
     88      if(random.NextDouble() < Symbol.VariableChangeProbability) {
    7889        VariableName = Symbol.VariableNames.SampleRandom(random);
    7990        if(weights.Length != Symbol.GetVariableValues(VariableName).Count()) {
     
    8394              .Select(_ => NormalDistributedRandom.NextDouble(random, 0, 1))
    8495              .ToArray();
    85         }
    86       } else {
    87         // mutate only one randomly selected weight
    88         var idx = random.Next(weights.Length);
    89         // 50% additive & 50% multiplicative
    90         if(random.NextDouble() < 0.5) {
    91           double x = NormalDistributedRandom.NextDouble(random, Symbol.WeightManipulatorMu,
    92             Symbol.WeightManipulatorSigma);
    93           weights[idx] = weights[idx] + x * shakingFactor;
    94         } else {
    95           double x = NormalDistributedRandom.NextDouble(random, 1.0, Symbol.MultiplicativeWeightManipulatorSigma);
    96           weights[idx] = weights[idx] * x;
    9796        }
    9897      }
  • branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/VariableBase.cs

    r14238 r14758  
    3434      get { return weightMu; }
    3535      set {
    36         if (value != weightMu) {
     36        if(value != weightMu) {
    3737          weightMu = value;
    3838          OnChanged(EventArgs.Empty);
     
    4545      get { return weightSigma; }
    4646      set {
    47         if (weightSigma < 0.0) throw new ArgumentException("Negative sigma is not allowed.");
    48         if (value != weightSigma) {
     47        if(weightSigma < 0.0) throw new ArgumentException("Negative sigma is not allowed.");
     48        if(value != weightSigma) {
    4949          weightSigma = value;
    5050          OnChanged(EventArgs.Empty);
     
    5757      get { return weightManipulatorMu; }
    5858      set {
    59         if (value != weightManipulatorMu) {
     59        if(value != weightManipulatorMu) {
    6060          weightManipulatorMu = value;
    6161          OnChanged(EventArgs.Empty);
     
    6868      get { return weightManipulatorSigma; }
    6969      set {
    70         if (weightManipulatorSigma < 0.0) throw new ArgumentException("Negative sigma is not allowed.");
    71         if (value != weightManipulatorSigma) {
     70        if(weightManipulatorSigma < 0.0) throw new ArgumentException("Negative sigma is not allowed.");
     71        if(value != weightManipulatorSigma) {
    7272          weightManipulatorSigma = value;
    7373          OnChanged(EventArgs.Empty);
     
    8080      get { return multiplicativeWeightManipulatorSigma; }
    8181      set {
    82         if (multiplicativeWeightManipulatorSigma < 0.0) throw new ArgumentException("Negative sigma is not allowed.");
    83         if (value != multiplicativeWeightManipulatorSigma) {
     82        if(multiplicativeWeightManipulatorSigma < 0.0) throw new ArgumentException("Negative sigma is not allowed.");
     83        if(value != multiplicativeWeightManipulatorSigma) {
    8484          multiplicativeWeightManipulatorSigma = value;
    8585          OnChanged(EventArgs.Empty);
     
    8787      }
    8888    }
     89
     90    [Storable(DefaultValue = 1.0)]
     91    private double variableChangeProbability;
     92
     93    public double VariableChangeProbability {
     94      get { return VariableChangeProbability; }
     95      set {
     96        if(value < 0 || value > 1.0) throw new ArgumentException("Variable change probability must lie in the interval [0..1]");
     97        variableChangeProbability = value;
     98      }
     99    }
     100
    89101    private List<string> variableNames;
    90102    [Storable]
     
    92104      get { return variableNames; }
    93105      set {
    94         if (value == null) throw new ArgumentNullException();
     106        if(value == null) throw new ArgumentNullException();
    95107        variableNames.Clear();
    96108        variableNames.AddRange(value);
     
    104116      get { return allVariableNames; }
    105117      set {
    106         if (value == null) throw new ArgumentNullException();
     118        if(value == null) throw new ArgumentNullException();
    107119        allVariableNames.Clear();
    108120        allVariableNames.AddRange(value);
     
    112124    public override bool Enabled {
    113125      get {
    114         if (variableNames.Count == 0) return false;
     126        if(variableNames.Count == 0) return false;
    115127        return base.Enabled;
    116128      }
    117129      set {
    118         if (variableNames.Count == 0) base.Enabled = false;
     130        if(variableNames.Count == 0) base.Enabled = false;
    119131        else base.Enabled = value;
    120132      }
     
    134146    [StorableHook(HookType.AfterDeserialization)]
    135147    private void AfterDeserialization() {
    136       if (allVariableNames == null || (allVariableNames.Count == 0 && variableNames.Count > 0)) {
     148      if(allVariableNames == null || (allVariableNames.Count == 0 && variableNames.Count > 0)) {
    137149        allVariableNames = variableNames;
    138150      }
     
    154166      weightManipulatorSigma = original.weightManipulatorSigma;
    155167      multiplicativeWeightManipulatorSigma = original.multiplicativeWeightManipulatorSigma;
    156     }
     168      variableChangeProbability = original.variableChangeProbability;
     169      }
    157170    protected VariableBase(string name, string description)
    158171      : base(name, description) {
     
    162175      weightManipulatorSigma = 0.05;
    163176      multiplicativeWeightManipulatorSigma = 0.03;
     177      variableChangeProbability = 0.2;
    164178      variableNames = new List<string>();
    165179      allVariableNames = new List<string>();
  • branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/VariableTreeNodeBase.cs

    r14238 r14758  
    6969    public override void ShakeLocalParameters(IRandom random, double shakingFactor) {
    7070      base.ShakeLocalParameters(random, shakingFactor);
    71       // 50% additive & 50% multiplicative
    72       if (random.NextDouble() < 0) {
     71      if(random.NextDouble() < 0) {
    7372        double x = NormalDistributedRandom.NextDouble(random, Symbol.WeightManipulatorMu, Symbol.WeightManipulatorSigma);
    7473        weight = weight + x * shakingFactor;
     
    7776        weight = weight * x;
    7877      }
     78      if(Symbol.VariableChangeProbability >= 1.0 || random.NextDouble() < Symbol.VariableChangeProbability) {
     79        var oldName = variableName;
    7980#pragma warning disable 612, 618
    80       variableName = Symbol.VariableNames.SelectRandom(random);
     81        variableName = Symbol.VariableNames.SelectRandom(random);
    8182#pragma warning restore 612, 618
     83        if(oldName != variableName) {
     84          weight = NormalDistributedRandom.NextDouble(random, Symbol.WeightMu, Symbol.WeightSigma);
     85        }
     86      }      // 50% additive & 50% multiplicative (BUG in if statement below!)
    8287    }
    8388
    8489    public override string ToString() {
    85       if (weight.IsAlmost(1.0)) return variableName;
     90      if(weight.IsAlmost(1.0)) return variableName;
    8691      else return weight.ToString("E4") + " " + variableName;
    8792    }
Note: See TracChangeset for help on using the changeset viewer.