Free cookie consent management tool by TermsFeed Policy Generator

source: branches/FitnessLandscapeAnalysis/HeuristicLab.Problems.NK/WeightInitializers/ExponentialDistributionWeightsInitializer.cs @ 7403

Last change on this file since 7403 was 7128, checked in by epitzer, 13 years ago

#1696 Integrate fitness landscape analysis plugins from Heureka! repository.

File size: 1.9 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Core;
6using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
7using HeuristicLab.Common;
8using HeuristicLab.Parameters;
9using HeuristicLab.Data;
10
11namespace 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}
Note: See TracBrowser for help on using the repository browser.