Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/SymbolicRegressionSolutionErrorCharacteristicsCurveView.cs @ 6807

Last change on this file since 6807 was 6807, checked in by gkronber, 13 years ago

#1081 added views for time series prognosis

File size: 4.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 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 System.Windows.Forms.DataVisualization.Charting;
26using HeuristicLab.Algorithms.DataAnalysis;
27using HeuristicLab.MainForm;
28using HeuristicLab.Problems.DataAnalysis.Views;
29
30namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views {
31  [View("Error Characteristics Curve")]
32  [Content(typeof(ISymbolicRegressionSolution))]
33  public partial class SymbolicRegressionSolutionErrorCharacteristicsCurveView : RegressionSolutionErrorCharacteristicsCurveView {
34    private IRegressionSolution linearRegressionSolution;
35    public SymbolicRegressionSolutionErrorCharacteristicsCurveView() {
36      InitializeComponent();
37    }
38
39    public new ISymbolicRegressionSolution Content {
40      get { return (ISymbolicRegressionSolution)base.Content; }
41      set { base.Content = value; }
42    }
43
44    protected override void OnContentChanged() {
45      if (Content != null)
46        linearRegressionSolution = CreateLinearRegressionSolution();
47      else
48        linearRegressionSolution = null;
49
50      base.OnContentChanged();
51    }
52
53    protected override void UpdateChart() {
54      base.UpdateChart();
55      if (Content == null || linearRegressionSolution == null) return;
56      AddRegressionSolution(linearRegressionSolution);
57    }
58
59    private IRegressionSolution CreateLinearRegressionSolution() {
60      if (Content == null) throw new InvalidOperationException();
61      double rmse, cvRmsError;
62      var problemData = (IRegressionProblemData)ProblemData.Clone();
63
64      //clear checked inputVariables
65      foreach (var inputVariable in problemData.InputVariables.CheckedItems) {
66        problemData.InputVariables.SetItemCheckedState(inputVariable.Value, false);
67      }
68
69      var laggedVariables = Content.Model.SymbolicExpressionTree.IterateNodesPostfix()
70        .OfType<LaggedVariableTreeNode>()
71        .Select(n => n.Lag)
72        .Where(l => l < 0);
73      if (laggedVariables.Any()) throw new NotSupportedException("The symbolic regression solution contains lagged variables.");
74
75      //check inputVariables used in the symbolic regression model
76      var usedVariables =
77        Content.Model.SymbolicExpressionTree.IterateNodesPostfix().OfType<VariableTreeNode>().Select(
78          node => node.VariableName).Distinct();
79      foreach (var variable in usedVariables) {
80        problemData.InputVariables.SetItemCheckedState(
81          problemData.InputVariables.Where(x => x.Value == variable).First(), true);
82      }
83
84      var solution = LinearRegression.CreateLinearRegressionSolution(problemData, out rmse, out cvRmsError);
85      solution.Name = "Linear Model";
86      return solution;
87    }
88
89    protected override void Content_ModelChanged(object sender, EventArgs e) {
90      linearRegressionSolution = CreateLinearRegressionSolution();
91      base.Content_ModelChanged(sender, e);
92    }
93
94    protected override void Content_ProblemDataChanged(object sender, EventArgs e) {
95      linearRegressionSolution = CreateLinearRegressionSolution();
96      base.Content_ProblemDataChanged(sender, e);
97    }
98
99    private void chart_MouseDown(object sender, MouseEventArgs e) {
100      if (e.Clicks < 2) return;
101      HitTestResult result = chart.HitTest(e.X, e.Y);
102      if (result.ChartElementType != ChartElementType.LegendItem) return;
103      if (result.Series.Name != linearRegressionSolution.Name) return;
104
105      MainFormManager.MainForm.ShowContent((IRegressionSolution)result.Series.Tag);
106    }
107  }
108}
Note: See TracBrowser for help on using the repository browser.