[5060] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[16565] | 3 | * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[5060] | 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using HeuristicLab.Common;
|
---|
| 24 | using HeuristicLab.Core;
|
---|
| 25 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
[16565] | 26 | using HEAL.Attic;
|
---|
[5060] | 27 | using HeuristicLab.Random;
|
---|
| 28 |
|
---|
[5532] | 29 | namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
|
---|
[16565] | 30 | [StorableType("D3076BBC-7CF3-4768-8C4B-3FC4FEF041B3")]
|
---|
[14826] | 31 | public sealed class VariableConditionTreeNode : SymbolicExpressionTreeNode, IVariableTreeNode {
|
---|
[5060] | 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]
|
---|
[16565] | 57 | private VariableConditionTreeNode(StorableConstructorFlag _) : base(_) { }
|
---|
[5060] | 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);
|
---|
[12422] | 76 |
|
---|
| 77 | #pragma warning disable 612, 618
|
---|
[5060] | 78 | variableName = Symbol.VariableNames.SelectRandom(random);
|
---|
[12422] | 79 | #pragma warning restore 612, 618
|
---|
| 80 |
|
---|
[5060] | 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;
|
---|
[12422] | 88 |
|
---|
| 89 | #pragma warning disable 612, 618
|
---|
[5060] | 90 | variableName = Symbol.VariableNames.SelectRandom(random);
|
---|
[12422] | 91 | #pragma warning restore 612, 618
|
---|
| 92 |
|
---|
[5060] | 93 | x = NormalDistributedRandom.NextDouble(random, Symbol.SlopeManipulatorMu, Symbol.SlopeManipulatorSigma);
|
---|
| 94 | slope = slope + x * shakingFactor;
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | public override string ToString() {
|
---|
[14345] | 98 | if (slope.IsAlmost(0.0) || Symbol.IgnoreSlope) {
|
---|
| 99 | return variableName + " < " + threshold.ToString("E4");
|
---|
| 100 | } else {
|
---|
[7671] | 101 | return variableName + " > " + threshold.ToString("E4") + Environment.NewLine +
|
---|
[14345] | 102 | "slope: " + slope.ToString("E4");
|
---|
| 103 | }
|
---|
[5060] | 104 | }
|
---|
| 105 | }
|
---|
| 106 | }
|
---|