#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.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Windows.Forms; using HeuristicLab.MainForm; using HeuristicLab.MainForm.WindowsForms; using HeuristicLab.Data.Views; using HeuristicLab.Data; using HeuristicLab.Problems.DataAnalysis.Evaluators; using HeuristicLab.Problems.DataAnalysis.VectorRegression; namespace HeuristicLab.Problems.DataAnalysis.VectorRegression.Views { [Content(typeof(IMultiTargetRegressionSolution), false)] [View("Multi-target Results View")] public partial class ResultsView : AsynchronousContentView { private List rowNames = new List() { "Mean squared error (training)", "Mean squared error (test)", "Pearson's R² (training)", "Pearson's R² (test)", "Mean relative error (training)", "Mean relative error (test)" }; public ResultsView() { InitializeComponent(); } public new IMultiTargetRegressionSolution Content { get { return (IMultiTargetRegressionSolution)base.Content; } set { base.Content = value; } } protected override void RegisterContentEvents() { base.RegisterContentEvents(); //Content.ModelChanged += new EventHandler(Content_ModelChanged); //Content.ProblemDataChanged += new EventHandler(Content_ProblemDataChanged); //Content.EstimatedValuesChanged += new EventHandler(Content_EstimatedValuesChanged); } protected override void DeregisterContentEvents() { base.DeregisterContentEvents(); //Content.ModelChanged -= new EventHandler(Content_ModelChanged); //Content.ProblemDataChanged -= new EventHandler(Content_ProblemDataChanged); //Content.EstimatedValuesChanged -= new EventHandler(Content_EstimatedValuesChanged); } private void Content_ModelChanged(object sender, EventArgs e) { UpdateView(); } private void Content_ProblemDataChanged(object sender, EventArgs e) { UpdateView(); } private void Content_EstimatedValuesChanged(object sender, EventArgs e) { UpdateView(); } protected override void OnContentChanged() { base.OnContentChanged(); UpdateView(); } private void UpdateView() { if (Content != null) { DoubleMatrix matrix = new DoubleMatrix(rowNames.Count, Content.TargetVariables.Count()); matrix.RowNames = rowNames; matrix.ColumnNames = Content.TargetVariables; matrix.SortableView = false; int columnIndex = 0; foreach (string targetVariable in Content.TargetVariables) { DataAnalysisSolution targetVariableSolution = Content.GetModelFor(targetVariable); IEnumerable originalTrainingValues = targetVariableSolution.ProblemData.Dataset.GetVariableValues(targetVariable, targetVariableSolution.ProblemData.TrainingSamplesStart.Value, targetVariableSolution.ProblemData.TrainingSamplesEnd.Value); IEnumerable originalTestValues = targetVariableSolution.ProblemData.Dataset.GetVariableValues(targetVariable, targetVariableSolution.ProblemData.TestSamplesStart.Value, targetVariableSolution.ProblemData.TestSamplesEnd.Value); matrix[0, columnIndex] = SimpleMSEEvaluator.Calculate(originalTrainingValues, targetVariableSolution.EstimatedTrainingValues); matrix[1, columnIndex] = SimpleMSEEvaluator.Calculate(originalTestValues, targetVariableSolution.EstimatedTestValues); matrix[2, columnIndex] = SimpleRSquaredEvaluator.Calculate(originalTrainingValues, targetVariableSolution.EstimatedTrainingValues); matrix[3, columnIndex] = SimpleRSquaredEvaluator.Calculate(originalTestValues, targetVariableSolution.EstimatedTestValues); matrix[4, columnIndex] = SimpleMeanAbsolutePercentageErrorEvaluator.Calculate(originalTrainingValues, targetVariableSolution.EstimatedTrainingValues); matrix[5, columnIndex] = SimpleMeanAbsolutePercentageErrorEvaluator.Calculate(originalTestValues, targetVariableSolution.EstimatedTestValues); columnIndex++; } matrixView.Content = matrix; } else matrixView.Content = null; } } }