#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;
using System;
namespace HeuristicLab.Analysis.FitnessLandscape.Analysis {
[StorableClass]
public class QualityTrailSummarizer : AlgorithmOperator, IQualityTrailAnalyzer {
public bool EnabledByDefault {
get { return false; }
}
#region Parameters
public LookupParameter QualityTrailParameter {
get { return (LookupParameter)Parameters["Quality Trail"]; }
}
public LookupParameter QualityTrailSummaryParameter {
get { return (LookupParameter)Parameters["QualityTrailSummary"]; }
}
public LookupParameter ResultsParameter {
get { return (LookupParameter)Parameters["Results"]; }
}
#endregion
#region Construction & Cloning
[StorableConstructor]
protected QualityTrailSummarizer(bool deserializing) : base(deserializing) { }
protected QualityTrailSummarizer(QualityTrailSummarizer original, Cloner cloner) : base(original, cloner) { }
public QualityTrailSummarizer() {
Parameters.Add(new LookupParameter("Quality Trail", "The quality of the solution"));
Parameters.Add(new LookupParameter("QualityTrailSummary", "Maximum nr of steps between statistically significantly correlated quality values"));
Parameters.Add(new LookupParameter("Results", "The collection of all results of this algorithm"));
var resultsCollector = new ResultsCollector();
resultsCollector.CollectedValues.Add(new LookupParameter(QualityTrailSummaryParameter.Name));
OperatorGraph.InitialOperator = resultsCollector;
}
public override IDeepCloneable Clone(Cloner cloner) {
return new QualityTrailSummarizer(this, cloner);
}
#endregion
public override IOperation Apply() {
QualityTrailSummaryTable qualityTrailSummary = CreateQualitytrailSummaryTable();
DataTable qualityTrail = QualityTrailParameter.ActualValue;
if (qualityTrail != null && qualityTrail.Rows.Count > 1) {
var values = qualityTrail.Rows.First().Values;
DistributionAnalyzer analyzer = new DistributionAnalyzer(values);
qualityTrailSummary.Rows["Value Quantiles"].Values.AddRange(new[] { 0, 0.25, 0.5, 0.75, 1 }.Select(q => analyzer[q]));
double variance, kurtosis, skewness, mean;
for (int i = 0; i < 4; i++) {
int minIndex = (int)Math.Round(i*values.Count*0.25);
int maxIndex = (int)Math.Round((i+1)*values.Count*0.25);
alglib.samplemoments(
values.GetRange(minIndex, maxIndex - minIndex).ToArray(),
out mean, out variance, out skewness, out kurtosis);
qualityTrailSummary.Rows["Epoch Averages"].Values.Add(mean);
qualityTrailSummary.Rows["Epoch Variances"].Values.Add(variance);
qualityTrailSummary.Rows["Epoch Skewnesses"].Values.Add(skewness);
qualityTrailSummary.Rows["Epoch Kurtoses"].Values.Add(kurtosis);
}
}
return base.Apply();
}
private QualityTrailSummaryTable CreateQualitytrailSummaryTable() {
QualityTrailSummaryTable qualityTrailSummary = new QualityTrailSummaryTable("Quality Trail Summary");
QualityTrailSummaryParameter.ActualValue = qualityTrailSummary;
qualityTrailSummary.Rows.Add(new DataRow("Value Quantiles"));
qualityTrailSummary.Rows.Add(new DataRow("Epoch Averages"));
qualityTrailSummary.Rows.Add(new DataRow("Epoch Variances"));
qualityTrailSummary.Rows.Add(new DataRow("Epoch Skewnesses"));
qualityTrailSummary.Rows.Add(new DataRow("Epoch Kurtoses"));
return qualityTrailSummary;
}
}
}