#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.Collections.Generic; using System.Linq; using System.Windows.Forms; using alglib; using HeuristicLab.Common; using HeuristicLab.Data; using HeuristicLab.MainForm; using HeuristicLab.MainForm.WindowsForms; using HeuristicLab.Optimization; using System; using HeuristicLab.Problems.DataAnalysis.Regression.Symbolic; using HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols; using HeuristicLab.Problems.DataAnalysis.Evaluators; using HeuristicLab.Analysis; namespace HeuristicLab.Problems.DataAnalysis.Views { [Content(typeof(RunCollection), false)] [View("RunCollection Validation Trajectory View")] public partial class RunCollectionValidationTrajectoryView : AsynchronousContentView { private const string validationQualityResultName = "Best solution quality table"; private const string validationComplexityResultName = "Best solution complexity"; public RunCollectionValidationTrajectoryView() { InitializeComponent(); } public new RunCollection Content { get { return (RunCollection)base.Content; } set { base.Content = value; } } protected override void RegisterContentEvents() { base.RegisterContentEvents(); this.Content.ItemsAdded += new HeuristicLab.Collections.CollectionItemsChangedEventHandler(Content_ItemsAdded); this.Content.ItemsRemoved += new HeuristicLab.Collections.CollectionItemsChangedEventHandler(Content_ItemsRemoved); this.Content.CollectionReset += new HeuristicLab.Collections.CollectionItemsChangedEventHandler(Content_CollectionReset); } protected override void DeregisterContentEvents() { base.RegisterContentEvents(); this.Content.ItemsAdded -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler(Content_ItemsAdded); this.Content.ItemsRemoved -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler(Content_ItemsRemoved); this.Content.CollectionReset -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler(Content_CollectionReset); } protected override void OnContentChanged() { base.OnContentChanged(); this.UpdateData(); } private void Content_ItemsAdded(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs e) { this.UpdateData(); } private void Content_ItemsRemoved(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs e) { this.UpdateData(); } private void Content_CollectionReset(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs e) { this.UpdateData(); } private void UpdateData() { matrixView.Content = CalculateValidationStatisticsTable(); } private DataTable CalculateValidationStatisticsTable() { DataTable matrix = null; if (Content != null) { List runsWithSolutions = (from run in Content where run.Results.ContainsKey(validationComplexityResultName) where run.Results.ContainsKey(validationQualityResultName) select run) .ToList(); IList allComplexityTables = (from run in Content where run.Results.ContainsKey(validationComplexityResultName) select run.Results[validationComplexityResultName]) .Cast() .ToList(); IList allQualityTables = (from run in Content where run.Results.ContainsKey(validationQualityResultName) select run.Results[validationQualityResultName]) .Cast() .ToList(); List complexityAttributes = new List() { "Best solution size", "Best solution height", "Best solution variables", }; List qualityAttributes = new List() { "Training MSE", "Test MSE", "Training R²", "Test R²" }; matrix = new DataTable(); //matrix.RowNames = rowNames; //matrix.ColumnNames = attributes; for (int column = 0; column < complexityAttributes.Count; column++) { string attribute = complexityAttributes[column]; matrix.Rows.Add(GetSolutionLockedAverage(attribute, allComplexityTables)); } for (int column = 0; column < qualityAttributes.Count; column++) { string attribute = qualityAttributes[column]; matrix.Rows.Add(GetSolutionLockedAverage(attribute, allQualityTables)); } } return matrix; } private DataRow GetSolutionLockedAverage(string attribute, IList runTables) { DataRow dataRow = new DataRow(attribute); List> runLists = new List>(); int n = 0; foreach (DataTable dt in runTables) { List runList = new List(); runList.AddRange(dt.Rows[attribute].Values); runLists.Add(runList); if (n < runList.Count) { n = runList.Count; } } for (int row = n; row > 0; row--) { List values = new List(); foreach (List runList in runLists) { if (runList.Count >= row) { values.Add(runList[runList.Count - row]); } } dataRow.Values.Add(values.Median()); } return dataRow; } } }