- Timestamp:
- 03/18/17 10:36:37 (8 years ago)
- 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 56 56 57 57 public override void ShakeLocalParameters(IRandom random, double shakingFactor) { 58 // 50% additive & 50% multiplicative 59 if 58 // 50% additive & 50% multiplicative (override of functionality of base class because of a BUG) 59 if(random.NextDouble() < 0.5) { 60 60 double x = NormalDistributedRandom.NextDouble(random, Symbol.WeightManipulatorMu, Symbol.WeightManipulatorSigma); 61 61 Weight = Weight + x * shakingFactor; … … 64 64 Weight = Weight * x; 65 65 } 66 if (random.NextDouble() < 0.2) { 66 if(random.NextDouble() < Symbol.VariableChangeProbability) { 67 var oldName = VariableName; 67 68 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); 68 72 } 69 73 variableValue = Symbol.GetVariableValues(VariableName).SampleRandom(random); -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/FactorVariableTreeNode.cs
r14717 r14758 75 75 76 76 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) { 78 89 VariableName = Symbol.VariableNames.SampleRandom(random); 79 90 if(weights.Length != Symbol.GetVariableValues(VariableName).Count()) { … … 83 94 .Select(_ => NormalDistributedRandom.NextDouble(random, 0, 1)) 84 95 .ToArray(); 85 }86 } else {87 // mutate only one randomly selected weight88 var idx = random.Next(weights.Length);89 // 50% additive & 50% multiplicative90 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;97 96 } 98 97 } -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/VariableBase.cs
r14238 r14758 34 34 get { return weightMu; } 35 35 set { 36 if 36 if(value != weightMu) { 37 37 weightMu = value; 38 38 OnChanged(EventArgs.Empty); … … 45 45 get { return weightSigma; } 46 46 set { 47 if 48 if 47 if(weightSigma < 0.0) throw new ArgumentException("Negative sigma is not allowed."); 48 if(value != weightSigma) { 49 49 weightSigma = value; 50 50 OnChanged(EventArgs.Empty); … … 57 57 get { return weightManipulatorMu; } 58 58 set { 59 if 59 if(value != weightManipulatorMu) { 60 60 weightManipulatorMu = value; 61 61 OnChanged(EventArgs.Empty); … … 68 68 get { return weightManipulatorSigma; } 69 69 set { 70 if 71 if 70 if(weightManipulatorSigma < 0.0) throw new ArgumentException("Negative sigma is not allowed."); 71 if(value != weightManipulatorSigma) { 72 72 weightManipulatorSigma = value; 73 73 OnChanged(EventArgs.Empty); … … 80 80 get { return multiplicativeWeightManipulatorSigma; } 81 81 set { 82 if 83 if 82 if(multiplicativeWeightManipulatorSigma < 0.0) throw new ArgumentException("Negative sigma is not allowed."); 83 if(value != multiplicativeWeightManipulatorSigma) { 84 84 multiplicativeWeightManipulatorSigma = value; 85 85 OnChanged(EventArgs.Empty); … … 87 87 } 88 88 } 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 89 101 private List<string> variableNames; 90 102 [Storable] … … 92 104 get { return variableNames; } 93 105 set { 94 if 106 if(value == null) throw new ArgumentNullException(); 95 107 variableNames.Clear(); 96 108 variableNames.AddRange(value); … … 104 116 get { return allVariableNames; } 105 117 set { 106 if 118 if(value == null) throw new ArgumentNullException(); 107 119 allVariableNames.Clear(); 108 120 allVariableNames.AddRange(value); … … 112 124 public override bool Enabled { 113 125 get { 114 if 126 if(variableNames.Count == 0) return false; 115 127 return base.Enabled; 116 128 } 117 129 set { 118 if 130 if(variableNames.Count == 0) base.Enabled = false; 119 131 else base.Enabled = value; 120 132 } … … 134 146 [StorableHook(HookType.AfterDeserialization)] 135 147 private void AfterDeserialization() { 136 if 148 if(allVariableNames == null || (allVariableNames.Count == 0 && variableNames.Count > 0)) { 137 149 allVariableNames = variableNames; 138 150 } … … 154 166 weightManipulatorSigma = original.weightManipulatorSigma; 155 167 multiplicativeWeightManipulatorSigma = original.multiplicativeWeightManipulatorSigma; 156 } 168 variableChangeProbability = original.variableChangeProbability; 169 } 157 170 protected VariableBase(string name, string description) 158 171 : base(name, description) { … … 162 175 weightManipulatorSigma = 0.05; 163 176 multiplicativeWeightManipulatorSigma = 0.03; 177 variableChangeProbability = 0.2; 164 178 variableNames = new List<string>(); 165 179 allVariableNames = new List<string>(); -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/VariableTreeNodeBase.cs
r14238 r14758 69 69 public override void ShakeLocalParameters(IRandom random, double shakingFactor) { 70 70 base.ShakeLocalParameters(random, shakingFactor); 71 // 50% additive & 50% multiplicative 72 if (random.NextDouble() < 0) { 71 if(random.NextDouble() < 0) { 73 72 double x = NormalDistributedRandom.NextDouble(random, Symbol.WeightManipulatorMu, Symbol.WeightManipulatorSigma); 74 73 weight = weight + x * shakingFactor; … … 77 76 weight = weight * x; 78 77 } 78 if(Symbol.VariableChangeProbability >= 1.0 || random.NextDouble() < Symbol.VariableChangeProbability) { 79 var oldName = variableName; 79 80 #pragma warning disable 612, 618 80 variableName = Symbol.VariableNames.SelectRandom(random);81 variableName = Symbol.VariableNames.SelectRandom(random); 81 82 #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!) 82 87 } 83 88 84 89 public override string ToString() { 85 if 90 if(weight.IsAlmost(1.0)) return variableName; 86 91 else return weight.ToString("E4") + " " + variableName; 87 92 }
Note: See TracChangeset
for help on using the changeset viewer.