#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 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 Statistics View")] public partial class RunCollectionValidationStatisticsView : AsynchronousContentView { private const string validationQualityResultName = "Best solution quality table"; private const string validationComplexityResultName = "Best solution complexity"; public RunCollectionValidationStatisticsView() { 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 = CalculateValidationStatisticsMatrix(); } private DoubleMatrix CalculateValidationStatisticsMatrix() { DoubleMatrix 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 attributes = new List() { "Best solution size", "Best solution height", "Best solution variables", "Training MSE", "Test MSE", "Training R²", "Test R²" }; List rowNames = (from run in runsWithSolutions select run.Name).ToList(); matrix = new DoubleMatrix(rowNames.Count, attributes.Count); matrix.SortableView = true; matrix.RowNames = rowNames; matrix.ColumnNames = attributes; for (int column = 0; column < attributes.Count; column++) { string attribute = attributes[column]; for (int row = 0; row < runsWithSolutions.Count; row++) { if (allComplexityTables[row].Rows.ContainsKey(attribute)) { matrix[row, column] = allComplexityTables[row].Rows[attribute].Values.Last(); } else if (allQualityTables[row].Rows.ContainsKey(attribute)) { matrix[row, column] = allQualityTables[row].Rows[attribute].Values.Last(); } } } } return matrix; } } }