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 | using System.Collections.Generic;
|
---|
29 | using HeuristicLab.Problems.DataAnalysis.MultiVariate.TimeSeriesPrognosis.Symbolic;
|
---|
30 |
|
---|
31 | namespace HeuristicLab.Problems.DataAnalysis.MultiVariate.TimeSeriesPrognosis.Views {
|
---|
32 | [View("Prognosis View")]
|
---|
33 | [Content(typeof(SymbolicTimeSeriesPrognosisSolution))]
|
---|
34 | public partial class PrognosisView : AsynchronousContentView {
|
---|
35 | private const string TARGETVARIABLE_SERIES_NAME = "TargetVariable";
|
---|
36 | private const string ESTIMATEDVALUES_SERIES_NAME = "EstimatedValues";
|
---|
37 | private int currentTimePoint;
|
---|
38 | public new SymbolicTimeSeriesPrognosisSolution Content {
|
---|
39 | get { return (SymbolicTimeSeriesPrognosisSolution)base.Content; }
|
---|
40 | set {
|
---|
41 | base.Content = value;
|
---|
42 | }
|
---|
43 | }
|
---|
44 |
|
---|
45 | public PrognosisView()
|
---|
46 | : base() {
|
---|
47 | InitializeComponent();
|
---|
48 | }
|
---|
49 |
|
---|
50 | #region events
|
---|
51 | protected override void RegisterContentEvents() {
|
---|
52 | base.RegisterContentEvents();
|
---|
53 | Content.ProblemDataChanged += new EventHandler(Content_ProblemDataChanged);
|
---|
54 | }
|
---|
55 |
|
---|
56 | protected override void DeregisterContentEvents() {
|
---|
57 | base.DeregisterContentEvents();
|
---|
58 | Content.ProblemDataChanged -= new EventHandler(Content_ProblemDataChanged);
|
---|
59 | }
|
---|
60 |
|
---|
61 | void Content_ProblemDataChanged(object sender, EventArgs e) {
|
---|
62 | OnContentChanged();
|
---|
63 | }
|
---|
64 |
|
---|
65 | protected override void OnContentChanged() {
|
---|
66 | base.OnContentChanged();
|
---|
67 | if (Content != null) {
|
---|
68 | UpdateRowIndexValue();
|
---|
69 | UpdateEstimatedValues();
|
---|
70 | }
|
---|
71 | }
|
---|
72 |
|
---|
73 |
|
---|
74 | private void UpdateEstimatedValues() {
|
---|
75 | if (InvokeRequired) Invoke((Action)UpdateEstimatedValues);
|
---|
76 | DoubleMatrix matrix = null;
|
---|
77 | if (Content != null) {
|
---|
78 | IEnumerable<string> targetVariables = Content.ProblemData.TargetVariables.CheckedItems.Select(x => x.Value.Value);
|
---|
79 | List<double[]> prognosis = Content.GetPrognosis(currentTimePoint).ToList();
|
---|
80 | double[,] values = new double[prognosis.Count, targetVariables.Count() * 2];
|
---|
81 | for (int row = 0; row < prognosis.Count; row++) {
|
---|
82 | int col = 0;
|
---|
83 | int t = currentTimePoint + row;
|
---|
84 | foreach (string targetVariable in targetVariables) {
|
---|
85 | values[row, col++] = t<Content.ProblemData.Dataset.Rows ? Content.ProblemData.Dataset[targetVariable, t] : double.NaN;
|
---|
86 | values[row, col++] = prognosis[row][(col - 1) / 2];
|
---|
87 | }
|
---|
88 | }
|
---|
89 | matrix = new DoubleMatrix(values);
|
---|
90 | string[] partitions = new string[] { "(original)", "(estimated)" };
|
---|
91 | matrix.ColumnNames = from targetVariable in targetVariables
|
---|
92 | from partition in partitions
|
---|
93 | select targetVariable + " " + partition;
|
---|
94 | ;
|
---|
95 | }
|
---|
96 | valuesView.Content = matrix;
|
---|
97 | }
|
---|
98 |
|
---|
99 | private void UpdateRowIndexValue() {
|
---|
100 | if(timePointValue.Content!=null)
|
---|
101 | timePointValue.Content.ValueChanged -= new EventHandler(Content_ValueChanged);
|
---|
102 | currentTimePoint = Content.ProblemData.TestSamplesStart.Value;
|
---|
103 | timePointValue.Content = new IntValue(currentTimePoint);
|
---|
104 | timePointValue.Locked = timePointValue.ReadOnly = false;
|
---|
105 | timePointValue.Content.ValueChanged += new EventHandler(Content_ValueChanged);
|
---|
106 | }
|
---|
107 |
|
---|
108 | void Content_ValueChanged(object sender, EventArgs e) {
|
---|
109 | currentTimePoint = int.Parse(timePointValue.Content.GetValue());
|
---|
110 | UpdateEstimatedValues();
|
---|
111 | }
|
---|
112 | #endregion
|
---|
113 | }
|
---|
114 | }
|
---|