[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
|
---|
| 21 | using System;
|
---|
| 22 | using System.Linq;
|
---|
| 23 | using System.Windows.Forms;
|
---|
[5829] | 24 | using HeuristicLab.Core.Views;
|
---|
[4068] | 25 | using HeuristicLab.Data;
|
---|
| 26 | using HeuristicLab.Data.Views;
|
---|
[3442] | 27 | using HeuristicLab.MainForm;
|
---|
| 28 | using HeuristicLab.MainForm.WindowsForms;
|
---|
[6255] | 29 | using System.Globalization;
|
---|
[3442] | 30 |
|
---|
| 31 | namespace HeuristicLab.Problems.DataAnalysis.Views {
|
---|
[5975] | 32 | [View("Estimated Values")]
|
---|
[5663] | 33 | [Content(typeof(IRegressionSolution))]
|
---|
[5829] | 34 | public partial class RegressionSolutionEstimatedValuesView : ItemView, IRegressionSolutionEvaluationView {
|
---|
[6238] | 35 | private const string TARGETVARIABLE_SERIES_NAME = "Target Variable";
|
---|
[6255] | 36 | private const string ESTIMATEDVALUES_SERIES_NAME = "Estimated Values (all)";
|
---|
[6238] | 37 | private const string ESTIMATEDVALUES_TRAINING_SERIES_NAME = "Estimated Values (training)";
|
---|
| 38 | private const string ESTIMATEDVALUES_TEST_SERIES_NAME = "Estimated Values (test)";
|
---|
[3442] | 39 |
|
---|
[5663] | 40 | public new IRegressionSolution Content {
|
---|
| 41 | get { return (IRegressionSolution)base.Content; }
|
---|
[3442] | 42 | set {
|
---|
| 43 | base.Content = value;
|
---|
| 44 | }
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | private StringConvertibleMatrixView matrixView;
|
---|
| 48 |
|
---|
[5663] | 49 | public RegressionSolutionEstimatedValuesView()
|
---|
[3442] | 50 | : base() {
|
---|
| 51 | InitializeComponent();
|
---|
| 52 | matrixView = new StringConvertibleMatrixView();
|
---|
[5014] | 53 | matrixView.ShowRowsAndColumnsTextBox = false;
|
---|
| 54 | matrixView.ShowStatisticalInformation = false;
|
---|
[3442] | 55 | matrixView.Dock = DockStyle.Fill;
|
---|
| 56 | this.Controls.Add(matrixView);
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | #region events
|
---|
| 60 | protected override void RegisterContentEvents() {
|
---|
| 61 | base.RegisterContentEvents();
|
---|
[5663] | 62 | Content.ModelChanged += new EventHandler(Content_ModelChanged);
|
---|
[3442] | 63 | Content.ProblemDataChanged += new EventHandler(Content_ProblemDataChanged);
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | protected override void DeregisterContentEvents() {
|
---|
| 67 | base.DeregisterContentEvents();
|
---|
[5663] | 68 | Content.ModelChanged -= new EventHandler(Content_ModelChanged);
|
---|
[3442] | 69 | Content.ProblemDataChanged -= new EventHandler(Content_ProblemDataChanged);
|
---|
| 70 | }
|
---|
| 71 |
|
---|
[5663] | 72 | private void Content_ProblemDataChanged(object sender, EventArgs e) {
|
---|
[3442] | 73 | OnContentChanged();
|
---|
| 74 | }
|
---|
| 75 |
|
---|
[5663] | 76 | private void Content_ModelChanged(object sender, EventArgs e) {
|
---|
[3442] | 77 | OnContentChanged();
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | protected override void OnContentChanged() {
|
---|
| 81 | base.OnContentChanged();
|
---|
| 82 | UpdateEstimatedValues();
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | private void UpdateEstimatedValues() {
|
---|
| 86 | if (InvokeRequired) Invoke((Action)UpdateEstimatedValues);
|
---|
| 87 | else {
|
---|
[6255] | 88 | StringMatrix matrix = null;
|
---|
[4011] | 89 | if (Content != null) {
|
---|
[6255] | 90 | string[,] values = new string[Content.ProblemData.Dataset.Rows, 7];
|
---|
[5014] | 91 |
|
---|
[5663] | 92 | double[] target = Content.ProblemData.Dataset.GetVariableValues(Content.ProblemData.TargetVariable);
|
---|
[6255] | 93 | var estimated = Content.EstimatedValues.GetEnumerator();
|
---|
[6238] | 94 | var estimated_training = Content.EstimatedTrainingValues.GetEnumerator();
|
---|
| 95 | var estimated_test = Content.EstimatedTestValues.GetEnumerator();
|
---|
| 96 |
|
---|
| 97 | foreach (var row in Content.ProblemData.TrainingIndizes) {
|
---|
| 98 | estimated_training.MoveNext();
|
---|
[6255] | 99 | values[row, 3] = estimated_training.Current.ToString();
|
---|
[6238] | 100 | }
|
---|
| 101 |
|
---|
| 102 | foreach (var row in Content.ProblemData.TestIndizes) {
|
---|
| 103 | estimated_test.MoveNext();
|
---|
[6255] | 104 | values[row, 4] = estimated_test.Current.ToString();
|
---|
[6238] | 105 | }
|
---|
| 106 |
|
---|
[6255] | 107 | foreach (var row in Enumerable.Range(0, Content.ProblemData.Dataset.Rows)) {
|
---|
| 108 | estimated.MoveNext();
|
---|
| 109 | double est = estimated.Current;
|
---|
| 110 | double res = Math.Abs(est - target[row]);
|
---|
| 111 | values[row, 0] = row.ToString();
|
---|
| 112 | values[row, 1] = target[row].ToString();
|
---|
| 113 | values[row, 2] = est.ToString();
|
---|
| 114 | values[row, 5] = Math.Abs(res).ToString();
|
---|
| 115 | values[row, 6] = Math.Abs(res / est).ToString();
|
---|
[5014] | 116 | }
|
---|
| 117 |
|
---|
[6255] | 118 | matrix = new StringMatrix(values);
|
---|
| 119 | matrix.ColumnNames = new string[] { "Id", TARGETVARIABLE_SERIES_NAME, ESTIMATEDVALUES_SERIES_NAME, ESTIMATEDVALUES_TRAINING_SERIES_NAME, ESTIMATEDVALUES_TEST_SERIES_NAME, "Absolute Error (all)", "Relative Error (all)" };
|
---|
| 120 | matrix.SortableView = true;
|
---|
[4011] | 121 | }
|
---|
| 122 | matrixView.Content = matrix;
|
---|
[3442] | 123 | }
|
---|
| 124 | }
|
---|
| 125 | #endregion
|
---|
| 126 | }
|
---|
| 127 | }
|
---|