using System; using System.Collections.Generic; using System.Linq; using System.Text; using HeuristicLab.Core; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using HeuristicLab.Common; using HeuristicLab.Parameters; using HeuristicLab.Data; namespace HeuristicLab.Problems.NK.WeightInitializers { [Item("ExponentialDistributionWeightsInitializer", "Assigned exponentially decreasing weights using the rate parameter lambad.")] public class ExponentialDistributionWeightsInitializer : ParameterizedNamedItem, IWeightsInitializer { public override bool CanChangeName { get { return false; } } public override bool CanChangeDescription { get { return false; } } public ValueParameter LambdaParameter { get { return (ValueParameter)Parameters["Lambda"]; } } [StorableConstructor] protected ExponentialDistributionWeightsInitializer(bool deserializing) : base(deserializing) { } protected ExponentialDistributionWeightsInitializer(ExponentialDistributionWeightsInitializer original, Cloner cloner) : base(original, cloner) { } public ExponentialDistributionWeightsInitializer() { Parameters.Add(new ValueParameter("Lambda", "The rate paramter of the exponential distribution.", new DoubleValue(1.0))); } public override IDeepCloneable Clone(Cloner cloner) { return new ExponentialDistributionWeightsInitializer(this, cloner); } public static double f(double x, double lambda) { if (x < 0) return 0; return lambda * Math.Exp(-lambda * x); } #region IWeightsInitializer Members public IEnumerable GetWeights(int nComponents) { double lambda = LambdaParameter.Value.Value; for (int i = 0; i