#region License Information /* HeuristicLab * Copyright (C) 2002-2016 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 HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using HeuristicLab.Random; namespace HeuristicLab.Problems.DataAnalysis.Symbolic { [StorableClass] public class FactorVariableTreeNode : VariableTreeNodeBase { public new FactorVariable Symbol { get { return (FactorVariable)base.Symbol; } } [Storable] private string variableValue; public string VariableValue { get { return variableValue; } set { variableValue = value; } } [StorableConstructor] protected FactorVariableTreeNode(bool deserializing) : base(deserializing) { } protected FactorVariableTreeNode(FactorVariableTreeNode original, Cloner cloner) : base(original, cloner) { variableValue = original.variableValue; } protected FactorVariableTreeNode() { } public FactorVariableTreeNode(FactorVariable variableSymbol) : base(variableSymbol) { } public override bool HasLocalParameters { get { return true; } } public override void ResetLocalParameters(IRandom random) { base.ResetLocalParameters(random); variableValue = Symbol.GetVariableValues(VariableName).SampleRandom(random); } public override void ShakeLocalParameters(IRandom random, double shakingFactor) { // 50% additive & 50% multiplicative if (random.NextDouble() < 0.5) { double x = NormalDistributedRandom.NextDouble(random, Symbol.WeightManipulatorMu, Symbol.WeightManipulatorSigma); Weight = Weight + x * shakingFactor; } else { double x = NormalDistributedRandom.NextDouble(random, 1.0, Symbol.MultiplicativeWeightManipulatorSigma); Weight = Weight * x; } if (random.NextDouble() < 0.2) { VariableName = Symbol.VariableNames.SampleRandom(random); } variableValue = Symbol.GetVariableValues(VariableName).SampleRandom(random); } public override IDeepCloneable Clone(Cloner cloner) { return new FactorVariableTreeNode(this, cloner); } public override string ToString() { return base.ToString() + " = " + variableValue; } } }