Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionEstimatedValuesView.cs @ 5991

Last change on this file since 5991 was 5975, checked in by mkommend, 14 years ago

#1313: Updated view names to use spaces instead of !camelCasing.

File size: 3.8 KB
RevLine 
[3442]1#region License Information
2/* HeuristicLab
[5445]3 * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[3442]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
21using System;
22using System.Linq;
23using System.Windows.Forms;
[5829]24using HeuristicLab.Core.Views;
[4068]25using HeuristicLab.Data;
26using HeuristicLab.Data.Views;
[3442]27using HeuristicLab.MainForm;
28using HeuristicLab.MainForm.WindowsForms;
29
30namespace HeuristicLab.Problems.DataAnalysis.Views {
[5975]31  [View("Estimated Values")]
[5663]32  [Content(typeof(IRegressionSolution))]
[5829]33  public partial class RegressionSolutionEstimatedValuesView : ItemView, IRegressionSolutionEvaluationView {
[3442]34    private const string TARGETVARIABLE_SERIES_NAME = "TargetVariable";
35    private const string ESTIMATEDVALUES_SERIES_NAME = "EstimatedValues";
36
[5663]37    public new IRegressionSolution Content {
38      get { return (IRegressionSolution)base.Content; }
[3442]39      set {
40        base.Content = value;
41      }
42    }
43
44    private StringConvertibleMatrixView matrixView;
45
[5663]46    public RegressionSolutionEstimatedValuesView()
[3442]47      : base() {
48      InitializeComponent();
49      matrixView = new StringConvertibleMatrixView();
[5014]50      matrixView.ShowRowsAndColumnsTextBox = false;
51      matrixView.ShowStatisticalInformation = false;
[3442]52      matrixView.Dock = DockStyle.Fill;
53      this.Controls.Add(matrixView);
54    }
55
56    #region events
57    protected override void RegisterContentEvents() {
58      base.RegisterContentEvents();
[5663]59      Content.ModelChanged += new EventHandler(Content_ModelChanged);
[3442]60      Content.ProblemDataChanged += new EventHandler(Content_ProblemDataChanged);
61    }
62
63    protected override void DeregisterContentEvents() {
64      base.DeregisterContentEvents();
[5663]65      Content.ModelChanged -= new EventHandler(Content_ModelChanged);
[3442]66      Content.ProblemDataChanged -= new EventHandler(Content_ProblemDataChanged);
67    }
68
[5663]69    private void Content_ProblemDataChanged(object sender, EventArgs e) {
[3442]70      OnContentChanged();
71    }
72
[5663]73    private void Content_ModelChanged(object sender, EventArgs e) {
[3442]74      OnContentChanged();
75    }
76
77    protected override void OnContentChanged() {
78      base.OnContentChanged();
79      UpdateEstimatedValues();
80    }
81
82    private void UpdateEstimatedValues() {
83      if (InvokeRequired) Invoke((Action)UpdateEstimatedValues);
84      else {
[4011]85        DoubleMatrix matrix = null;
86        if (Content != null) {
[5014]87          double[,] values = new double[Content.ProblemData.Dataset.Rows, 4];
88
[5663]89          double[] target = Content.ProblemData.Dataset.GetVariableValues(Content.ProblemData.TargetVariable);
[5014]90          double[] estimated = Content.EstimatedValues.ToArray();
91          for (int row = 0; row < target.Length; row++) {
92            values[row, 0] = target[row];
93            values[row, 1] = estimated[row];
94            values[row, 2] = estimated[row] - target[row];
95            values[row, 3] = estimated[row] / target[row] - 1;
96          }
97
[4011]98          matrix = new DoubleMatrix(values);
[5663]99          matrix.ColumnNames = new string[] { TARGETVARIABLE_SERIES_NAME, ESTIMATEDVALUES_SERIES_NAME, "Absolute Error", "Relative Error" };
[4011]100        }
101        matrixView.Content = matrix;
[3442]102      }
103    }
104    #endregion
105  }
106}
Note: See TracBrowser for help on using the repository browser.