[2] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[17180] | 3 | * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[2] | 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 |
|
---|
[4722] | 22 | using HeuristicLab.Common;
|
---|
[2] | 23 | using HeuristicLab.Core;
|
---|
| 24 | using HeuristicLab.Data;
|
---|
[3269] | 25 | using HeuristicLab.Operators;
|
---|
| 26 | using HeuristicLab.Parameters;
|
---|
[16565] | 27 | using HEAL.Attic;
|
---|
[17244] | 28 | using System;
|
---|
[2] | 29 |
|
---|
| 30 | namespace HeuristicLab.Random {
|
---|
[1153] | 31 | /// <summary>
|
---|
| 32 | /// Normally distributed random number generator.
|
---|
| 33 | /// </summary>
|
---|
[16565] | 34 | [StorableType("0EAF4184-6C98-4C9D-80A1-09A42E03450E")]
|
---|
[3269] | 35 | [Item("NormalRandomizer", "Initializes the value of variable 'Value' to a random value normally distributed with parameters 'Mu' and 'Sigma'")]
|
---|
[17244] | 36 | [Obsolete("Use NormalRandomizerPolar instead.")]
|
---|
[3269] | 37 | public class NormalRandomizer : SingleSuccessorOperator {
|
---|
[4722] | 38 | #region Parameter Properties
|
---|
[3269] | 39 | public ILookupParameter<IRandom> RandomParameter {
|
---|
| 40 | get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
|
---|
[2] | 41 | }
|
---|
[3269] | 42 | public IValueLookupParameter<DoubleValue> MuParameter {
|
---|
| 43 | get { return (IValueLookupParameter<DoubleValue>)Parameters["Mu"]; }
|
---|
[426] | 44 | }
|
---|
[3269] | 45 | public IValueLookupParameter<DoubleValue> SigmaParameter {
|
---|
| 46 | get { return (IValueLookupParameter<DoubleValue>)Parameters["Sigma"]; }
|
---|
[426] | 47 | }
|
---|
[3269] | 48 | public ILookupParameter<DoubleValue> ValueParameter {
|
---|
| 49 | get { return (ILookupParameter<DoubleValue>)Parameters["Value"]; }
|
---|
| 50 | }
|
---|
| 51 | #endregion
|
---|
[4722] | 52 |
|
---|
[3269] | 53 | #region Properties
|
---|
| 54 | public DoubleValue Mu {
|
---|
| 55 | get { return MuParameter.ActualValue; }
|
---|
| 56 | set { MuParameter.ActualValue = value; }
|
---|
| 57 | }
|
---|
| 58 | public DoubleValue Max {
|
---|
| 59 | get { return SigmaParameter.ActualValue; }
|
---|
| 60 | set { SigmaParameter.ActualValue = value; }
|
---|
| 61 | }
|
---|
| 62 | #endregion
|
---|
[4722] | 63 |
|
---|
| 64 | [StorableConstructor]
|
---|
[16565] | 65 | protected NormalRandomizer(StorableConstructorFlag _) : base(_) { }
|
---|
[4722] | 66 | protected NormalRandomizer(NormalRandomizer original, Cloner cloner) : base(original, cloner) { }
|
---|
[1153] | 67 | /// <summary>
|
---|
| 68 | /// Initializes a new instance of <see cref="NormalRandomizer"/> with four variable infos
|
---|
| 69 | /// (<c>Mu</c>, <c>Sigma</c>, <c>Value</c> and <c>Random</c>).
|
---|
| 70 | /// </summary>
|
---|
[2] | 71 | public NormalRandomizer() {
|
---|
[3269] | 72 | Parameters.Add(new LookupParameter<IRandom>("Random", "A random generator that supplies uniformly distributed values."));
|
---|
| 73 | Parameters.Add(new ValueLookupParameter<DoubleValue>("Mu", "Mu parameter of the normal distribution (N(mu,sigma))."));
|
---|
| 74 | Parameters.Add(new ValueLookupParameter<DoubleValue>("Sigma", "Sigma parameter of the normal distribution (N(mu,sigma))."));
|
---|
| 75 | Parameters.Add(new LookupParameter<DoubleValue>("Value", "The value that should be set to a random value."));
|
---|
[2] | 76 | }
|
---|
| 77 |
|
---|
[4722] | 78 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 79 | return new NormalRandomizer(this, cloner);
|
---|
| 80 | }
|
---|
| 81 |
|
---|
[1153] | 82 | /// <summary>
|
---|
[3269] | 83 | /// Generates a new normally distributed random variable and assigns it to the specified variable.
|
---|
[1153] | 84 | /// </summary>
|
---|
[3269] | 85 | public override IOperation Apply() {
|
---|
| 86 | IRandom random = RandomParameter.ActualValue;
|
---|
| 87 | double mu = MuParameter.ActualValue.Value;
|
---|
| 88 | double sigma = SigmaParameter.ActualValue.Value;
|
---|
[2] | 89 |
|
---|
[3269] | 90 | NormalDistributedRandom normalRandom = new NormalDistributedRandom(random, mu, sigma);
|
---|
| 91 | ValueParameter.ActualValue = new DoubleValue(normalRandom.NextDouble());
|
---|
[7644] | 92 | return base.Apply();
|
---|
[2] | 93 | }
|
---|
| 94 | }
|
---|
| 95 | }
|
---|