#region License Information /* HeuristicLab * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Operators; using HeuristicLab.Optimization; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using System.Linq; namespace HeuristicLab.Analysis.FitnessLandscape { [StorableClass] public class InformationAnalyzer : SingleSuccessorOperator, IQualityTrailAnalyzer { public bool EnabledByDefault { get { return false; } } #region Parameters public LookupParameter QualityTrailParameter { get { return (LookupParameter)Parameters["Quality Trail"]; } } public LookupParameter ResultsParameter { get { return (LookupParameter)Parameters["Results"]; } } public ValueLookupParameter NQuantilesParameter { get { return (ValueLookupParameter)Parameters["NQuantiles"]; } } public ValueLookupParameter ShapeSizeParameter { get { return (ValueLookupParameter)Parameters["ShapeSize"]; } } public LookupParameter InformationContentParameter { get { return (LookupParameter)Parameters["InformationContent"]; } } public LookupParameter PartialInformationContentParameter { get { return (LookupParameter)Parameters["PartialInformationContent"]; } } public LookupParameter DensityBasinInformationParameter { get { return (LookupParameter)Parameters["DensityBasinInformation"]; } } public LookupParameter TotalEntropyParameter { get { return (LookupParameter)Parameters["TotalEntropy"]; } } public LookupParameter InformationStabilityParameter { get { return (LookupParameter)Parameters["InformationStability"]; } } public LookupParameter RegularityParameter { get { return (LookupParameter)Parameters["Regularity"]; } } public LookupParameter DiversityParameter { get { return (LookupParameter)Parameters["Diversity"]; } } public LookupParameter PeakInformationContentParameter { get { return (LookupParameter)Parameters["PeakInformationContent"]; } } public LookupParameter PeakDensityBasinInformationParameter { get { return (LookupParameter)Parameters["PeakDensityBasinInformation"]; } } #endregion [StorableConstructor] protected InformationAnalyzer(bool deserializing) : base(deserializing) { } protected InformationAnalyzer(InformationAnalyzer original, Cloner cloner) : base(original, cloner) { } public InformationAnalyzer() { Parameters.Add(new LookupParameter("Quality Trail", "The qualities of the solutions")); Parameters.Add(new LookupParameter("Results", "The collection of all results of this algorithm")); Parameters.Add(new ValueLookupParameter("NQuantiles", "The number of delta quantiles to display", new IntValue(20))); Parameters.Add(new ValueLookupParameter("ShapeSize", "The number of slopes to consider as shapes.", new IntValue(2))); Parameters.Add(new LookupParameter("InformationContent", "The information content H(0) at eps = 0")); Parameters.Add(new LookupParameter("PartialInformationContent", "Partial information content M(0) at eps = 0")); Parameters.Add(new LookupParameter("DensityBasinInformation", "Density Basin Information h(0) at eps = 0")); Parameters.Add(new LookupParameter("TotalEntropy", "The overall disorder in the trajectory")); Parameters.Add(new LookupParameter("InformationStability", "Information Stability Value")); Parameters.Add(new LookupParameter("Regularity", "The number of different quality differences")); Parameters.Add(new LookupParameter("Diversity", "The number of different quality values")); Parameters.Add(new LookupParameter("PeakInformationContent", "Maximum information content at any quality delta.")); Parameters.Add(new LookupParameter("PeakDensityBasinInformation", "Maximum density basin information at any quality delta.")); } public override IDeepCloneable Clone(Cloner cloner) { return new InformationAnalyzer(this, cloner); } public override IOperation Apply() { var qualityTrail = QualityTrailParameter.ActualValue; if (qualityTrail == null || qualityTrail.Rows.Count == 0) return base.Apply(); var qualities = QualityTrailParameter.ActualValue.Rows.First().Values.ToList(); if (qualities.Count <= 2) return base.Apply(); var nQuantiles = NQuantilesParameter.ActualValue.Value; var shapeSize = ShapeSizeParameter.ActualValue.Value; var results = ResultsParameter.ActualValue; var analysis = new InformationAnalysis(qualities, nQuantiles, shapeSize); var ic = new DoubleValue(analysis.InformationContent.FirstOrDefault()); InformationContentParameter.ActualValue = ic; AddOrUpdateResult(results, InformationContentParameter.Name, ic); var pic = new DoubleValue(analysis.PartialInformationContent.FirstOrDefault()); PartialInformationContentParameter.ActualValue = pic; AddOrUpdateResult(results, PartialInformationContentParameter.Name, pic); var dbi = new DoubleValue(analysis.DensityBasinInformation.FirstOrDefault()); DensityBasinInformationParameter.ActualValue = dbi; AddOrUpdateResult(results, DensityBasinInformationParameter.Name, dbi); var @is = new DoubleValue(analysis.InformationStability); InformationStabilityParameter.ActualValue = @is; AddOrUpdateResult(results, InformationStabilityParameter.Name, @is); var regularity = new DoubleValue(1.0 * analysis.Regularity / qualities.Count); RegularityParameter.ActualValue = regularity; AddOrUpdateResult(results, RegularityParameter.Name, regularity); var diversity = new DoubleValue(1.0 * analysis.Diversity / qualities.Count); DiversityParameter.ActualValue = diversity; AddOrUpdateResult(results, DiversityParameter.Name, diversity); var totalEntropy = new DoubleValue(analysis.TotalEntropy.FirstOrDefault()); TotalEntropyParameter.ActualValue = totalEntropy; AddOrUpdateResult(results, TotalEntropyParameter.Name, totalEntropy); var peakIc = new DoubleValue(analysis.PeakInformationContent.Value); PeakInformationContentParameter.ActualValue = peakIc; AddOrUpdateResult(results, PeakInformationContentParameter.Name, peakIc); var peakDbi = new DoubleValue(analysis.PeakDensityBasinInformation.Value); PeakDensityBasinInformationParameter.ActualValue = peakDbi; AddOrUpdateResult(results, PeakDensityBasinInformationParameter.Name, peakDbi); return base.Apply(); } private static void AddOrUpdateResult(ResultCollection results, string name, IItem item, bool clone = false) { IResult r; if (!results.TryGetValue(name, out r)) { results.Add(new Result(name, clone ? (IItem)item.Clone() : item)); } else r.Value = clone ? (IItem)item.Clone() : item; } } }