Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSolutionsAnalyzer.cs @ 13704

Last change on this file since 13704 was 13636, checked in by mkommend, 9 years ago

#2525: Merged r13392, r13393 and r13395 into stable.

File size: 3.5 KB
Line 
1#region License Information
2
3/* HeuristicLab
4 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
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 {
35  [StorableClass]
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.