Free cookie consent management tool by TermsFeed Policy Generator

source: branches/gteufl/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/SymbolicRegressionSolutionErrorCharacteristicsCurveView.cs @ 12062

Last change on this file since 12062 was 9456, checked in by swagner, 12 years ago

Updated copyright year and added some missing license headers (#1889)

File size: 3.5 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
63      //clear checked inputVariables
64      foreach (var inputVariable in problemData.InputVariables.CheckedItems) {
65        problemData.InputVariables.SetItemCheckedState(inputVariable.Value, false);
66      }
67
68      //check inputVariables used in the symbolic regression model
69      var usedVariables =
70        Content.Model.SymbolicExpressionTree.IterateNodesPostfix().OfType<VariableTreeNode>().Select(
71          node => node.VariableName).Distinct();
72      foreach (var variable in usedVariables) {
73        problemData.InputVariables.SetItemCheckedState(
74          problemData.InputVariables.First(x => x.Value == variable), true);
75      }
76
77      var solution = LinearRegression.CreateLinearRegressionSolution(problemData, out rmse, out cvRmsError);
78      solution.Name = "Linear Model";
79      return solution;
80    }
81
82    protected override void Content_ModelChanged(object sender, EventArgs e) {
83      linearRegressionSolution = CreateLinearRegressionSolution();
84      base.Content_ModelChanged(sender, e);
85    }
86
87    protected override void Content_ProblemDataChanged(object sender, EventArgs e) {
88      linearRegressionSolution = CreateLinearRegressionSolution();
89      base.Content_ProblemDataChanged(sender, e);
90    }
91  }
92}
Note: See TracBrowser for help on using the repository browser.