[3253] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[17180] | 3 | * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[3253] | 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 |
|
---|
[17604] | 22 | using System;
|
---|
[4722] | 23 | using HeuristicLab.Common;
|
---|
[4068] | 24 | using HeuristicLab.Core;
|
---|
[3253] | 25 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
[16565] | 26 | using HEAL.Attic;
|
---|
[3269] | 27 | using HeuristicLab.Random;
|
---|
[5532] | 28 | namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
|
---|
[16565] | 29 | [StorableType("247DBD04-18F2-4184-B6F5-6E283BF06FD0")]
|
---|
[3258] | 30 | public sealed class ConstantTreeNode : SymbolicExpressionTreeTerminalNode {
|
---|
[3269] | 31 | public new Constant Symbol {
|
---|
| 32 | get { return (Constant)base.Symbol; }
|
---|
| 33 | }
|
---|
[3253] | 34 |
|
---|
| 35 | private double constantValue;
|
---|
| 36 | [Storable]
|
---|
| 37 | public double Value {
|
---|
| 38 | get { return constantValue; }
|
---|
| 39 | set { constantValue = value; }
|
---|
| 40 | }
|
---|
[3485] | 41 |
|
---|
[17604] | 42 | public override Type DataType {
|
---|
| 43 | get { return typeof(double); }
|
---|
| 44 | }
|
---|
| 45 |
|
---|
[4722] | 46 | [StorableConstructor]
|
---|
[16565] | 47 | private ConstantTreeNode(StorableConstructorFlag _) : base(_) { }
|
---|
[3485] | 48 |
|
---|
[4722] | 49 | private ConstantTreeNode(ConstantTreeNode original, Cloner cloner)
|
---|
| 50 | : base(original, cloner) {
|
---|
[3253] | 51 | constantValue = original.constantValue;
|
---|
| 52 | }
|
---|
| 53 |
|
---|
[4722] | 54 | private ConstantTreeNode() : base() { }
|
---|
[3253] | 55 | public ConstantTreeNode(Constant constantSymbol) : base(constantSymbol) { }
|
---|
| 56 |
|
---|
[3442] | 57 | public override bool HasLocalParameters {
|
---|
| 58 | get {
|
---|
| 59 | return true;
|
---|
| 60 | }
|
---|
| 61 | }
|
---|
[3269] | 62 | public override void ResetLocalParameters(IRandom random) {
|
---|
| 63 | base.ResetLocalParameters(random);
|
---|
[3465] | 64 | var range = Symbol.MaxValue - Symbol.MinValue;
|
---|
[6180] | 65 | Value = random.NextDouble() * range + Symbol.MinValue;
|
---|
[3269] | 66 | }
|
---|
| 67 |
|
---|
[3512] | 68 | public override void ShakeLocalParameters(IRandom random, double shakingFactor) {
|
---|
| 69 | base.ShakeLocalParameters(random, shakingFactor);
|
---|
[5326] | 70 | // 50% additive & 50% multiplicative
|
---|
| 71 | if (random.NextDouble() < 0.5) {
|
---|
| 72 | double x = NormalDistributedRandom.NextDouble(random, Symbol.ManipulatorMu, Symbol.ManipulatorSigma);
|
---|
| 73 | Value = Value + x * shakingFactor;
|
---|
| 74 | } else {
|
---|
| 75 | double x = NormalDistributedRandom.NextDouble(random, 1.0, Symbol.MultiplicativeManipulatorSigma);
|
---|
| 76 | Value = Value * x;
|
---|
| 77 | }
|
---|
[3512] | 78 | }
|
---|
| 79 |
|
---|
[4722] | 80 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 81 | return new ConstantTreeNode(this, cloner);
|
---|
[3253] | 82 | }
|
---|
[3442] | 83 |
|
---|
| 84 | public override string ToString() {
|
---|
[3465] | 85 | return constantValue.ToString("E4");
|
---|
[3442] | 86 | }
|
---|
[3253] | 87 | }
|
---|
| 88 | }
|
---|