#region License Information /* HeuristicLab * Copyright (C) 2002-2018 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 HeuristicLab.Analysis; using HeuristicLab.Analysis.Views; using HeuristicLab.Core.Views; using HeuristicLab.Data; using HeuristicLab.MainForm; using HeuristicLab.MainForm.WindowsForms; namespace HeuristicLab.Problems.DynamicalSystemsModelling { [View("Solution View")] [Content(typeof(Solution), true)] public sealed partial class SolutionView : ItemView { public new Solution Content { get { return (Solution)base.Content; } set { base.Content = value; } } public SolutionView() { InitializeComponent(); } protected override void OnContentChanged() { base.OnContentChanged(); if (Content == null) { episodeStartTextbox.Text = string.Empty; episodeEndTextbox.Text = string.Empty; } else { var episode = Content.TrainingEpisodes.First(); episodeStartTextbox.Text = episode.Start.ToString(); episodeEndTextbox.Text = episode.End.ToString(); } UpdatePredictions(); } private void UpdatePredictions() { tableLayoutPanel.Controls.Clear(); if (Content == null) return; tableLayoutPanel.RowCount = Content.Trees.Length; var targetVars = Content.TargetVariables; var calculatedVars = Content.TargetVariables.Concat(Content.LatentVariables).ToArray(); var ds = Content.ProblemData.Dataset; var predictionEpisode = new IntRange(int.Parse(episodeStartTextbox.Text), int.Parse(episodeEndTextbox.Text)); trackBar.Minimum = 0; trackBar.Maximum = ds.Rows; var forecastHorizon = 0; int.TryParse(forecastTextbox.Text, out forecastHorizon); // trackBar.Value = predictionEpisode.Start; double snmse; var predictions = Content.Predict(predictionEpisode, forecastHorizon).ToArray(); errorLabel.Text = $"SNMSE: {0.0:e4}"; var trainingPredictions = predictions.Take(predictionEpisode.Size).ToArray(); var forecastPredictions = predictions.Skip(predictionEpisode.Size).ToArray(); for (int i = 0; i < calculatedVars.Length; i++) { var varName = calculatedVars[i]; var tree = Content.Trees[i]; var dt = new DataTable(varName); var trainingPredValues = Enumerable.Repeat(double.NaN, predictionEpisode.Start) .Concat(trainingPredictions.Select(pi => pi[i])) .Concat(Enumerable.Repeat(double.NaN, ds.Rows - predictionEpisode.Start - trainingPredictions.Length)) .ToArray(); var predRow = new DataRow(varName + " (training)", varName + " (training)", trainingPredValues); dt.Rows.Add(predRow); if (targetVars.Contains(varName)) { var targetValues = ds.GetReadOnlyDoubleValues(varName); var targetRow = new DataRow(varName + " (target)", varName + " (target)", targetValues); dt.Rows.Add(targetRow); } if (ds.Rows - predictionEpisode.End - forecastPredictions.Length > 0) { var forecastPredValues = Enumerable.Repeat(double.NaN, predictionEpisode.End) .Concat(forecastPredictions.Select(pi => pi[i])) .Concat(Enumerable.Repeat(double.NaN, ds.Rows - predictionEpisode.End - forecastPredictions.Length)) .ToArray(); var forecastRow = new DataRow(varName + " (forecast)", varName + " (forecast)", forecastPredValues); dt.Rows.Add(forecastRow); } var vizProp = new DataTableVisualProperties(); dt.VisualProperties = vizProp; var dtv = new DataTableView(); dtv.Content = dt; dtv.ShowChartOnly = true; dtv.Dock = System.Windows.Forms.DockStyle.Fill; tableLayoutPanel.Controls.Add(dtv, 0, i); } } protected override void OnLockedChanged() { base.OnLockedChanged(); } private void updateButton_Click(object sender, System.EventArgs e) { UpdatePredictions(); } private void trackBar_Validated(object sender, EventArgs e) { var start = int.Parse(episodeStartTextbox.Text); if (start == trackBar.Value) return; var end = int.Parse(episodeEndTextbox.Text); var delta = end - start; episodeStartTextbox.Text = (trackBar.Value).ToString(); episodeEndTextbox.Text = (trackBar.Value + delta).ToString(); } private void episodeStartTextbox_Validating(object sender, System.ComponentModel.CancelEventArgs e) { int res; e.Cancel = !int.TryParse(episodeStartTextbox.Text, out res); } private void episodeStartTextbox_Validated(object sender, EventArgs e) { trackBar.Value = int.Parse(episodeStartTextbox.Text); } } }