Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.FitnessLandscapeAnalysis/HeuristicLab.Analysis.FitnessLandscape/Algorithms/EvolvabilityAnalyzer.cs @ 17495

Last change on this file since 17495 was 16995, checked in by gkronber, 5 years ago

#2520 Update plugin dependencies and references for HL.FLA for new persistence

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