Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 12099 was 12009, checked in by ascheibe, 10 years ago

#2212 updated copyright year

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  public class SymbolicRegressionSolutionsAnalyzer : SingleSuccessorOperator, IAnalyzer {
36    private const string ResultCollectionParameterName = "Results";
37    private const string RegressionSolutionQualitiesResultName = "Regression Solution Qualities";
38
39    public ILookupParameter<ResultCollection> ResultCollectionParameter {
40      get { return (ILookupParameter<ResultCollection>)Parameters[ResultCollectionParameterName]; }
41    }
42
43    public virtual bool EnabledByDefault {
44      get { return false; }
45    }
46
47    [StorableConstructor]
48    protected SymbolicRegressionSolutionsAnalyzer(bool deserializing) : base(deserializing) { }
49    protected SymbolicRegressionSolutionsAnalyzer(SymbolicRegressionSolutionsAnalyzer original, Cloner cloner)
50      : base(original, cloner) { }
51    public override IDeepCloneable Clone(Cloner cloner) {
52      return new SymbolicRegressionSolutionsAnalyzer(this, cloner);
53    }
54
55    public SymbolicRegressionSolutionsAnalyzer() {
56      Parameters.Add(new LookupParameter<ResultCollection>(ResultCollectionParameterName, "The result collection to store the analysis results."));
57    }
58
59    public override IOperation Apply() {
60      var results = ResultCollectionParameter.ActualValue;
61
62      if (!results.ContainsKey(RegressionSolutionQualitiesResultName)) {
63        var newDataTable = new DataTable(RegressionSolutionQualitiesResultName);
64        results.Add(new Result(RegressionSolutionQualitiesResultName, "Chart displaying the training and test qualities of the regression solutions.", newDataTable));
65      }
66
67      var dataTable = (DataTable)results[RegressionSolutionQualitiesResultName].Value;
68      foreach (var result in results.Where(r => r.Value is IRegressionSolution)) {
69        var solution = (IRegressionSolution)result.Value;
70
71        var trainingR2 = result.Name + Environment.NewLine + "Training R²";
72        if (!dataTable.Rows.ContainsKey(trainingR2))
73          dataTable.Rows.Add(new DataRow(trainingR2));
74
75        var testR2 = result.Name + Environment.NewLine + " Test R²";
76        if (!dataTable.Rows.ContainsKey(testR2))
77          dataTable.Rows.Add(new DataRow(testR2));
78
79        dataTable.Rows[trainingR2].Values.Add(solution.TrainingRSquared);
80        dataTable.Rows[testR2].Values.Add(solution.TestRSquared);
81      }
82
83      return base.Apply();
84    }
85  }
86}
Note: See TracBrowser for help on using the repository browser.