Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2745_EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/Operators/ModelQualityAnalyzer.cs @ 17915

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

#2745 updated persistence to HEAL.Attic

File size: 4.1 KB
RevLine 
[15064]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
[17332]22using HEAL.Attic;
[15064]23using HeuristicLab.Analysis;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Operators;
27using HeuristicLab.Optimization;
28using HeuristicLab.Parameters;
29using HeuristicLab.Problems.DataAnalysis;
30
31namespace HeuristicLab.Algorithms.EGO {
32  [Item("ModelQualityAnalyzer", "Collects RealVectors into a modifiablbe dataset")]
[17332]33    [StorableType("12c5a773-4397-45eb-ad25-0ffc897513f8")]
34    public class ModelQualityAnalyzer : SingleSuccessorOperator, IAnalyzer, IResultsOperator {
[15064]35    public override bool CanChangeName => true;
36    public bool EnabledByDefault => false;
37
38    public ILookupParameter<IRegressionSolution> ModelParameter => (ILookupParameter<IRegressionSolution>)Parameters["Model"];
39    public ILookupParameter<ResultCollection> ResultsParameter => (ILookupParameter<ResultCollection>)Parameters["Results"];
40
41    private const string PlotName = "Model Quality Values";
42    private const string R2RowName = "Training R²";
43    private const string MAERowName = "Training Mean Absolute Error";
44    private const string RMSERowName = "Training Root Mean Squared Error";
45    private const string ModelResultName = "Model";
46
47
48    [StorableConstructor]
[17332]49    protected ModelQualityAnalyzer(StorableConstructorFlag deserializing) : base(deserializing) { }
[15064]50    protected ModelQualityAnalyzer(ModelQualityAnalyzer original, Cloner cloner) : base(original, cloner) { }
51    public ModelQualityAnalyzer() {
52      Parameters.Add(new LookupParameter<IRegressionSolution>("Model", "The model of this iteration"));
53      Parameters.Add(new LookupParameter<ResultCollection>("Results", "The collection to store the results in."));
54    }
55
56    public override IDeepCloneable Clone(Cloner cloner) {
57      return new ModelQualityAnalyzer(this, cloner);
58    }
59
60    public sealed override IOperation Apply() {
61      var model = ModelParameter.ActualValue;
62      var results = ResultsParameter.ActualValue;
63      if (model == null) return base.Apply();
64      var plot = CreateDataTableResult(results);
65      plot.Rows[R2RowName].Values.Add(model.TrainingRSquared);
66      plot.Rows[MAERowName].Values.Add(model.TrainingMeanAbsoluteError);
67      plot.Rows[RMSERowName].Values.Add(model.TrainingRootMeanSquaredError);
68      if (!results.ContainsKey(ModelResultName)) results.Add(new Result(ModelResultName, model));
69      results[ModelResultName].Value = model;
70      return base.Apply();
71    }
72
73    private static DataTable CreateDataTableResult(ResultCollection results) {
74      DataTable plot;
75      if (!results.ContainsKey(PlotName)) {
76        plot = new DataTable("Model-Quality-Measures", "The quality measures of the models on the training data") {
77          VisualProperties = {
78            XAxisTitle = "Generation",
79          }
80        };
81        results.Add(new Result(PlotName, plot));
82      } else plot = (DataTable)results[PlotName].Value;
83      if (!plot.Rows.ContainsKey(R2RowName)) plot.Rows.Add(new DataRow(R2RowName, R2RowName, new double[0]));
84      if (!plot.Rows.ContainsKey(MAERowName)) plot.Rows.Add(new DataRow(MAERowName, MAERowName, new double[0]));
85      if (!plot.Rows.ContainsKey(RMSERowName)) plot.Rows.Add(new DataRow(RMSERowName, RMSERowName, new double[0]));
86
87      return plot;
88    }
89
90  }
91}
Note: See TracBrowser for help on using the repository browser.