using System.Collections.Generic; using System.Drawing; using System.Linq; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Optimization; using HeuristicLab.Data; using HeuristicLab.Common.Resources; using HEAL.Attic; namespace HeuristicLab.Analysis.FitnessLandscape { [Item("InformationAnalysisValue Aggregator", "Aggregates information anlysis values.")] [StorableType("829CDE87-6290-42AE-93EF-5095B52AD6FF")] public class InformationAnalysisValueAggregator : NamedItem, IAggregator { #region Fields [Storable] private List InformationContentValues; [Storable] private List PartialInformationContentValues; [Storable] private List DensityBasinInformationValues; [Storable] private List InformationStabilityValues; #endregion #region Properties public static new Image StaticItemImage { get { return VSImageLibrary.Database; } } public override bool CanChangeName { get { return false; } } #endregion #region Construction and Cloning [StorableConstructor] protected InformationAnalysisValueAggregator(StorableConstructorFlag _) : base(_) { } protected InformationAnalysisValueAggregator(InformationAnalysisValueAggregator original, Cloner cloner) : base(original, cloner) { InformationContentValues = original.InformationContentValues.ToList(); PartialInformationContentValues = original.PartialInformationContentValues.ToList(); DensityBasinInformationValues = original.DensityBasinInformationValues.ToList(); InformationStabilityValues = original.InformationStabilityValues.ToList(); } public InformationAnalysisValueAggregator() { name = ItemName; description = ItemDescription; InformationContentValues = new List(); PartialInformationContentValues = new List(); DensityBasinInformationValues = new List(); InformationStabilityValues = new List(); } public override IDeepCloneable Clone(Cloner cloner) { return new InformationAnalysisValueAggregator(this, cloner); } #endregion #region IAggregator Members public void MaybeAddResult(IResult result) { if (result.DataType == typeof(DoubleValue)) { double value = ((DoubleValue)result.Value).Value; switch (result.Name) { case "InformationContentValue": InformationContentValues.Add(value); break; case "PartialInformationContentValue": PartialInformationContentValues.Add(value); break; case "DensityBasinInformationValue": DensityBasinInformationValues.Add(value); break; case "InformationStabilityValue": InformationStabilityValues.Add(value); break; } } } public void Reset() { InformationContentValues.Clear(); PartialInformationContentValues.Clear(); InformationStabilityValues.Clear(); DensityBasinInformationValues.Clear(); } public IResult CreateResult() { var results = new ResultCollection(); results.AddRange(CreateSummary("Inf Cont", InformationContentValues)); results.AddRange(CreateSummary("Part Inf Cont", PartialInformationContentValues)); results.AddRange(CreateSummary("Dens Bas Inf", DensityBasinInformationValues)); results.AddRange(CreateSummary("Inf Stab", InformationStabilityValues)); return new Result("Inf. Val.", results); } private static IEnumerable CreateSummary(string name, IEnumerable values) { DistributionAnalyzer analyzer = new DistributionAnalyzer(values); return new[] { new Result(name + " Avg", new DoubleValue(analyzer.Mean)), new Result(name + " Quart-Spread", new DoubleValue(analyzer[0.75]-analyzer[0.25])), new Result(name + " 90%-Spread", new DoubleValue(analyzer[0.95]-analyzer[0.05])), new Result(name + " Range", new DoubleValue(analyzer[1]-analyzer[0])), }; } #endregion } }