Changeset 14237 for branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/VariableTreeNode.cs
- Timestamp:
- 08/05/16 14:25:28 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/VariableTreeNode.cs
r14185 r14237 21 21 22 22 using HeuristicLab.Common; 23 using HeuristicLab.Core;24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;25 23 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 using HeuristicLab.Random;27 24 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 28 25 [StorableClass] 29 public class VariableTreeNode : SymbolicExpressionTreeTerminalNode {26 public class VariableTreeNode : VariableTreeNodeBase { 30 27 public new Variable Symbol { 31 28 get { return (Variable)base.Symbol; } 32 29 } 33 [Storable]34 private double weight;35 public double Weight {36 get { return weight; }37 set { weight = value; }38 }39 [Storable]40 private string variableName;41 public string VariableName {42 get { return variableName; }43 set { variableName = value; }44 }45 46 30 [StorableConstructor] 47 31 protected VariableTreeNode(bool deserializing) : base(deserializing) { } 48 32 protected VariableTreeNode(VariableTreeNode original, Cloner cloner) 49 33 : base(original, cloner) { 50 weight = original.weight;51 variableName = original.variableName;52 34 } 53 35 protected VariableTreeNode() { } 54 36 public VariableTreeNode(Variable variableSymbol) : base(variableSymbol) { } 55 37 56 public override bool HasLocalParameters {57 get { return true; }58 }59 60 public override void ResetLocalParameters(IRandom random) {61 base.ResetLocalParameters(random);62 weight = NormalDistributedRandom.NextDouble(random, Symbol.WeightMu, Symbol.WeightSigma);63 64 #pragma warning disable 612, 61865 variableName = Symbol.VariableNames.SelectRandom(random);66 #pragma warning restore 612, 61867 }68 69 public override void ShakeLocalParameters(IRandom random, double shakingFactor) {70 base.ShakeLocalParameters(random, shakingFactor);71 // 50% additive & 50% multiplicative72 if (random.NextDouble() < 0) {73 double x = NormalDistributedRandom.NextDouble(random, Symbol.WeightManipulatorMu, Symbol.WeightManipulatorSigma);74 weight = weight + x * shakingFactor;75 } else {76 double x = NormalDistributedRandom.NextDouble(random, 1.0, Symbol.MultiplicativeWeightManipulatorSigma);77 weight = weight * x;78 }79 #pragma warning disable 612, 61880 variableName = Symbol.VariableNames.SelectRandom(random);81 #pragma warning restore 612, 61882 }83 84 38 public override IDeepCloneable Clone(Cloner cloner) { 85 39 return new VariableTreeNode(this, cloner); 86 40 } 87 88 public override string ToString() {89 if (weight.IsAlmost(1.0)) return variableName;90 else return weight.ToString("E4") + " " + variableName;91 }92 41 } 93 42 }
Note: See TracChangeset
for help on using the changeset viewer.