Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PersistenceSpeedUp/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/SymbolicRegressionSolutionErrorCharacteristicsCurveView.cs @ 14427

Last change on this file since 14427 was 6760, checked in by epitzer, 13 years ago

#1530 integrate changes from trunk

File size: 4.0 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      //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.Where(x => x.Value == variable).First(), 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    private void chart_MouseDown(object sender, MouseEventArgs e) {
94      if (e.Clicks < 2) return;
95      HitTestResult result = chart.HitTest(e.X, e.Y);
96      if (result.ChartElementType != ChartElementType.LegendItem) return;
97      if (result.Series.Name != linearRegressionSolution.Name) return;
98
99      MainFormManager.MainForm.ShowContent((IRegressionSolution)result.Series.Tag);
100    }
101  }
102}
Note: See TracBrowser for help on using the repository browser.