Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Views/3.4/TimeSeriesPrognosis/TimeSeriesPrognosisSolutionPrognosedValuesView.cs @ 8010

Last change on this file since 8010 was 8010, checked in by mkommend, 12 years ago

#1081: Corrected time series solution results and implemented new models.

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