#region License Information
/* HeuristicLab
* Copyright (C) 2002-2010 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 System.Collections.Generic;
using System.Text;
using HeuristicLab.Common;
using HeuristicLab.Core;
using HeuristicLab.Data;
using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
using HeuristicLab.Operators;
using HeuristicLab.Parameters;
namespace HeuristicLab.Random {
///
/// Normally distributed random number generator.
///
[StorableClass]
[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
///
/// 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."));
}
///
/// 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 null;
}
}
}