using System.Linq; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Operators; using HeuristicLab.Optimization; using HeuristicLab.Parameters; using HEAL.Attic; namespace HeuristicLab.Analysis.FitnessLandscape.Algorithms { [Item("EvolvabilityAnalyzer", "Analyzes and consolidates repeated (very short) trails to evolvability metrics.")] [StorableType("446A5494-B5EE-4C52-B6AE-B1B37E3E5E4D")] public class EvolvabilityAnalyzer : SingleSuccessorOperator, IRepeatsAnalyzer { #region Parameters public ScopeTreeLookupParameter FinalQualitiesParameter { get { return (ScopeTreeLookupParameter)Parameters["FinalQualities"]; } } public LookupParameter BaseQualityParameter { get { return (LookupParameter)Parameters["BaseQuality"]; } } public LookupParameter E_a_Parameter { get { return (LookupParameter)Parameters["E_a"]; } } public LookupParameter E_b_Parameter { get { return (LookupParameter)Parameters["E_b"]; } } public LookupParameter E_c_Parameter { get { return (LookupParameter)Parameters["E_c"]; } } public LookupParameter E_d_Parameter { get { return (LookupParameter)Parameters["E_d"]; } } public LookupParameter ExpectedAbsoluteQualityDeltaParameter { get { return (LookupParameter)Parameters["ExpectedAbsoluteQualityDelta"]; } } public LookupParameter ExpectedRelativeQualityDeltaParameter { get { return (LookupParameter)Parameters["ExpectedRelativeQualityDelta"]; } } public LookupParameter ResultsParameter { get { return (LookupParameter)Parameters["Results"]; } } #endregion #region Construction & Cloning [StorableConstructor] protected EvolvabilityAnalyzer(StorableConstructorFlag _) : base(_) { } protected EvolvabilityAnalyzer(EvolvabilityAnalyzer original, Cloner cloner) : base(original, cloner) { } public EvolvabilityAnalyzer() { Parameters.Add(new ScopeTreeLookupParameter("FinalQualities", "Quality values of the end of the trails.")); Parameters.Add(new LookupParameter("BaseQuality", "Initial quality value.")); Parameters.Add(new LookupParameter("E_a", "Probability of non-deleterious mutation.")); Parameters.Add(new LookupParameter("E_b", "Average expected offspring fitness.")); Parameters.Add(new LookupParameter("E_c", "90th percentile offspring fitness.")); Parameters.Add(new LookupParameter("E_d", "10th percentile offspring fitness.")); Parameters.Add(new LookupParameter("ExpectedAbsoluteQualityDelta", "Expected absolute quality delta.")); Parameters.Add(new LookupParameter("ExpectedRelativeQualityDelta", "Expected relative quality delta.")); Parameters.Add(new LookupParameter("Results", "The collection of all results of this algorithm")); FinalQualitiesParameter.Depth = 2; FinalQualitiesParameter.ActualName = "Quality"; BaseQualityParameter.ActualName = "Quality"; } public override IDeepCloneable Clone(Cloner cloner) { return new EvolvabilityAnalyzer(this, cloner); } #endregion public override IOperation Apply() { double baseQuality = BaseQualityParameter.ActualValue.Value; var finalQualities = FinalQualitiesParameter.ActualValue.Select(v => v.Value).ToList(); E_a_Parameter.ActualValue = new DoubleValue(1.0 * finalQualities.Count(fq => fq >= baseQuality) / finalQualities.Count); if (finalQualities.Count > 0) { DistributionAnalyzer a = new DistributionAnalyzer(finalQualities); double mean = a.Mean; E_b_Parameter.ActualValue = new DoubleValue(mean); E_c_Parameter.ActualValue = new DoubleValue(a[0.9]); E_d_Parameter.ActualValue = new DoubleValue(a[0.1]); ExpectedAbsoluteQualityDeltaParameter.ActualValue = new DoubleValue(mean - baseQuality); ExpectedRelativeQualityDeltaParameter.ActualValue = new DoubleValue((mean - baseQuality)/baseQuality); var results = ResultsParameter.ActualValue; results.Add(new Result("Base Quality", (DoubleValue)BaseQualityParameter.ActualValue.Clone())); results.Add(new Result("E_a", (DoubleValue)E_a_Parameter.ActualValue.Clone())); results.Add(new Result("E_b", (DoubleValue)E_b_Parameter.ActualValue.Clone())); results.Add(new Result("E_c", (DoubleValue)E_c_Parameter.ActualValue.Clone())); results.Add(new Result("E_d", (DoubleValue)E_d_Parameter.ActualValue.Clone())); results.Add(new Result("Expected Absolute Quality Delta", (DoubleValue)ExpectedAbsoluteQualityDeltaParameter.ActualValue.Clone())); results.Add(new Result("Expected Relative Quality Delta", (DoubleValue)ExpectedRelativeQualityDeltaParameter.ActualValue.Clone())); } return base.Apply(); } } }