Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Random/3.3/NormalRandomizer.cs @ 4047

Last change on this file since 4047 was 3376, checked in by swagner, 15 years ago

Moved interfaces and classes for deep cloning from HeuristicLab.Core to HeuristicLab.Common (#975).

File size: 3.6 KB
RevLine 
[2]1#region License Information
2/* HeuristicLab
[3269]3 * Copyright (C) 2002-2010 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
22using System;
23using System.Collections.Generic;
24using System.Text;
[3376]25using HeuristicLab.Common;
[2]26using HeuristicLab.Core;
27using HeuristicLab.Data;
[1853]28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
[3269]29using HeuristicLab.Operators;
30using HeuristicLab.Parameters;
[2]31
32namespace HeuristicLab.Random {
[1153]33  /// <summary>
34  /// Normally distributed random number generator.
35  /// </summary>
[3269]36  [StorableClass]
37  [Item("NormalRandomizer", "Initializes the value of variable 'Value' to a random value normally distributed with parameters 'Mu' and 'Sigma'")]
38  public class NormalRandomizer : SingleSuccessorOperator {
39    #region parameter properties
40    public ILookupParameter<IRandom> RandomParameter {
41      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
[2]42    }
[3269]43    public IValueLookupParameter<DoubleValue> MuParameter {
44      get { return (IValueLookupParameter<DoubleValue>)Parameters["Mu"]; }
[426]45    }
[3269]46    public IValueLookupParameter<DoubleValue> SigmaParameter {
47      get { return (IValueLookupParameter<DoubleValue>)Parameters["Sigma"]; }
[426]48    }
[3269]49    public ILookupParameter<DoubleValue> ValueParameter {
50      get { return (ILookupParameter<DoubleValue>)Parameters["Value"]; }
51    }
52    #endregion
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
[1153]63    /// <summary>
64    /// Initializes a new instance of <see cref="NormalRandomizer"/> with four variable infos
65    /// (<c>Mu</c>, <c>Sigma</c>, <c>Value</c> and <c>Random</c>).
66    /// </summary>
[2]67    public NormalRandomizer() {
[3269]68      Parameters.Add(new LookupParameter<IRandom>("Random", "A random generator that supplies uniformly distributed values."));
69      Parameters.Add(new ValueLookupParameter<DoubleValue>("Mu", "Mu parameter of the normal distribution (N(mu,sigma))."));
70      Parameters.Add(new ValueLookupParameter<DoubleValue>("Sigma", "Sigma parameter of the normal distribution (N(mu,sigma))."));
71      Parameters.Add(new LookupParameter<DoubleValue>("Value", "The value that should be set to a random value."));
[2]72    }
73
[1153]74    /// <summary>
[3269]75    /// Generates a new normally distributed random variable and assigns it to the specified variable.
[1153]76    /// </summary>
[3269]77    public override IOperation Apply() {
78      IRandom random = RandomParameter.ActualValue;
79      double mu = MuParameter.ActualValue.Value;
80      double sigma = SigmaParameter.ActualValue.Value;
[2]81
[3269]82      NormalDistributedRandom normalRandom = new NormalDistributedRandom(random, mu, sigma);
83      ValueParameter.ActualValue = new DoubleValue(normalRandom.NextDouble());
[2]84      return null;
85    }
86  }
87}
Note: See TracBrowser for help on using the repository browser.