#region License Information /* HeuristicLab * Copyright (C) 2002-2016 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 HeuristicLab.Analysis; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Operators; using HeuristicLab.Optimization; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using HeuristicLab.Problems.DataAnalysis; namespace HeuristicLab.Algorithms.EGO { [Item("ModelQualityAnalyzer", "Collects RealVectors into a modifiablbe dataset")] [StorableClass] public class ModelQualityAnalyzer : SingleSuccessorOperator, IAnalyzer, IResultsOperator { public override bool CanChangeName => true; public bool EnabledByDefault => false; public ILookupParameter ModelParameter => (ILookupParameter)Parameters["Model"]; public ILookupParameter ResultsParameter => (ILookupParameter)Parameters["Results"]; private const string PlotName = "Model Quality Values"; private const string R2RowName = "Training R²"; private const string MAERowName = "Training Mean Absolute Error"; private const string RMSERowName = "Training Root Mean Squared Error"; private const string ModelResultName = "Model"; [StorableConstructor] protected ModelQualityAnalyzer(bool deserializing) : base(deserializing) { } protected ModelQualityAnalyzer(ModelQualityAnalyzer original, Cloner cloner) : base(original, cloner) { } public ModelQualityAnalyzer() { Parameters.Add(new LookupParameter("Model", "The model of this iteration")); Parameters.Add(new LookupParameter("Results", "The collection to store the results in.")); } public override IDeepCloneable Clone(Cloner cloner) { return new ModelQualityAnalyzer(this, cloner); } public sealed override IOperation Apply() { var model = ModelParameter.ActualValue; var results = ResultsParameter.ActualValue; if (model == null) return base.Apply(); var plot = CreateDataTableResult(results); plot.Rows[R2RowName].Values.Add(model.TrainingRSquared); plot.Rows[MAERowName].Values.Add(model.TrainingMeanAbsoluteError); plot.Rows[RMSERowName].Values.Add(model.TrainingRootMeanSquaredError); if (!results.ContainsKey(ModelResultName)) results.Add(new Result(ModelResultName, model)); results[ModelResultName].Value = model; return base.Apply(); } private static DataTable CreateDataTableResult(ResultCollection results) { DataTable plot; if (!results.ContainsKey(PlotName)) { plot = new DataTable("Model-Quality-Measures", "The quality measures of the models on the training data") { VisualProperties = { XAxisTitle = "Generation", } }; results.Add(new Result(PlotName, plot)); } else plot = (DataTable)results[PlotName].Value; if (!plot.Rows.ContainsKey(R2RowName)) plot.Rows.Add(new DataRow(R2RowName, R2RowName, new double[0])); if (!plot.Rows.ContainsKey(MAERowName)) plot.Rows.Add(new DataRow(MAERowName, MAERowName, new double[0])); if (!plot.Rows.ContainsKey(RMSERowName)) plot.Rows.Add(new DataRow(RMSERowName, RMSERowName, new double[0])); return plot; } } }