#region License Information /* HeuristicLab * Copyright (C) 2002-2019 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.Data; using HeuristicLab.Operators; using HeuristicLab.Parameters; using HEAL.Attic; namespace HeuristicLab.Random { /// /// Normally distributed random number generator. /// [StorableType("0EAF4184-6C98-4C9D-80A1-09A42E03450E")] [Item("NormalRandomizer", "Initializes the value of variable 'Value' to a random value normally distributed with parameters 'Mu' and 'Sigma'")] public class NormalRandomizer : SingleSuccessorOperator { #region Parameter Properties public ILookupParameter RandomParameter { get { return (ILookupParameter)Parameters["Random"]; } } public IValueLookupParameter MuParameter { get { return (IValueLookupParameter)Parameters["Mu"]; } } public IValueLookupParameter SigmaParameter { get { return (IValueLookupParameter)Parameters["Sigma"]; } } public ILookupParameter ValueParameter { get { return (ILookupParameter)Parameters["Value"]; } } #endregion #region Properties public DoubleValue Mu { get { return MuParameter.ActualValue; } set { MuParameter.ActualValue = value; } } public DoubleValue Max { get { return SigmaParameter.ActualValue; } set { SigmaParameter.ActualValue = value; } } #endregion [StorableConstructor] protected NormalRandomizer(StorableConstructorFlag _) : base(_) { } protected NormalRandomizer(NormalRandomizer original, Cloner cloner) : base(original, cloner) { } /// /// Initializes a new instance of with four variable infos /// (Mu, Sigma, Value and Random). /// public NormalRandomizer() { Parameters.Add(new LookupParameter("Random", "A random generator that supplies uniformly distributed values.")); Parameters.Add(new ValueLookupParameter("Mu", "Mu parameter of the normal distribution (N(mu,sigma)).")); Parameters.Add(new ValueLookupParameter("Sigma", "Sigma parameter of the normal distribution (N(mu,sigma)).")); Parameters.Add(new LookupParameter("Value", "The value that should be set to a random value.")); } public override IDeepCloneable Clone(Cloner cloner) { return new NormalRandomizer(this, cloner); } /// /// Generates a new normally distributed random variable and assigns it to the specified variable. /// public override IOperation Apply() { IRandom random = RandomParameter.ActualValue; double mu = MuParameter.ActualValue.Value; double sigma = SigmaParameter.ActualValue.Value; NormalDistributedRandom normalRandom = new NormalDistributedRandom(random, mu, sigma); ValueParameter.ActualValue = new DoubleValue(normalRandom.NextDouble()); return base.Apply(); } } }