using System; using System.Collections.Generic; using System.Linq; using HeuristicLab.Analysis.FitnessLandscape.DataTables; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Operators; using HeuristicLab.Optimization; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Analysis.FitnessLandscape.Algorithms { [Item("EvolvabilityAnalyzer", "Analyzes and consolidates repeated (very short) trails to evolvability metrics.")] [StorableClass] 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(bool deserializing) : base(deserializing) { } 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(); } } }