1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System.Linq;
|
---|
23 | using HeuristicLab.Analysis.FitnessLandscape.DataTables;
|
---|
24 | using HeuristicLab.Common;
|
---|
25 | using HeuristicLab.Core;
|
---|
26 | using HeuristicLab.Operators;
|
---|
27 | using HeuristicLab.Optimization.Operators;
|
---|
28 | using HeuristicLab.Parameters;
|
---|
29 | using System;
|
---|
30 | using HEAL.Attic;
|
---|
31 |
|
---|
32 | namespace HeuristicLab.Analysis.FitnessLandscape.Analysis {
|
---|
33 |
|
---|
34 | [StorableType("78C1D578-7752-45B4-9174-DF30D38A7E8A")]
|
---|
35 | public class QualityTrailSummarizer : AlgorithmOperator, IQualityTrailAnalyzer {
|
---|
36 | public bool EnabledByDefault {
|
---|
37 | get { return false; }
|
---|
38 | }
|
---|
39 |
|
---|
40 | #region Parameters
|
---|
41 | public LookupParameter<DataTable> QualityTrailParameter {
|
---|
42 | get { return (LookupParameter<DataTable>)Parameters["Quality Trail"]; }
|
---|
43 | }
|
---|
44 | public LookupParameter<QualityTrailSummaryTable> QualityTrailSummaryParameter {
|
---|
45 | get { return (LookupParameter<QualityTrailSummaryTable>)Parameters["QualityTrailSummary"]; }
|
---|
46 | }
|
---|
47 | public LookupParameter<VariableCollection> ResultsParameter {
|
---|
48 | get { return (LookupParameter<VariableCollection>)Parameters["Results"]; }
|
---|
49 | }
|
---|
50 | #endregion
|
---|
51 |
|
---|
52 | #region Construction & Cloning
|
---|
53 | [StorableConstructor]
|
---|
54 | protected QualityTrailSummarizer(StorableConstructorFlag _) : base(_) { }
|
---|
55 | protected QualityTrailSummarizer(QualityTrailSummarizer original, Cloner cloner) : base(original, cloner) { }
|
---|
56 |
|
---|
57 | public QualityTrailSummarizer() {
|
---|
58 | Parameters.Add(new LookupParameter<DataTable>("Quality Trail", "The quality of the solution"));
|
---|
59 | Parameters.Add(new LookupParameter<QualityTrailSummaryTable>("QualityTrailSummary", "Maximum nr of steps between statistically significantly correlated quality values"));
|
---|
60 | Parameters.Add(new LookupParameter<VariableCollection>("Results", "The collection of all results of this algorithm"));
|
---|
61 |
|
---|
62 | var resultsCollector = new ResultsCollector();
|
---|
63 | resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>(QualityTrailSummaryParameter.Name));
|
---|
64 |
|
---|
65 | OperatorGraph.InitialOperator = resultsCollector;
|
---|
66 | }
|
---|
67 |
|
---|
68 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
69 | return new QualityTrailSummarizer(this, cloner);
|
---|
70 | }
|
---|
71 | #endregion
|
---|
72 |
|
---|
73 | public override IOperation Apply() {
|
---|
74 | QualityTrailSummaryTable qualityTrailSummary = CreateQualitytrailSummaryTable();
|
---|
75 | DataTable qualityTrail = QualityTrailParameter.ActualValue;
|
---|
76 | if (qualityTrail != null && qualityTrail.Rows.Count > 1) {
|
---|
77 | var values = qualityTrail.Rows.First().Values;
|
---|
78 | DistributionAnalyzer analyzer = new DistributionAnalyzer(values);
|
---|
79 | qualityTrailSummary.Rows["Value Quantiles"].Values.AddRange(new[] { 0, 0.25, 0.5, 0.75, 1 }.Select(q => analyzer[q]));
|
---|
80 | double variance, kurtosis, skewness, mean;
|
---|
81 | for (int i = 0; i < 4; i++) {
|
---|
82 | int minIndex = (int)Math.Round(i*values.Count*0.25);
|
---|
83 | int maxIndex = (int)Math.Round((i+1)*values.Count*0.25);
|
---|
84 | alglib.samplemoments(
|
---|
85 | values.GetRange(minIndex, maxIndex - minIndex).ToArray(),
|
---|
86 | out mean, out variance, out skewness, out kurtosis);
|
---|
87 | qualityTrailSummary.Rows["Epoch Averages"].Values.Add(mean);
|
---|
88 | qualityTrailSummary.Rows["Epoch Variances"].Values.Add(variance);
|
---|
89 | qualityTrailSummary.Rows["Epoch Skewnesses"].Values.Add(skewness);
|
---|
90 | qualityTrailSummary.Rows["Epoch Kurtoses"].Values.Add(kurtosis);
|
---|
91 | }
|
---|
92 | }
|
---|
93 | return base.Apply();
|
---|
94 | }
|
---|
95 |
|
---|
96 | private QualityTrailSummaryTable CreateQualitytrailSummaryTable() {
|
---|
97 | QualityTrailSummaryTable qualityTrailSummary = new QualityTrailSummaryTable("Quality Trail Summary");
|
---|
98 | QualityTrailSummaryParameter.ActualValue = qualityTrailSummary;
|
---|
99 | qualityTrailSummary.Rows.Add(new DataRow("Value Quantiles"));
|
---|
100 | qualityTrailSummary.Rows.Add(new DataRow("Epoch Averages"));
|
---|
101 | qualityTrailSummary.Rows.Add(new DataRow("Epoch Variances"));
|
---|
102 | qualityTrailSummary.Rows.Add(new DataRow("Epoch Skewnesses"));
|
---|
103 | qualityTrailSummary.Rows.Add(new DataRow("Epoch Kurtoses"));
|
---|
104 | return qualityTrailSummary;
|
---|
105 | }
|
---|
106 |
|
---|
107 | }
|
---|
108 | }
|
---|