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 | using System;
|
---|
22 | using System.Collections.Generic;
|
---|
23 | using System.Linq;
|
---|
24 | using System.Windows.Forms;
|
---|
25 | using HeuristicLab.Data;
|
---|
26 | using HeuristicLab.Data.Views;
|
---|
27 | using HeuristicLab.MainForm;
|
---|
28 | using HeuristicLab.MainForm.WindowsForms;
|
---|
29 |
|
---|
30 | namespace HeuristicLab.Problems.DataAnalysis.Views {
|
---|
31 | [View("Estimated Values")]
|
---|
32 | [Content(typeof(ITimeSeriesPrognosisSolution))]
|
---|
33 | public partial class TimeSeriesPrognosisSolutionEstimatedValuesView : DataAnalysisSolutionEvaluationView {
|
---|
34 | private const string TARGETVARIABLE_SERIES_NAME = "Target Variable";
|
---|
35 | private const string PROGNOSEDVALUES_TRAINING_SERIES_NAME = "Prognosed Values (training)";
|
---|
36 | private const string PROGNOSEDVALUES_TEST_SERIES_NAME = "Prognosed Values (test)";
|
---|
37 |
|
---|
38 | public new ITimeSeriesPrognosisSolution Content {
|
---|
39 | get { return (ITimeSeriesPrognosisSolution)base.Content; }
|
---|
40 | set {
|
---|
41 | base.Content = value;
|
---|
42 | }
|
---|
43 | }
|
---|
44 |
|
---|
45 | private StringConvertibleMatrixView matrixView;
|
---|
46 |
|
---|
47 | public TimeSeriesPrognosisSolutionEstimatedValuesView()
|
---|
48 | : base() {
|
---|
49 | InitializeComponent();
|
---|
50 | matrixView = new StringConvertibleMatrixView();
|
---|
51 | matrixView.ShowRowsAndColumnsTextBox = false;
|
---|
52 | matrixView.ShowStatisticalInformation = false;
|
---|
53 | matrixView.Dock = DockStyle.Fill;
|
---|
54 | this.Controls.Add(matrixView);
|
---|
55 | }
|
---|
56 |
|
---|
57 | #region events
|
---|
58 | protected override void RegisterContentEvents() {
|
---|
59 | base.RegisterContentEvents();
|
---|
60 | Content.ModelChanged += new EventHandler(Content_ModelChanged);
|
---|
61 | Content.ProblemDataChanged += new EventHandler(Content_ProblemDataChanged);
|
---|
62 | }
|
---|
63 |
|
---|
64 | protected override void DeregisterContentEvents() {
|
---|
65 | base.DeregisterContentEvents();
|
---|
66 | Content.ModelChanged -= new EventHandler(Content_ModelChanged);
|
---|
67 | Content.ProblemDataChanged -= new EventHandler(Content_ProblemDataChanged);
|
---|
68 | }
|
---|
69 |
|
---|
70 | private void Content_ProblemDataChanged(object sender, EventArgs e) {
|
---|
71 | OnContentChanged();
|
---|
72 | }
|
---|
73 |
|
---|
74 | private void Content_ModelChanged(object sender, EventArgs e) {
|
---|
75 | OnContentChanged();
|
---|
76 | }
|
---|
77 |
|
---|
78 | protected override void OnContentChanged() {
|
---|
79 | base.OnContentChanged();
|
---|
80 | UpdateEstimatedValues();
|
---|
81 | }
|
---|
82 |
|
---|
83 | private void UpdateEstimatedValues() {
|
---|
84 | if (InvokeRequired) Invoke((Action)UpdateEstimatedValues);
|
---|
85 | else {
|
---|
86 | StringMatrix matrix = null;
|
---|
87 | List<string> columnNames = new List<string>();
|
---|
88 | if (Content != null) {
|
---|
89 | columnNames.Add("Id");
|
---|
90 |
|
---|
91 | string[,] values = new string[Content.ProblemData.Dataset.Rows, 1 + 3 * Content.ProblemData.TargetVariables.Count()];
|
---|
92 | foreach (var row in Enumerable.Range(0, Content.ProblemData.Dataset.Rows))
|
---|
93 | values[row, 0] = row.ToString();
|
---|
94 |
|
---|
95 | var allPrognosedTraining = Content.PrognosedTrainingValues.SelectMany(x=>x).ToArray();
|
---|
96 | var allPrognosedTest = Content.PrognosedTestValues.SelectMany(x => x).ToArray();
|
---|
97 |
|
---|
98 | int i = 0;
|
---|
99 | int targetVariableIndex = 0;
|
---|
100 | foreach (var targetVariable in Content.ProblemData.TargetVariables) {
|
---|
101 | var prognosedTraining =
|
---|
102 | allPrognosedTraining.Skip(targetVariableIndex).TakeEvery(Content.ProblemData.TargetVariables.Count());
|
---|
103 | var prognosedTest =
|
---|
104 | allPrognosedTest.Skip(targetVariableIndex).TakeEvery(Content.ProblemData.TargetVariables.Count());
|
---|
105 |
|
---|
106 | double[] target = Content.ProblemData.Dataset.GetDoubleValues(targetVariable).ToArray();
|
---|
107 |
|
---|
108 | var prognosedTrainingEnumerator = prognosedTraining.GetEnumerator();
|
---|
109 | foreach (var row in Content.ProblemData.TrainingIndizes) {
|
---|
110 | prognosedTrainingEnumerator.MoveNext();
|
---|
111 | values[row, i + 2] = prognosedTrainingEnumerator.Current.ToString();
|
---|
112 | }
|
---|
113 |
|
---|
114 | var prognosedTestEnumerator = prognosedTest.GetEnumerator();
|
---|
115 | foreach (var row in Content.ProblemData.TestIndizes) {
|
---|
116 | prognosedTestEnumerator.MoveNext();
|
---|
117 | values[row, i + 3] = prognosedTestEnumerator.Current.ToString();
|
---|
118 | }
|
---|
119 |
|
---|
120 | foreach (var row in Enumerable.Range(0, Content.ProblemData.Dataset.Rows)) {
|
---|
121 | values[row, i + 1] = target[row].ToString();
|
---|
122 | }
|
---|
123 |
|
---|
124 | columnNames.AddRange(new string[] { targetVariable + "(actual)", targetVariable + "(training)", targetVariable + "(test)" });
|
---|
125 | i += 3;
|
---|
126 | targetVariableIndex++;
|
---|
127 | } // foreach
|
---|
128 |
|
---|
129 |
|
---|
130 | matrix = new StringMatrix(values);
|
---|
131 | matrix.ColumnNames = columnNames.ToArray();
|
---|
132 | matrix.SortableView = true;
|
---|
133 |
|
---|
134 | } // if
|
---|
135 | matrixView.Content = matrix;
|
---|
136 | }
|
---|
137 | }
|
---|
138 | #endregion
|
---|
139 | }
|
---|
140 | }
|
---|