Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/VariableConditionTreeNode.cs @ 7461

Last change on this file since 7461 was 5809, checked in by mkommend, 14 years ago

#1418: Reintegrated branch into trunk.

File size: 3.6 KB
RevLine 
[5060]1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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 HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27using HeuristicLab.Random;
28
[5532]29namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
[5060]30  [StorableClass]
31  public sealed class VariableConditionTreeNode : SymbolicExpressionTreeNode {
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(bool deserializing) : base(deserializing) { }
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      variableName = Symbol.VariableNames.SelectRandom(random);
77      slope = NormalDistributedRandom.NextDouble(random, Symbol.SlopeInitializerMu, Symbol.SlopeInitializerSigma);
78    }
79
80    public override void ShakeLocalParameters(IRandom random, double shakingFactor) {
81      base.ShakeLocalParameters(random, shakingFactor);
82      double x = NormalDistributedRandom.NextDouble(random, Symbol.ThresholdManipulatorMu, Symbol.ThresholdManipulatorSigma);
83      threshold = threshold + x * shakingFactor;
84      variableName = Symbol.VariableNames.SelectRandom(random);
85      x = NormalDistributedRandom.NextDouble(random, Symbol.SlopeManipulatorMu, Symbol.SlopeManipulatorSigma);
86      slope = slope + x * shakingFactor;
87    }
88
89    public override string ToString() {
90      return variableName + " > " + threshold.ToString("E4") + Environment.NewLine +
91        "slope: " + slope.ToString("E4");
92    }
93  }
94}
Note: See TracBrowser for help on using the repository browser.