Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/SymbolicRegressionSolutionErrorCharacteristicsCurveView.cs @ 11142

Last change on this file since 11142 was 11093, checked in by gkronber, 10 years ago

#2197: fixed bugs in views for data analysis solutions that might occur if the problem does not have training samples (e.g. when the data is loaded into an existing solution)

File size: 3.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 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.Linq;
24using System.Windows.Forms;
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    private IRegressionSolution linearRegressionSolution;
34    public SymbolicRegressionSolutionErrorCharacteristicsCurveView() {
35      InitializeComponent();
36    }
37
38    public new ISymbolicRegressionSolution Content {
39      get { return (ISymbolicRegressionSolution)base.Content; }
40      set { base.Content = value; }
41    }
42
43    protected override void OnContentChanged() {
44      if (Content != null)
45        linearRegressionSolution = CreateLinearRegressionSolution();
46      else
47        linearRegressionSolution = null;
48
49      base.OnContentChanged();
50    }
51
52    protected override void UpdateChart() {
53      base.UpdateChart();
54      if (Content == null || linearRegressionSolution == null) return;
55      AddRegressionSolution(linearRegressionSolution);
56    }
57
58    private IRegressionSolution CreateLinearRegressionSolution() {
59      if (Content == null) throw new InvalidOperationException();
60      double rmse, cvRmsError;
61      var problemData = (IRegressionProblemData)ProblemData.Clone();
62      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)
63
64      //clear checked inputVariables
65      foreach (var inputVariable in problemData.InputVariables.CheckedItems) {
66        problemData.InputVariables.SetItemCheckedState(inputVariable.Value, false);
67      }
68
69      //check inputVariables used in the symbolic regression model
70      var usedVariables =
71        Content.Model.SymbolicExpressionTree.IterateNodesPostfix().OfType<VariableTreeNode>().Select(
72          node => node.VariableName).Distinct();
73      foreach (var variable in usedVariables) {
74        problemData.InputVariables.SetItemCheckedState(
75          problemData.InputVariables.First(x => x.Value == variable), true);
76      }
77
78      var solution = LinearRegression.CreateLinearRegressionSolution(problemData, out rmse, out cvRmsError);
79      solution.Name = "Linear Model";
80      return solution;
81    }
82
83    protected override void Content_ModelChanged(object sender, EventArgs e) {
84      linearRegressionSolution = CreateLinearRegressionSolution();
85      base.Content_ModelChanged(sender, e);
86    }
87
88    protected override void Content_ProblemDataChanged(object sender, EventArgs e) {
89      linearRegressionSolution = CreateLinearRegressionSolution();
90      base.Content_ProblemDataChanged(sender, e);
91    }
92  }
93}
Note: See TracBrowser for help on using the repository browser.