[14237] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[17180] | 3 | * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[14237] | 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 |
|
---|
[17573] | 22 | using System;
|
---|
[14237] | 23 | using HeuristicLab.Common;
|
---|
| 24 | using HeuristicLab.Core;
|
---|
| 25 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
[16565] | 26 | using HEAL.Attic;
|
---|
[14237] | 27 | using HeuristicLab.Random;
|
---|
[17573] | 28 |
|
---|
[14237] | 29 | namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
|
---|
[17573] | 30 | [StorableType("E79432BB-414D-4535-8751-D0139AF048E1")]
|
---|
| 31 | public class WindowedSymbolTreeNode : SymbolicExpressionTreeNode, IWindowedSymbolTreeNode {
|
---|
| 32 | public new WindowedSymbol Symbol {
|
---|
| 33 | get { return (WindowedSymbol)base.Symbol; }
|
---|
[14237] | 34 | }
|
---|
| 35 | [Storable]
|
---|
[17573] | 36 | private double offset;
|
---|
| 37 | public double Offset {
|
---|
| 38 | get { return offset; }
|
---|
| 39 | set { offset = Math.Min(Math.Max(value, 0.0), 1.0); }
|
---|
[14237] | 40 | }
|
---|
| 41 | [Storable]
|
---|
[17573] | 42 | private double length;
|
---|
| 43 | public double Length {
|
---|
| 44 | get { return length; }
|
---|
| 45 | set { length = Math.Min(Math.Max(value, 0.0), 1.0); }
|
---|
[14237] | 46 | }
|
---|
| 47 |
|
---|
| 48 | [StorableConstructor]
|
---|
[17573] | 49 | protected WindowedSymbolTreeNode(StorableConstructorFlag _) : base(_) { }
|
---|
| 50 | protected WindowedSymbolTreeNode(WindowedSymbolTreeNode original, Cloner cloner)
|
---|
[14237] | 51 | : base(original, cloner) {
|
---|
[17573] | 52 | offset = original.offset;
|
---|
| 53 | length = original.length;
|
---|
[14237] | 54 | }
|
---|
[17573] | 55 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 56 | return new WindowedSymbolTreeNode(this, cloner);
|
---|
| 57 | }
|
---|
[14237] | 58 |
|
---|
[17573] | 59 | public WindowedSymbolTreeNode(WindowedSymbol windowedSymbol) : base(windowedSymbol) {
|
---|
| 60 | if (!windowedSymbol.EnableWindowing) {
|
---|
| 61 | Offset = 0.0;
|
---|
| 62 | Length = 1.0;
|
---|
| 63 | }
|
---|
| 64 | }
|
---|
| 65 |
|
---|
[14237] | 66 | public override bool HasLocalParameters {
|
---|
[17573] | 67 | get { return Symbol.EnableWindowing; }
|
---|
[14237] | 68 | }
|
---|
| 69 |
|
---|
| 70 | public override void ResetLocalParameters(IRandom random) {
|
---|
| 71 | base.ResetLocalParameters(random);
|
---|
| 72 |
|
---|
[17573] | 73 | if (Symbol.EnableWindowing) {
|
---|
| 74 | Offset = NormalDistributedRandom.NextDouble(random, Symbol.OffsetMu, Symbol.OffsetSigma);
|
---|
| 75 | Length = NormalDistributedRandom.NextDouble(random, Symbol.LengthMu, Symbol.LengthSigma);
|
---|
| 76 | }
|
---|
[14237] | 77 | }
|
---|
| 78 |
|
---|
| 79 | public override void ShakeLocalParameters(IRandom random, double shakingFactor) {
|
---|
| 80 | base.ShakeLocalParameters(random, shakingFactor);
|
---|
[14815] | 81 |
|
---|
[17573] | 82 | if (Symbol.EnableWindowing) {
|
---|
| 83 | Offset += NormalDistributedRandom.NextDouble(random, Symbol.ManipulatorOffsetMu, Symbol.ManipulatorOffsetSigma) * shakingFactor;
|
---|
| 84 | Length += NormalDistributedRandom.NextDouble(random, Symbol.ManipulatorLengthMu, Symbol.ManipulatorLengthSigma) * shakingFactor;
|
---|
[14237] | 85 | }
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | public override string ToString() {
|
---|
[17573] | 89 | return Symbol.EnableWindowing
|
---|
| 90 | ? base.ToString() + $"[{Offset} : {Length}]"
|
---|
| 91 | : base.ToString();
|
---|
[14237] | 92 | }
|
---|
| 93 | }
|
---|
| 94 | }
|
---|