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