#region License Information /* HeuristicLab * Copyright (C) 2002-2011 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.Collections.Generic; using System.Linq; using System.Windows.Forms; using HeuristicLab.Data; using HeuristicLab.Data.Views; using HeuristicLab.MainForm; using HeuristicLab.MainForm.WindowsForms; namespace HeuristicLab.Problems.DataAnalysis.Views { [View("Estimated Values")] [Content(typeof(ITimeSeriesPrognosisSolution))] public partial class TimeSeriesPrognosisSolutionEstimatedValuesView : DataAnalysisSolutionEvaluationView { private const string TARGETVARIABLE_SERIES_NAME = "Target Variable"; private const string PROGNOSEDVALUES_TRAINING_SERIES_NAME = "Prognosed Values (training)"; private const string PROGNOSEDVALUES_TEST_SERIES_NAME = "Prognosed Values (test)"; public new ITimeSeriesPrognosisSolution Content { get { return (ITimeSeriesPrognosisSolution)base.Content; } set { base.Content = value; } } private StringConvertibleMatrixView matrixView; public TimeSeriesPrognosisSolutionEstimatedValuesView() : base() { InitializeComponent(); matrixView = new StringConvertibleMatrixView(); matrixView.ShowRowsAndColumnsTextBox = false; matrixView.ShowStatisticalInformation = false; matrixView.Dock = DockStyle.Fill; this.Controls.Add(matrixView); } #region events protected override void RegisterContentEvents() { base.RegisterContentEvents(); Content.ModelChanged += new EventHandler(Content_ModelChanged); Content.ProblemDataChanged += new EventHandler(Content_ProblemDataChanged); } protected override void DeregisterContentEvents() { base.DeregisterContentEvents(); Content.ModelChanged -= new EventHandler(Content_ModelChanged); Content.ProblemDataChanged -= new EventHandler(Content_ProblemDataChanged); } private void Content_ProblemDataChanged(object sender, EventArgs e) { OnContentChanged(); } private void Content_ModelChanged(object sender, EventArgs e) { OnContentChanged(); } protected override void OnContentChanged() { base.OnContentChanged(); UpdateEstimatedValues(); } private void UpdateEstimatedValues() { if (InvokeRequired) Invoke((Action)UpdateEstimatedValues); else { StringMatrix matrix = null; List columnNames = new List(); if (Content != null) { columnNames.Add("Id"); string[,] values = new string[Content.ProblemData.Dataset.Rows, 1 + 3 * Content.ProblemData.TargetVariables.Count()]; foreach (var row in Enumerable.Range(0, Content.ProblemData.Dataset.Rows)) values[row, 0] = row.ToString(); var allPrognosedTraining = Content.PrognosedTrainingValues.SelectMany(x=>x).ToArray(); var allPrognosedTest = Content.PrognosedTestValues.SelectMany(x => x).ToArray(); int i = 0; int targetVariableIndex = 0; foreach (var targetVariable in Content.ProblemData.TargetVariables) { var prognosedTraining = allPrognosedTraining.Skip(targetVariableIndex).TakeEvery(Content.ProblemData.TargetVariables.Count()); var prognosedTest = allPrognosedTest.Skip(targetVariableIndex).TakeEvery(Content.ProblemData.TargetVariables.Count()); double[] target = Content.ProblemData.Dataset.GetDoubleValues(targetVariable).ToArray(); var prognosedTrainingEnumerator = prognosedTraining.GetEnumerator(); foreach (var row in Content.ProblemData.TrainingIndizes) { prognosedTrainingEnumerator.MoveNext(); values[row, i + 2] = prognosedTrainingEnumerator.Current.ToString(); } var prognosedTestEnumerator = prognosedTest.GetEnumerator(); foreach (var row in Content.ProblemData.TestIndizes) { prognosedTestEnumerator.MoveNext(); values[row, i + 3] = prognosedTestEnumerator.Current.ToString(); } foreach (var row in Enumerable.Range(0, Content.ProblemData.Dataset.Rows)) { values[row, i + 1] = target[row].ToString(); } columnNames.AddRange(new string[] { targetVariable + "(actual)", targetVariable + "(training)", targetVariable + "(test)" }); i += 3; targetVariableIndex++; } // foreach matrix = new StringMatrix(values); matrix.ColumnNames = columnNames.ToArray(); matrix.SortableView = true; } // if matrixView.Content = matrix; } } #endregion } }