#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 System.Linq; using HeuristicLab.Analysis.FitnessLandscape.DataTables; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Operators; using HeuristicLab.Optimization.Operators; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Analysis.FitnessLandscape.Analysis { [StorableClass] public class InformationAnalyzer : AlgorithmOperator, IQualityTrailAnalyzer { public bool EnabledByDefault { get { return false; } } #region Parameters public LookupParameter QualityTrailParameter { get { return (LookupParameter)Parameters["Quality Trail"]; } } public LookupParameter InformationStabilityParameter { get { return (LookupParameter)Parameters["Information Stability"]; } } public LookupParameter InformationParameter { get { return (LookupParameter)Parameters["Information"]; } } public LookupParameter ResultsParameter { get { return (LookupParameter)Parameters["Results"]; } } public ValueLookupParameter NQuantilesParameter { get { return (ValueLookupParameter)Parameters["NQuantiles"]; } } public LookupParameter InformationContentValueParameter { get { return (LookupParameter)Parameters["InformationContentValue"]; } } public LookupParameter PartialInformationContentValueParameter { get { return (LookupParameter)Parameters["PartialInformationContentValue"]; } } public LookupParameter DensityBasinInformationValueParameter { get { return (LookupParameter)Parameters["DensityBasinInformationValue"]; } } public LookupParameter InformationStabilityValueParameter { get { return (LookupParameter)Parameters["InformationStabilityValue"]; } } public LookupParameter RegularityValueParameter { get { return (LookupParameter)Parameters["RegularityValue"]; } } #endregion private InformationStabilityTable InformationStability { get { return InformationStabilityParameter.ActualValue; } } private double InformationContentValue { set { InformationContentValueParameter.ActualValue = new DoubleValue(value); } } private double PartialInformationContentValue { set { PartialInformationContentValueParameter.ActualValue = new DoubleValue(value); } } private double DensityBasinInformationValue { set { DensityBasinInformationValueParameter.ActualValue = new DoubleValue(value); } } private double InformationStabilityValue { set { InformationStabilityValueParameter.ActualValue = new DoubleValue(value); } } [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("Information Stability", "Information stability development over time")); Parameters.Add(new LookupParameter("Information", "A data table that information theoretic fitness landscape characteristics")); 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 LookupParameter("InformationContentValue", "The information content H(0) at eps = 0")); Parameters.Add(new LookupParameter("PartialInformationContentValue", "Partial information content M(0) at eps = 0")); Parameters.Add(new LookupParameter("DensityBasinInformationValue", "Density Basin Information h(0) at eps = 0")); Parameters.Add(new LookupParameter("InformationStabilityValue", "Information Stability Value")); Parameters.Add(new LookupParameter("RegularityValue", "The number of different quality differences")); var resultsCollector = new ResultsCollector(); resultsCollector.CollectedValues.Add(new LookupParameter(InformationParameter.Name)); resultsCollector.CollectedValues.Add(new LookupParameter(InformationStabilityParameter.Name)); resultsCollector.CollectedValues.Add(new LookupParameter(InformationContentValueParameter.Name)); resultsCollector.CollectedValues.Add(new LookupParameter(PartialInformationContentValueParameter.Name)); resultsCollector.CollectedValues.Add(new LookupParameter(DensityBasinInformationValueParameter.Name)); resultsCollector.CollectedValues.Add(new LookupParameter(InformationStabilityValueParameter.Name)); resultsCollector.CollectedValues.Add(new LookupParameter(RegularityValueParameter.Name)); OperatorGraph.InitialOperator = resultsCollector; resultsCollector.Successor = null; } public override IDeepCloneable Clone(Cloner cloner) { return new InformationAnalyzer(this, cloner); } public override IOperation Apply() { DataTable qualityTrail = QualityTrailParameter.ActualValue; if (qualityTrail != null && qualityTrail.Rows.Count > 0) { EnsureExistsInformationStabilityTable(); EnsureExistsInformationTable(); AnalyseInformation(); } return base.Apply(); } private void AnalyseInformation() { int nQuantiles = NQuantilesParameter.ActualValue.Value; var qualities = QualityTrailParameter.ActualValue.Rows.First().Values.ToList(); if (qualities.Count > nQuantiles) { InformationAnalysisTable informationTable = InformationParameter.ActualValue; var informationContent = informationTable.Rows["Information Content"].Values; var partialInformationContent = informationTable.Rows["Partial Information Content"].Values; var densityBasinInformation = informationTable.Rows["Density Basin Information"].Values; var qualityDelta = informationTable.Rows["Quality Delta"].Values; var analysis = new InformationAnalysis(qualities, nQuantiles); InformationStability.Rows["Regularity"].Values.Add(analysis.Regularity); InformationStability.Rows["Relative Regularity"].Values.Add(1.0 * analysis.Regularity / qualities.Count); InformationStability.Rows["Information Stability"].Values.Add(analysis.InformationStability); informationContent.Clear(); informationContent.AddRange(analysis.InformationContent); partialInformationContent.Clear(); partialInformationContent.AddRange(analysis.PartialInformationContent); densityBasinInformation.Clear(); densityBasinInformation.AddRange(analysis.DensityBasinInformation); qualityDelta.Clear(); qualityDelta.AddRange(analysis.QualityDelta); InformationContentValue = analysis.InformationContent.FirstOrDefault(); PartialInformationContentValue = analysis.PartialInformationContent.FirstOrDefault(); DensityBasinInformationValue = analysis.DensityBasinInformation.FirstOrDefault(); InformationStabilityValue = analysis.InformationStability; RegularityValueParameter.ActualValue = new IntValue(analysis.Regularity); } } private void EnsureExistsInformationTable() { InformationAnalysisTable information = InformationParameter.ActualValue; if (information == null) { information = new InformationAnalysisTable("Information"); information.Rows.Add(new DataRow("Information Content")); information.Rows.Add(new DataRow("Partial Information Content")); information.Rows.Add(new DataRow("Density Basin Information")); var row = new DataRow("Quality Delta"); row.VisualProperties.SecondYAxis = true; information.Rows.Add(row); InformationParameter.ActualValue = information; } } private void EnsureExistsInformationStabilityTable() { InformationStabilityTable informationStability = InformationStabilityParameter.ActualValue; if (informationStability == null) { informationStability = new InformationStabilityTable("Information Stability"); informationStability.Rows.Add(new DataRow("Information Stability")); informationStability.Rows.Add(new DataRow("Relative Regularity")); var row = new DataRow("Regularity"); row.VisualProperties.SecondYAxis = true; informationStability.Rows.Add(row); InformationStabilityParameter.ActualValue = informationStability; } } } }