Free cookie consent management tool by TermsFeed Policy Generator

source: branches/FitnessLandscapeAnalysis/HeuristicLab.Analysis.FitnessLandscape/Algorithms/EvolvabilityAnalyzer.cs @ 9346

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

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

File size: 5.3 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using HeuristicLab.Analysis.FitnessLandscape.DataTables;
5using HeuristicLab.Common;
6using HeuristicLab.Core;
7using HeuristicLab.Data;
8using HeuristicLab.Operators;
9using HeuristicLab.Optimization;
10using HeuristicLab.Parameters;
11using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
12
13namespace HeuristicLab.Analysis.FitnessLandscape.Algorithms {
14
15  [Item("EvolvabilityAnalyzer", "Analyzes and consolidates repeated (very short) trails to evolvability metrics.")]
16  [StorableClass]
17  public class EvolvabilityAnalyzer : SingleSuccessorOperator, IRepeatsAnalyzer {
18
19    #region Parameters
20    public ScopeTreeLookupParameter<DoubleValue> FinalQualitiesParameter {
21      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["FinalQualities"]; }
22    }
23    public LookupParameter<DoubleValue> BaseQualityParameter {
24      get { return (LookupParameter<DoubleValue>)Parameters["BaseQuality"]; }
25    }
26    public LookupParameter<DoubleValue> E_a_Parameter {
27      get { return (LookupParameter<DoubleValue>)Parameters["E_a"]; }
28    }
29    public LookupParameter<DoubleValue> E_b_Parameter {
30      get { return (LookupParameter<DoubleValue>)Parameters["E_b"]; }
31    }
32    public LookupParameter<DoubleValue> E_c_Parameter {
33      get { return (LookupParameter<DoubleValue>)Parameters["E_c"]; }
34    }
35    public LookupParameter<DoubleValue> E_d_Parameter {
36      get { return (LookupParameter<DoubleValue>)Parameters["E_d"]; }
37    }
38    public LookupParameter<DoubleValue> ExpectedAbsoluteQualityDeltaParameter {
39      get { return (LookupParameter<DoubleValue>)Parameters["ExpectedAbsoluteQualityDelta"]; }
40    }
41    public LookupParameter<DoubleValue> ExpectedRelativeQualityDeltaParameter {
42      get { return (LookupParameter<DoubleValue>)Parameters["ExpectedRelativeQualityDelta"]; }
43    }   
44    public LookupParameter<ResultCollection> ResultsParameter {
45      get { return (LookupParameter<ResultCollection>)Parameters["Results"]; }
46    }
47    #endregion
48
49    #region Construction & Cloning
50    [StorableConstructor]
51    protected EvolvabilityAnalyzer(bool deserializing) : base(deserializing) { }
52    protected EvolvabilityAnalyzer(EvolvabilityAnalyzer original, Cloner cloner) : base(original, cloner) { }
53    public EvolvabilityAnalyzer() {
54      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("FinalQualities", "Quality values of the end of the trails."));
55      Parameters.Add(new LookupParameter<DoubleValue>("BaseQuality", "Initial quality value."));
56
57      Parameters.Add(new LookupParameter<DoubleValue>("E_a", "Probability of non-deleterious mutation."));
58      Parameters.Add(new LookupParameter<DoubleValue>("E_b", "Average expected offspring fitness."));
59      Parameters.Add(new LookupParameter<DoubleValue>("E_c", "90th percentile offspring fitness."));
60      Parameters.Add(new LookupParameter<DoubleValue>("E_d", "10th percentile offspring fitness."));
61      Parameters.Add(new LookupParameter<DoubleValue>("ExpectedAbsoluteQualityDelta", "Expected absolute quality delta."));
62      Parameters.Add(new LookupParameter<DoubleValue>("ExpectedRelativeQualityDelta", "Expected relative quality delta."));
63
64      Parameters.Add(new LookupParameter<ResultCollection>("Results", "The collection of all results of this algorithm"));
65      FinalQualitiesParameter.Depth = 2;
66      FinalQualitiesParameter.ActualName = "Quality";
67      BaseQualityParameter.ActualName = "Quality";     
68    }
69    public override IDeepCloneable Clone(Cloner cloner) {
70      return new EvolvabilityAnalyzer(this, cloner);
71    }
72    #endregion
73
74    public override IOperation Apply() {
75      double baseQuality = BaseQualityParameter.ActualValue.Value;
76      var finalQualities = FinalQualitiesParameter.ActualValue.Select(v => v.Value).ToList();
77      E_a_Parameter.ActualValue = new DoubleValue(1.0 * finalQualities.Count(fq => fq >= baseQuality) / finalQualities.Count);
78      if (finalQualities.Count > 0) {
79        DistributionAnalyzer a = new DistributionAnalyzer(finalQualities);
80        double mean = a.Mean;
81        E_b_Parameter.ActualValue = new DoubleValue(mean);
82        E_c_Parameter.ActualValue = new DoubleValue(a[0.9]);
83        E_d_Parameter.ActualValue = new DoubleValue(a[0.1]);
84        ExpectedAbsoluteQualityDeltaParameter.ActualValue = new DoubleValue(mean - baseQuality);
85        ExpectedRelativeQualityDeltaParameter.ActualValue = new DoubleValue((mean - baseQuality)/baseQuality);
86        var results = ResultsParameter.ActualValue;
87        results.Add(new Result("Base Quality", (DoubleValue)BaseQualityParameter.ActualValue.Clone()));
88        results.Add(new Result("E_a", (DoubleValue)E_a_Parameter.ActualValue.Clone()));
89        results.Add(new Result("E_b", (DoubleValue)E_b_Parameter.ActualValue.Clone()));
90        results.Add(new Result("E_c", (DoubleValue)E_c_Parameter.ActualValue.Clone()));
91        results.Add(new Result("E_d", (DoubleValue)E_d_Parameter.ActualValue.Clone()));
92        results.Add(new Result("Expected Absolute Quality Delta", (DoubleValue)ExpectedAbsoluteQualityDeltaParameter.ActualValue.Clone()));
93        results.Add(new Result("Expected Relative Quality Delta", (DoubleValue)ExpectedRelativeQualityDeltaParameter.ActualValue.Clone()));
94      }     
95      return base.Apply();
96    }
97  }
98}
Note: See TracBrowser for help on using the repository browser.