[13439] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2015 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.Problems.DataAnalysis.Views;
|
---|
| 28 |
|
---|
| 29 | namespace HeuristicLab.Algorithms.DataAnalysis.Views {
|
---|
| 30 | [View("Estimated Values")]
|
---|
| 31 | [Content(typeof(GaussianProcessRegressionSolution), false)]
|
---|
| 32 | public partial class GaussianProcessRegressionSolutionEstimatedValuesView : RegressionSolutionEstimatedValuesView {
|
---|
| 33 | private const string TARGETVARIABLE_SERIES_NAME = "Target Variable";
|
---|
| 34 | private const string ESTIMATEDVALUES_SERIES_NAME = "Estimated Values (all)";
|
---|
| 35 | private const string ESTIMATEDVALUES_TRAINING_SERIES_NAME = "Estimated Values (training)";
|
---|
| 36 | private const string ESTIMATEDVALUES_TEST_SERIES_NAME = "Estimated Values (test)";
|
---|
| 37 | private const string ESTIMATEDVARIANCE_TRAINING_SERIES_NAME = "Estimated Variance (training)";
|
---|
| 38 | private const string ESTIMATEDVARIANCE_TEST_SERIES_NAME = "Estimated Variance (test)";
|
---|
| 39 |
|
---|
| 40 | public new GaussianProcessRegressionSolution Content {
|
---|
| 41 | get { return (GaussianProcessRegressionSolution)base.Content; }
|
---|
| 42 | set {
|
---|
| 43 | base.Content = value;
|
---|
| 44 | }
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | public GaussianProcessRegressionSolutionEstimatedValuesView()
|
---|
| 48 | : base() {
|
---|
| 49 | InitializeComponent();
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | #region events
|
---|
| 53 | protected override void RegisterContentEvents() {
|
---|
| 54 | base.RegisterContentEvents();
|
---|
| 55 | Content.ModelChanged += new EventHandler(Content_ModelChanged);
|
---|
| 56 | Content.ProblemDataChanged += new EventHandler(Content_ProblemDataChanged);
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | protected override void DeregisterContentEvents() {
|
---|
| 60 | base.DeregisterContentEvents();
|
---|
| 61 | Content.ModelChanged -= new EventHandler(Content_ModelChanged);
|
---|
| 62 | Content.ProblemDataChanged -= new EventHandler(Content_ProblemDataChanged);
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | private void Content_ProblemDataChanged(object sender, EventArgs e) {
|
---|
| 66 | OnContentChanged();
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | private void Content_ModelChanged(object sender, EventArgs e) {
|
---|
| 70 | OnContentChanged();
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | protected override void OnContentChanged() {
|
---|
| 74 | base.OnContentChanged();
|
---|
| 75 | UpdateEstimatedValues();
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | private void UpdateEstimatedValues() {
|
---|
| 79 | if (InvokeRequired) Invoke((Action)UpdateEstimatedValues);
|
---|
| 80 | else {
|
---|
| 81 | StringMatrix matrix = null;
|
---|
| 82 | if (Content != null) {
|
---|
| 83 | string[,] values = new string[Content.ProblemData.Dataset.Rows, 9];
|
---|
| 84 |
|
---|
| 85 | var trainingRows = Content.ProblemData.TrainingIndices;
|
---|
| 86 | var testRows = Content.ProblemData.TestIndices;
|
---|
| 87 |
|
---|
| 88 | double[] target = Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable).ToArray();
|
---|
| 89 | var estimated = Content.EstimatedValues.GetEnumerator();
|
---|
| 90 | var estimated_training = Content.EstimatedTrainingValues.GetEnumerator();
|
---|
| 91 | var estimated_test = Content.EstimatedTestValues.GetEnumerator();
|
---|
| 92 | var estimated_var_training = Content.GetEstimatedVariance(trainingRows).GetEnumerator();
|
---|
| 93 | var estimated_var_test = Content.GetEstimatedVariance(testRows).GetEnumerator();
|
---|
| 94 |
|
---|
| 95 | foreach (var row in Content.ProblemData.TrainingIndices) {
|
---|
| 96 | estimated_training.MoveNext();
|
---|
| 97 | estimated_var_training.MoveNext();
|
---|
| 98 | values[row, 3] = estimated_training.Current.ToString();
|
---|
| 99 | values[row, 7] = estimated_var_training.Current.ToString();
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | foreach (var row in Content.ProblemData.TestIndices) {
|
---|
| 103 | estimated_test.MoveNext();
|
---|
| 104 | estimated_var_test.MoveNext();
|
---|
| 105 | values[row, 4] = estimated_test.Current.ToString();
|
---|
| 106 | values[row, 8] = estimated_var_test.Current.ToString();
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | foreach (var row in Enumerable.Range(0, Content.ProblemData.Dataset.Rows)) {
|
---|
| 110 | estimated.MoveNext();
|
---|
| 111 | double est = estimated.Current;
|
---|
| 112 | double res = Math.Abs(est - target[row]);
|
---|
| 113 | values[row, 0] = row.ToString();
|
---|
| 114 | values[row, 1] = target[row].ToString();
|
---|
| 115 | values[row, 2] = est.ToString();
|
---|
| 116 | values[row, 5] = Math.Abs(res).ToString();
|
---|
| 117 | values[row, 6] = Math.Abs(res / est).ToString();
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | matrix = new StringMatrix(values);
|
---|
| 121 | 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)", ESTIMATEDVARIANCE_TRAINING_SERIES_NAME, ESTIMATEDVARIANCE_TEST_SERIES_NAME };
|
---|
| 122 | matrix.SortableView = true;
|
---|
| 123 | }
|
---|
| 124 | matrixView.Content = matrix;
|
---|
| 125 | }
|
---|
| 126 | }
|
---|
| 127 | #endregion
|
---|
| 128 | }
|
---|
| 129 | }
|
---|