#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;
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 ValueLookupParameter ShapeSizeParameter {
get { return (ValueLookupParameter)Parameters["ShapeSize"]; }
}
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 TotalEntropyValueParameter {
get { return (LookupParameter)Parameters["TotalEntropyValue"]; }
}
public LookupParameter InformationStabilityValueParameter {
get { return (LookupParameter)Parameters["InformationStabilityValue"]; }
}
public LookupParameter RegularityValueParameter {
get { return (LookupParameter)Parameters["RegularityValue"]; }
}
public LookupParameter DiversityValueParameter {
get { return (LookupParameter)Parameters["DiversityValue"]; }
}
#region Peaks
public LookupParameter PeakInformationContentParameter {
get { return (LookupParameter) Parameters["PeakInformationContent"]; }
}
public LookupParameter PeakInformationContentQualityDeltaParameter {
get { return (LookupParameter) Parameters["PeakInformationContentQualityDelta"]; }
}
public LookupParameter PeakDensityBasinInformationParameter {
get { return (LookupParameter) Parameters["PeakDensityBasinInformation"]; }
}
public LookupParameter PeakDensityBasinInformationQualityDeltaParameter {
get { return (LookupParameter) Parameters["PeakDensityBasinInformationQualityDelta"]; }
}
#endregion
#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 TotalEntropyValue {
set { TotalEntropyValueParameter.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 ValueLookupParameter("ShapeSize", "The number of slopes to consider as shapes.", new IntValue(2)));
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("TotalEntropyValue", "The overall disorder in the trajectory"));
Parameters.Add(new LookupParameter("InformationStabilityValue", "Information Stability Value"));
Parameters.Add(new LookupParameter("RegularityValue", "The number of different quality differences"));
Parameters.Add(new LookupParameter("DiversityValue", "The number of different quality values"));
Parameters.Add(new LookupParameter("PeakInformationContent", "Maximum information content at any quality delta."));
Parameters.Add(new LookupParameter("PeakInformationContentQualityDelta", "Quality delta with maximum information content."));
Parameters.Add(new LookupParameter("PeakDensityBasinInformation", "Maximum density basin information at any quality delta."));
Parameters.Add(new LookupParameter("PeakDensityBasinInformationQualityDelta", "Quality delta with maximum density basin information."));
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(TotalEntropyValueParameter.Name));
resultsCollector.CollectedValues.Add(new LookupParameter(InformationStabilityValueParameter.Name));
resultsCollector.CollectedValues.Add(new LookupParameter(RegularityValueParameter.Name));
resultsCollector.CollectedValues.Add(new LookupParameter(DiversityValueParameter.Name));
resultsCollector.CollectedValues.Add(new LookupParameter(PeakInformationContentParameter.Name));
resultsCollector.CollectedValues.Add(new LookupParameter(PeakInformationContentQualityDeltaParameter.Name));
resultsCollector.CollectedValues.Add(new LookupParameter(PeakDensityBasinInformationParameter.Name));
resultsCollector.CollectedValues.Add(new LookupParameter(PeakDensityBasinInformationQualityDeltaParameter.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;
int shapeSize = ShapeSizeParameter.ActualValue.Value;
var qualities = QualityTrailParameter.ActualValue.Rows.First().Values.ToList();
if (qualities.Count > 2) {
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 totalEntropy = informationTable.Rows["Total Entropy"].Values;
var qualityDelta = informationTable.Rows["Quality Delta"].Values;
var analysis = new InformationAnalysis(qualities, nQuantiles, shapeSize);
InformationStability.Rows["Regularity"].Values.Add(analysis.Regularity);
InformationStability.Rows["Diversity"].Values.Add(analysis.Diversity);
InformationStability.Rows["Relative Regularity"].Values.Add(1.0*analysis.Regularity/qualities.Count);
InformationStability.Rows["Relative Diversity"].Values.Add(1.0*analysis.Diversity/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);
totalEntropy.Clear();
totalEntropy.AddRange(analysis.TotalEntropy);
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);
DiversityValueParameter.ActualValue = new IntValue(analysis.Diversity);
if (analysis.PeakInformationContent != null) {
PeakInformationContentParameter.ActualValue = new DoubleValue(analysis.PeakInformationContent.Value);
PeakInformationContentQualityDeltaParameter.ActualValue = new DoubleValue(analysis.PeakInformationContent.QualityDelta);
}
if (analysis.PeakDensityBasinInformation != null) {
PeakDensityBasinInformationParameter.ActualValue = new DoubleValue(analysis.PeakDensityBasinInformation.Value);
PeakDensityBasinInformationQualityDeltaParameter.ActualValue = new DoubleValue(analysis.PeakDensityBasinInformation.QualityDelta);
}
}
}
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"));
information.Rows.Add(new DataRow("Total Entropy"));
information.Rows.Add(new DataRow("Quality Delta") {VisualProperties = {SecondYAxis = true}});
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"));
informationStability.Rows.Add(new DataRow("Relative Diversity"));
informationStability.Rows.Add(new DataRow("Regularity") {VisualProperties = {SecondYAxis = true}});
informationStability.Rows.Add(new DataRow("Diversity") {VisualProperties = {SecondYAxis = true}});
InformationStabilityParameter.ActualValue = informationStability;
}
}
}
}