Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2745_EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/Operators/VariableVariabilityAnalyzer.cs @ 17432

Last change on this file since 17432 was 17332, checked in by bwerth, 5 years ago

#2745 updated persistence to HEAL.Attic

File size: 4.6 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 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;
23using System.Linq;
24using HEAL.Attic;
25using HeuristicLab.Analysis;
26using HeuristicLab.Common;
27using HeuristicLab.Core;
28using HeuristicLab.Data;
29using HeuristicLab.Operators;
30using HeuristicLab.Optimization;
31using HeuristicLab.Parameters;
32using HeuristicLab.Problems.DataAnalysis;
33
34namespace HeuristicLab.Algorithms.EGO {
35  [Item("VariableVariabilityAnalyzer", "Analyzes the correlation between perdictions and actual fitness values")]
36    [StorableType("3bc82bbb-e9dd-4a50-8241-cfcf230be8c9")]
37    public class VariableVariabilityAnalyzer : SingleSuccessorOperator, IAnalyzer, IResultsOperator {
38    public override bool CanChangeName => true;
39    public bool EnabledByDefault => false;
40
41    public ILookupParameter<ModifiableDataset> DatasetParameter => (ILookupParameter<ModifiableDataset>)Parameters["Dataset"];
42    public ILookupParameter<ResultCollection> ResultsParameter => (ILookupParameter<ResultCollection>)Parameters["Results"];
43    public ILookupParameter<IntValue> InitialEvaluationsParameter => (ILookupParameter<IntValue>)Parameters["Initial Evaluations"];
44    public IFixedValueParameter<IntValue> LookBackSizeParameter => (IFixedValueParameter<IntValue>)Parameters["LookBackSize"];
45
46    private const string NormalizedPlotName = "Normalized Variable Variance";
47    private const string PlotName = "Variable Variance";
48
49    [StorableConstructor]
50    protected VariableVariabilityAnalyzer(StorableConstructorFlag deserializing) : base(deserializing) { }
51    protected VariableVariabilityAnalyzer(VariableVariabilityAnalyzer original, Cloner cloner) : base(original, cloner) { }
52    public VariableVariabilityAnalyzer() {
53      Parameters.Add(new FixedValueParameter<IntValue>("LookBackSize", new IntValue(10)));
54      Parameters.Add(new LookupParameter<IntValue>("Initial Evaluations"));
55      Parameters.Add(new LookupParameter<ModifiableDataset>("Dataset"));
56      Parameters.Add(new LookupParameter<ResultCollection>("Results", "The collection to store the results in."));
57    }
58
59    public override IDeepCloneable Clone(Cloner cloner) {
60      return new VariableVariabilityAnalyzer(this, cloner);
61    }
62
63    public sealed override IOperation Apply() {
64      var dataset = DatasetParameter.ActualValue;
65      var results = ResultsParameter.ActualValue;
66      var initialEvals = InitialEvaluationsParameter.ActualValue.Value;
67      var lbsize = LookBackSizeParameter.Value.Value;
68
69      var normPlot = CreateScatterPlotResult(results, NormalizedPlotName);
70      var plot = CreateScatterPlotResult(results, PlotName);
71      foreach (var s in dataset.VariableNames) {
72        if (!normPlot.Rows.ContainsKey(s)) normPlot.Rows.Add(new DataRow(s));
73        if (!plot.Rows.ContainsKey(s)) plot.Rows.Add(new DataRow(s));
74
75        if (dataset.Rows < lbsize) continue;
76        var wd = dataset.GetDoubleValues(s, Enumerable.Range(dataset.Rows - lbsize, lbsize)).StandardDeviation();
77        plot.Rows[s].Values.Add(wd);
78
79        if (dataset.Rows < Math.Max(initialEvals, lbsize)) continue;
80        var sd = dataset.GetDoubleValues(s, Enumerable.Range(0, initialEvals)).StandardDeviation();
81        normPlot.Rows[s].Values.Add(wd / sd);
82      }
83      return base.Apply();
84    }
85
86    private static DataTable CreateScatterPlotResult(ResultCollection results, string plotname) {
87      DataTable plot;
88      if (!results.ContainsKey(plotname)) {
89        plot = new DataTable(plotname) {
90          VisualProperties = {
91            XAxisTitle = "Iteration",
92            YAxisTitle = plotname.Equals(NormalizedPlotName)? "Normalized Variance (Variance of last Samples)/(Variance of Initial Samples)" : "Standard deviation of last samples"
93          }
94        };
95        results.Add(new Result(plotname, plot));
96      }
97      plot = (DataTable)results[plotname].Value;
98      return plot;
99    }
100
101  }
102}
Note: See TracBrowser for help on using the repository browser.