#region License Information
/* HeuristicLab
* Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.Linq;
using System.Windows.Forms;
using HeuristicLab.Data;
using HeuristicLab.Data.Views;
using HeuristicLab.MainForm;
using HeuristicLab.MainForm.WindowsForms;
using System.Collections.Generic;
using HeuristicLab.Problems.DataAnalysis.MultiVariate.TimeSeriesPrognosis.Symbolic;
namespace HeuristicLab.Problems.DataAnalysis.MultiVariate.TimeSeriesPrognosis.Views {
[View("Prognosis View")]
[Content(typeof(SymbolicTimeSeriesPrognosisSolution))]
public partial class PrognosisView : AsynchronousContentView {
private const string TARGETVARIABLE_SERIES_NAME = "TargetVariable";
private const string ESTIMATEDVALUES_SERIES_NAME = "EstimatedValues";
private int currentTimePoint;
public new SymbolicTimeSeriesPrognosisSolution Content {
get { return (SymbolicTimeSeriesPrognosisSolution)base.Content; }
set {
base.Content = value;
}
}
public PrognosisView()
: base() {
InitializeComponent();
}
#region events
protected override void RegisterContentEvents() {
base.RegisterContentEvents();
Content.ProblemDataChanged += new EventHandler(Content_ProblemDataChanged);
}
protected override void DeregisterContentEvents() {
base.DeregisterContentEvents();
Content.ProblemDataChanged -= new EventHandler(Content_ProblemDataChanged);
}
void Content_ProblemDataChanged(object sender, EventArgs e) {
OnContentChanged();
}
protected override void OnContentChanged() {
base.OnContentChanged();
if (Content != null) {
UpdateRowIndexValue();
UpdateEstimatedValues();
}
}
private void UpdateEstimatedValues() {
if (InvokeRequired) Invoke((Action)UpdateEstimatedValues);
DoubleMatrix matrix = null;
if (Content != null) {
matrix = CalculateMatrix();
}
valuesView.Content = matrix;
}
public DoubleMatrix CalculateMatrix() {
DoubleMatrix matrix = null;
IEnumerable targetVariables = Content.ProblemData.TargetVariables.CheckedItems.Select(x => x.Value.Value);
List prognosis = Content.GetPrognosis(currentTimePoint).ToList();
double[,] values = new double[prognosis.Count, targetVariables.Count() * 2];
for (int row = 0; row < prognosis.Count; row++) {
int col = 0;
int t = currentTimePoint + row;
foreach (string targetVariable in targetVariables) {
values[row, col++] = t < Content.ProblemData.Dataset.Rows ? Content.ProblemData.Dataset[targetVariable, t] : double.NaN;
values[row, col++] = prognosis[row][(col - 1) / 2];
}
}
matrix = new DoubleMatrix(values);
string[] partitions = new string[] { "(original)", "(estimated)" };
matrix.ColumnNames = from targetVariable in targetVariables
from partition in partitions
select targetVariable + " " + partition;
;
return matrix;
}
private void UpdateRowIndexValue() {
if(timePointValue.Content!=null)
timePointValue.Content.ValueChanged -= new EventHandler(Content_ValueChanged);
currentTimePoint = Content.ProblemData.TestSamplesStart.Value;
timePointValue.Content = new IntValue(currentTimePoint);
timePointValue.Locked = timePointValue.ReadOnly = false;
timePointValue.Content.ValueChanged += new EventHandler(Content_ValueChanged);
}
void Content_ValueChanged(object sender, EventArgs e) {
currentTimePoint = int.Parse(timePointValue.Content.GetValue());
UpdateEstimatedValues();
}
#endregion
}
}