Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/VariableConditionTreeNode.cs @ 18027

Last change on this file since 18027 was 17181, checked in by swagner, 5 years ago

#2875: Merged r17180 from trunk to stable

File size: 3.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
26using HEAL.Attic;
27using HeuristicLab.Random;
28
29namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
30  [StorableType("D3076BBC-7CF3-4768-8C4B-3FC4FEF041B3")]
31  public sealed class VariableConditionTreeNode : SymbolicExpressionTreeNode, IVariableTreeNode {
32    #region properties
33    public new VariableCondition Symbol {
34      get { return (VariableCondition)base.Symbol; }
35    }
36    [Storable]
37    private double threshold;
38    public double Threshold {
39      get { return threshold; }
40      set { threshold = value; }
41    }
42    [Storable]
43    private string variableName;
44    public string VariableName {
45      get { return variableName; }
46      set { variableName = value; }
47    }
48    [Storable]
49    private double slope;
50    public double Slope {
51      get { return slope; }
52      set { slope = value; }
53    }
54    #endregion
55
56    [StorableConstructor]
57    private VariableConditionTreeNode(StorableConstructorFlag _) : base(_) { }
58    private VariableConditionTreeNode(VariableConditionTreeNode original, Cloner cloner)
59      : base(original, cloner) {
60      threshold = original.threshold;
61      variableName = original.variableName;
62      slope = original.slope;
63    }
64    public override IDeepCloneable Clone(Cloner cloner) {
65      return new VariableConditionTreeNode(this, cloner);
66    }
67
68    public VariableConditionTreeNode(VariableCondition variableConditionSymbol) : base(variableConditionSymbol) { }
69    public override bool HasLocalParameters {
70      get { return true; }
71    }
72
73    public override void ResetLocalParameters(IRandom random) {
74      base.ResetLocalParameters(random);
75      threshold = NormalDistributedRandom.NextDouble(random, Symbol.ThresholdInitializerMu, Symbol.ThresholdInitializerSigma);
76
77#pragma warning disable 612, 618
78      variableName = Symbol.VariableNames.SelectRandom(random);
79#pragma warning restore 612, 618
80
81      slope = NormalDistributedRandom.NextDouble(random, Symbol.SlopeInitializerMu, Symbol.SlopeInitializerSigma);
82    }
83
84    public override void ShakeLocalParameters(IRandom random, double shakingFactor) {
85      base.ShakeLocalParameters(random, shakingFactor);
86      double x = NormalDistributedRandom.NextDouble(random, Symbol.ThresholdManipulatorMu, Symbol.ThresholdManipulatorSigma);
87      threshold = threshold + x * shakingFactor;
88
89#pragma warning disable 612, 618
90      variableName = Symbol.VariableNames.SelectRandom(random);
91#pragma warning restore 612, 618
92
93      x = NormalDistributedRandom.NextDouble(random, Symbol.SlopeManipulatorMu, Symbol.SlopeManipulatorSigma);
94      slope = slope + x * shakingFactor;
95    }
96
97    public override string ToString() {
98      if (slope.IsAlmost(0.0) || Symbol.IgnoreSlope) {
99        return variableName + " < " + threshold.ToString("E4");
100      } else {
101        return variableName + " > " + threshold.ToString("E4") + Environment.NewLine +
102               "slope: " + slope.ToString("E4");
103      }
104    }
105  }
106}
Note: See TracBrowser for help on using the repository browser.