Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSolutionsAnalyzer.cs @ 13395

Last change on this file since 13395 was 13395, checked in by pfleck, 8 years ago

#2525

  • Changed unit test that it also lists types that have a StorableConstructor but are not marked as StorableClass.
  • Put both storable tests in a single StorableTest.cs.
  • Added missing StorableClassAttributes.
File size: 3.5 KB
RevLine 
[10596]1#region License Information
2
3/* HeuristicLab
[12012]4 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[10596]5 *
6 * This file is part of HeuristicLab.
7 *
8 * HeuristicLab is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * HeuristicLab is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#endregion
23
24using System;
25using System.Linq;
26using HeuristicLab.Analysis;
27using HeuristicLab.Common;
28using HeuristicLab.Core;
29using HeuristicLab.Operators;
30using HeuristicLab.Optimization;
31using HeuristicLab.Parameters;
32using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
33
34namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
[13395]35  [StorableClass]
[10596]36  public class SymbolicRegressionSolutionsAnalyzer : SingleSuccessorOperator, IAnalyzer {
37    private const string ResultCollectionParameterName = "Results";
38    private const string RegressionSolutionQualitiesResultName = "Regression Solution Qualities";
39
40    public ILookupParameter<ResultCollection> ResultCollectionParameter {
41      get { return (ILookupParameter<ResultCollection>)Parameters[ResultCollectionParameterName]; }
42    }
43
44    public virtual bool EnabledByDefault {
45      get { return false; }
46    }
47
48    [StorableConstructor]
49    protected SymbolicRegressionSolutionsAnalyzer(bool deserializing) : base(deserializing) { }
50    protected SymbolicRegressionSolutionsAnalyzer(SymbolicRegressionSolutionsAnalyzer original, Cloner cloner)
51      : base(original, cloner) { }
52    public override IDeepCloneable Clone(Cloner cloner) {
53      return new SymbolicRegressionSolutionsAnalyzer(this, cloner);
54    }
55
56    public SymbolicRegressionSolutionsAnalyzer() {
57      Parameters.Add(new LookupParameter<ResultCollection>(ResultCollectionParameterName, "The result collection to store the analysis results."));
58    }
59
60    public override IOperation Apply() {
61      var results = ResultCollectionParameter.ActualValue;
62
63      if (!results.ContainsKey(RegressionSolutionQualitiesResultName)) {
64        var newDataTable = new DataTable(RegressionSolutionQualitiesResultName);
65        results.Add(new Result(RegressionSolutionQualitiesResultName, "Chart displaying the training and test qualities of the regression solutions.", newDataTable));
66      }
67
68      var dataTable = (DataTable)results[RegressionSolutionQualitiesResultName].Value;
69      foreach (var result in results.Where(r => r.Value is IRegressionSolution)) {
70        var solution = (IRegressionSolution)result.Value;
71
72        var trainingR2 = result.Name + Environment.NewLine + "Training R²";
73        if (!dataTable.Rows.ContainsKey(trainingR2))
74          dataTable.Rows.Add(new DataRow(trainingR2));
75
76        var testR2 = result.Name + Environment.NewLine + " Test R²";
77        if (!dataTable.Rows.ContainsKey(testR2))
78          dataTable.Rows.Add(new DataRow(testR2));
79
80        dataTable.Rows[trainingR2].Values.Add(solution.TrainingRSquared);
81        dataTable.Rows[testR2].Values.Add(solution.TestRSquared);
82      }
83
84      return base.Apply();
85    }
86  }
87}
Note: See TracBrowser for help on using the repository browser.