[4401] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 | using System;
|
---|
| 22 | using System.Linq;
|
---|
| 23 | using System.Windows.Forms;
|
---|
| 24 | using HeuristicLab.Data;
|
---|
| 25 | using HeuristicLab.Data.Views;
|
---|
| 26 | using HeuristicLab.MainForm;
|
---|
| 27 | using HeuristicLab.MainForm.WindowsForms;
|
---|
| 28 | using System.Collections.Generic;
|
---|
| 29 |
|
---|
| 30 | namespace HeuristicLab.Problems.DataAnalysis.MultiVariate.Views {
|
---|
| 31 | [View("Estimated Values View")]
|
---|
| 32 | [Content(typeof(IMultiVariateDataAnalysisSolution))]
|
---|
| 33 | public partial class EstimatedValuesView : AsynchronousContentView {
|
---|
| 34 | private const string TARGETVARIABLE_SERIES_NAME = "TargetVariable";
|
---|
| 35 | private const string ESTIMATEDVALUES_SERIES_NAME = "EstimatedValues";
|
---|
| 36 |
|
---|
| 37 | public new IMultiVariateDataAnalysisSolution Content {
|
---|
| 38 | get { return (IMultiVariateDataAnalysisSolution)base.Content; }
|
---|
| 39 | set {
|
---|
| 40 | base.Content = value;
|
---|
| 41 | }
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | private StringConvertibleMatrixView matrixView;
|
---|
| 45 |
|
---|
| 46 | public EstimatedValuesView()
|
---|
| 47 | : base() {
|
---|
| 48 | InitializeComponent();
|
---|
| 49 | matrixView = new StringConvertibleMatrixView();
|
---|
| 50 | matrixView.Dock = DockStyle.Fill;
|
---|
| 51 | this.Controls.Add(matrixView);
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | #region events
|
---|
| 55 | protected override void RegisterContentEvents() {
|
---|
| 56 | base.RegisterContentEvents();
|
---|
| 57 | Content.ProblemDataChanged += new EventHandler(Content_ProblemDataChanged);
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | protected override void DeregisterContentEvents() {
|
---|
| 61 | base.DeregisterContentEvents();
|
---|
| 62 | Content.ProblemDataChanged -= new EventHandler(Content_ProblemDataChanged);
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | void Content_ProblemDataChanged(object sender, EventArgs e) {
|
---|
| 66 | OnContentChanged();
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | protected override void OnContentChanged() {
|
---|
| 70 | base.OnContentChanged();
|
---|
| 71 | UpdateEstimatedValues();
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | private void UpdateEstimatedValues() {
|
---|
| 75 | if (InvokeRequired) Invoke((Action)UpdateEstimatedValues);
|
---|
| 76 | else {
|
---|
| 77 | DoubleMatrix matrix = null;
|
---|
| 78 | if (Content != null) {
|
---|
| 79 | IEnumerable<string> targetVariables = Content.ProblemData.TargetVariables.CheckedItems.Select(x => x.Value.Value);
|
---|
| 80 | List<double[]> estimatedValues = Content.EstimatedValues.ToList();
|
---|
| 81 | double[,] values = new double[estimatedValues.Count, targetVariables.Count() * 2];
|
---|
| 82 | for (int row = 0; row < estimatedValues.Count; row++) {
|
---|
| 83 | int col = 0;
|
---|
| 84 | foreach (string targetVariable in targetVariables) {
|
---|
| 85 | values[row, col++] = Content.ProblemData.Dataset[targetVariable, row];
|
---|
| 86 | values[row, col++] = estimatedValues[row][(col - 1) / 2];
|
---|
| 87 | }
|
---|
| 88 | }
|
---|
| 89 | matrix = new DoubleMatrix(values);
|
---|
| 90 | string[] partitions = new string[] { "(original)", "(estimated)" };
|
---|
| 91 | matrix.ColumnNames = from targetVariable in targetVariables
|
---|
| 92 | from partition in partitions
|
---|
| 93 | select targetVariable + " " + partition;
|
---|
| 94 | ;
|
---|
| 95 | }
|
---|
| 96 | matrixView.Content = matrix;
|
---|
| 97 | }
|
---|
| 98 | }
|
---|
| 99 | #endregion
|
---|
| 100 | }
|
---|
| 101 | }
|
---|