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