Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/05/16 14:25:28 (8 years ago)
Author:
gkronber
Message:

#2650: work in progress..

File:
1 edited

Legend:

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

    r14185 r14237  
    2121
    2222using HeuristicLab.Common;
    23 using HeuristicLab.Core;
    24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2523using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    26 using HeuristicLab.Random;
    2724namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    2825  [StorableClass]
    29   public class VariableTreeNode : SymbolicExpressionTreeTerminalNode {
     26  public class VariableTreeNode : VariableTreeNodeBase {
    3027    public new Variable Symbol {
    3128      get { return (Variable)base.Symbol; }
    3229    }
    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 
    4630    [StorableConstructor]
    4731    protected VariableTreeNode(bool deserializing) : base(deserializing) { }
    4832    protected VariableTreeNode(VariableTreeNode original, Cloner cloner)
    4933      : base(original, cloner) {
    50       weight = original.weight;
    51       variableName = original.variableName;
    5234    }
    5335    protected VariableTreeNode() { }
    5436    public VariableTreeNode(Variable variableSymbol) : base(variableSymbol) { }
    5537
    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, 618
    65       variableName = Symbol.VariableNames.SelectRandom(random);
    66 #pragma warning restore 612, 618
    67     }
    68 
    69     public override void ShakeLocalParameters(IRandom random, double shakingFactor) {
    70       base.ShakeLocalParameters(random, shakingFactor);
    71       // 50% additive & 50% multiplicative
    72       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, 618
    80       variableName = Symbol.VariableNames.SelectRandom(random);
    81 #pragma warning restore 612, 618
    82     }
    83 
    8438    public override IDeepCloneable Clone(Cloner cloner) {
    8539      return new VariableTreeNode(this, cloner);
    8640    }
    87 
    88     public override string ToString() {
    89       if (weight.IsAlmost(1.0)) return variableName;
    90       else return weight.ToString("E4") + " " + variableName;
    91     }
    9241  }
    9342}
Note: See TracChangeset for help on using the changeset viewer.