Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PausableBasicAlgorithm/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/SymbolicRegressionSolutionErrorCharacteristicsCurveView.cs @ 14388

Last change on this file since 14388 was 13003, checked in by gkronber, 9 years ago

#2452 refactored RegressionSolutionErrorCharacteristicsCurveView to better support comparison of a set of solutions in one chart (via drag&drop)

File size: 3.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 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
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using HeuristicLab.Algorithms.DataAnalysis;
26using HeuristicLab.MainForm;
27using HeuristicLab.Problems.DataAnalysis.Views;
28
29namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views {
30  [View("Error Characteristics Curve")]
31  [Content(typeof(ISymbolicRegressionSolution))]
32  public partial class SymbolicRegressionSolutionErrorCharacteristicsCurveView : RegressionSolutionErrorCharacteristicsCurveView {
33    public SymbolicRegressionSolutionErrorCharacteristicsCurveView() {
34      InitializeComponent();
35    }
36
37    public new ISymbolicRegressionSolution Content {
38      get { return (ISymbolicRegressionSolution)base.Content; }
39      set { base.Content = value; }
40    }
41
42    private IRegressionSolution CreateLinearRegressionSolution() {
43      if (Content == null) throw new InvalidOperationException();
44      double rmse, cvRmsError;
45      var problemData = (IRegressionProblemData)ProblemData.Clone();
46      if (!problemData.TrainingIndices.Any()) return null; // don't create an LR model if the problem does not have a training set (e.g. loaded into an existing model)
47
48      //clear checked inputVariables
49      foreach (var inputVariable in problemData.InputVariables.CheckedItems) {
50        problemData.InputVariables.SetItemCheckedState(inputVariable.Value, false);
51      }
52
53      //check inputVariables used in the symbolic regression model
54      var usedVariables =
55        Content.Model.SymbolicExpressionTree.IterateNodesPostfix().OfType<VariableTreeNode>().Select(
56          node => node.VariableName).Distinct();
57      foreach (var variable in usedVariables) {
58        problemData.InputVariables.SetItemCheckedState(
59          problemData.InputVariables.First(x => x.Value == variable), true);
60      }
61
62      var solution = LinearRegression.CreateLinearRegressionSolution(problemData, out rmse, out cvRmsError);
63      solution.Name = "Baseline (linear subset)";
64      return solution;
65    }
66
67
68    protected override IEnumerable<IRegressionSolution> CreateBaselineSolutions() {
69      foreach (var sol in base.CreateBaselineSolutions()) yield return sol;
70      yield return CreateLinearRegressionSolution();
71    }
72  }
73}
Note: See TracBrowser for help on using the repository browser.