Free cookie consent management tool by TermsFeed Policy Generator

source: branches/FitnessLandscapeAnalysis/HeuristicLab.Analysis.FitnessLandscape/Analysis/QualityTrailSummarizer.cs @ 8694

Last change on this file since 8694 was 7176, checked in by gkronber, 13 years ago

#1696 adapted analyzers to compile with changes of r7172 (#1584)

File size: 4.9 KB
RevLine 
[7128]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
22using System.Linq;
23using HeuristicLab.Analysis.FitnessLandscape.DataTables;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Data;
27using HeuristicLab.Operators;
28using HeuristicLab.Optimization.Operators;
29using HeuristicLab.Parameters;
30using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
31using System;
32
33namespace HeuristicLab.Analysis.FitnessLandscape.Analysis {
34
35  [StorableClass]
36  public class QualityTrailSummarizer : AlgorithmOperator, IQualityTrailAnalyzer {
[7176]37    public bool EnabledByDefault {
38      get { return false; }
39    }
[7128]40
41    #region Parameters
42    public LookupParameter<DataTable> QualityTrailParameter {
43      get { return (LookupParameter<DataTable>)Parameters["Quality Trail"]; }
44    }
45    public LookupParameter<QualityTrailSummaryTable> QualityTrailSummaryParameter {
46      get { return (LookupParameter<QualityTrailSummaryTable>)Parameters["QualityTrailSummary"]; }
47    }
48    public LookupParameter<VariableCollection> ResultsParameter {
49      get { return (LookupParameter<VariableCollection>)Parameters["Results"]; }
50    }
51    #endregion
52
53    #region Construction & Cloning
54    [StorableConstructor]
55    protected QualityTrailSummarizer(bool deserializing) : base(deserializing) { }
56    protected QualityTrailSummarizer(QualityTrailSummarizer original, Cloner cloner) : base(original, cloner) { }
57
58    public QualityTrailSummarizer() {
59      Parameters.Add(new LookupParameter<DataTable>("Quality Trail", "The quality of the solution"));
60      Parameters.Add(new LookupParameter<QualityTrailSummaryTable>("QualityTrailSummary", "Maximum nr of steps between statistically significantly correlated quality values"));
61      Parameters.Add(new LookupParameter<VariableCollection>("Results", "The collection of all results of this algorithm"));
62
63      var resultsCollector = new ResultsCollector();
64      resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>(QualityTrailSummaryParameter.Name));
65
66      OperatorGraph.InitialOperator = resultsCollector;
67    }
68
69    public override IDeepCloneable Clone(Cloner cloner) {
70      return new QualityTrailSummarizer(this, cloner);
71    }
72    #endregion
73
74    public override IOperation Apply() {
75      QualityTrailSummaryTable qualityTrailSummary = CreateQualitytrailSummaryTable();
76      DataTable qualityTrail = QualityTrailParameter.ActualValue;
77      if (qualityTrail != null && qualityTrail.Rows.Count > 1) {
78        var values = qualityTrail.Rows.First().Values;       
79        DistributionAnalyzer analyzer = new DistributionAnalyzer(values);
80        qualityTrailSummary.Rows["Value Quantiles"].Values.AddRange(new[] { 0, 0.25, 0.5, 0.75, 1 }.Select(q => analyzer[q]));
81        double variance, kurtosis, skewness, mean;
82        for (int i = 0; i < 4; i++) {
83          int minIndex = (int)Math.Round(i*values.Count*0.25);
84          int maxIndex = (int)Math.Round((i+1)*values.Count*0.25);
85          alglib.samplemoments(
86            values.GetRange(minIndex, maxIndex - minIndex).ToArray(),
87            out mean, out variance, out skewness, out kurtosis);
88          qualityTrailSummary.Rows["Epoch Averages"].Values.Add(mean);
89          qualityTrailSummary.Rows["Epoch Variances"].Values.Add(variance);
90          qualityTrailSummary.Rows["Epoch Skewnesses"].Values.Add(skewness);
91          qualityTrailSummary.Rows["Epoch Kurtoses"].Values.Add(kurtosis);
92        }
93      }
94      return base.Apply();
95    }
96
97    private QualityTrailSummaryTable CreateQualitytrailSummaryTable() {
98      QualityTrailSummaryTable qualityTrailSummary = new QualityTrailSummaryTable("Quality Trail Summary");
99      QualityTrailSummaryParameter.ActualValue = qualityTrailSummary;
100      qualityTrailSummary.Rows.Add(new DataRow("Value Quantiles"));
101      qualityTrailSummary.Rows.Add(new DataRow("Epoch Averages"));
102      qualityTrailSummary.Rows.Add(new DataRow("Epoch Variances"));
103      qualityTrailSummary.Rows.Add(new DataRow("Epoch Skewnesses"));
104      qualityTrailSummary.Rows.Add(new DataRow("Epoch Kurtoses"));
105      return qualityTrailSummary;
106    }
107
108  }
109}
Note: See TracBrowser for help on using the repository browser.