[7128] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Text;
|
---|
| 5 | using HeuristicLab.Core;
|
---|
| 6 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 7 | using HeuristicLab.Common;
|
---|
| 8 | using HeuristicLab.Parameters;
|
---|
| 9 | using HeuristicLab.Data;
|
---|
| 10 |
|
---|
| 11 | namespace HeuristicLab.Problems.NK.WeightInitializers {
|
---|
| 12 |
|
---|
| 13 | [Item("ExponentialDistributionWeightsInitializer", "Assigned exponentially decreasing weights using the rate parameter lambad.")]
|
---|
| 14 | public class ExponentialDistributionWeightsInitializer : ParameterizedNamedItem, IWeightsInitializer {
|
---|
| 15 |
|
---|
| 16 | public override bool CanChangeName { get { return false; } }
|
---|
| 17 | public override bool CanChangeDescription { get { return false; } }
|
---|
| 18 | public ValueParameter<DoubleValue> LambdaParameter {
|
---|
| 19 | get { return (ValueParameter<DoubleValue>)Parameters["Lambda"]; }
|
---|
| 20 | }
|
---|
| 21 |
|
---|
| 22 | [StorableConstructor]
|
---|
| 23 | protected ExponentialDistributionWeightsInitializer(bool deserializing) : base(deserializing) { }
|
---|
| 24 | protected ExponentialDistributionWeightsInitializer(ExponentialDistributionWeightsInitializer original, Cloner cloner)
|
---|
| 25 | : base(original, cloner) {
|
---|
| 26 | }
|
---|
| 27 | public ExponentialDistributionWeightsInitializer() {
|
---|
| 28 | Parameters.Add(new ValueParameter<DoubleValue>("Lambda", "The rate paramter of the exponential distribution.", new DoubleValue(1.0)));
|
---|
| 29 | }
|
---|
| 30 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 31 | return new ExponentialDistributionWeightsInitializer(this, cloner);
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | public static double f(double x, double lambda) {
|
---|
| 35 | if (x < 0)
|
---|
| 36 | return 0;
|
---|
| 37 | return lambda * Math.Exp(-lambda * x);
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | #region IWeightsInitializer Members
|
---|
| 41 | public IEnumerable<double> GetWeights(int nComponents) {
|
---|
| 42 | double lambda = LambdaParameter.Value.Value;
|
---|
| 43 | for (int i = 0; i<nComponents; i++)
|
---|
| 44 | yield return f(i, lambda);
|
---|
| 45 | }
|
---|
| 46 | #endregion
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | }
|
---|