#region License Information /* HeuristicLab * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; using HEAL.Attic; using HeuristicLab.Random; namespace HeuristicLab.Problems.DataAnalysis.Symbolic { [StorableType("E79432BB-414D-4535-8751-D0139AF048E1")] public class WindowedSymbolTreeNode : SymbolicExpressionTreeNode, IWindowedSymbolTreeNode { public new WindowedSymbol Symbol { get { return (WindowedSymbol)base.Symbol; } } [Storable] private double offset; public double Offset { get { return offset; } set { offset = Math.Min(Math.Max(value, 0.0), 1.0); } } [Storable] private double length; public double Length { get { return length; } set { length = Math.Min(Math.Max(value, 0.0), 1.0); } } [StorableConstructor] protected WindowedSymbolTreeNode(StorableConstructorFlag _) : base(_) { } protected WindowedSymbolTreeNode(WindowedSymbolTreeNode original, Cloner cloner) : base(original, cloner) { offset = original.offset; length = original.length; } public override IDeepCloneable Clone(Cloner cloner) { return new WindowedSymbolTreeNode(this, cloner); } public WindowedSymbolTreeNode(WindowedSymbol windowedSymbol) : base(windowedSymbol) { if (!windowedSymbol.EnableWindowing) { Offset = 0.0; Length = 1.0; } } public override bool HasLocalParameters { get { return Symbol.EnableWindowing; } } public override void ResetLocalParameters(IRandom random) { base.ResetLocalParameters(random); if (Symbol.EnableWindowing) { Offset = NormalDistributedRandom.NextDouble(random, Symbol.OffsetMu, Symbol.OffsetSigma); Length = NormalDistributedRandom.NextDouble(random, Symbol.LengthMu, Symbol.LengthSigma); } } public override void ShakeLocalParameters(IRandom random, double shakingFactor) { base.ShakeLocalParameters(random, shakingFactor); if (Symbol.EnableWindowing) { Offset += NormalDistributedRandom.NextDouble(random, Symbol.ManipulatorOffsetMu, Symbol.ManipulatorOffsetSigma) * shakingFactor; Length += NormalDistributedRandom.NextDouble(random, Symbol.ManipulatorLengthMu, Symbol.ManipulatorLengthSigma) * shakingFactor; } } public override string ToString() { return Symbol.EnableWindowing ? base.ToString() + $"[{Offset:f3} : {Length:f3}]" : base.ToString(); } } }