[3442] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[7259] | 3 | * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[3442] | 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;
|
---|
[4068] | 24 | using HeuristicLab.Data;
|
---|
| 25 | using HeuristicLab.Data.Views;
|
---|
[3442] | 26 | using HeuristicLab.MainForm;
|
---|
| 27 | using HeuristicLab.MainForm.WindowsForms;
|
---|
| 28 |
|
---|
| 29 | namespace HeuristicLab.Problems.DataAnalysis.Views {
|
---|
[5975] | 30 | [View("Estimated Clusters")]
|
---|
[5853] | 31 | [Content(typeof(IClusteringSolution))]
|
---|
[6642] | 32 | public partial class ClusteringSolutionEstimatedClusterView : DataAnalysisSolutionEvaluationView {
|
---|
[5853] | 33 | private const string CLUSTER_NAMES = "Cluster";
|
---|
[3442] | 34 |
|
---|
[5853] | 35 | public new IClusteringSolution Content {
|
---|
| 36 | get { return (IClusteringSolution)base.Content; }
|
---|
[3442] | 37 | set {
|
---|
| 38 | base.Content = value;
|
---|
| 39 | }
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | private StringConvertibleMatrixView matrixView;
|
---|
| 43 |
|
---|
[5853] | 44 | public ClusteringSolutionEstimatedClusterView()
|
---|
[3442] | 45 | : base() {
|
---|
| 46 | InitializeComponent();
|
---|
| 47 | matrixView = new StringConvertibleMatrixView();
|
---|
[5014] | 48 | matrixView.ShowRowsAndColumnsTextBox = false;
|
---|
| 49 | matrixView.ShowStatisticalInformation = false;
|
---|
[3442] | 50 | matrixView.Dock = DockStyle.Fill;
|
---|
| 51 | this.Controls.Add(matrixView);
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | #region events
|
---|
| 55 | protected override void RegisterContentEvents() {
|
---|
| 56 | base.RegisterContentEvents();
|
---|
[5663] | 57 | Content.ModelChanged += new EventHandler(Content_ModelChanged);
|
---|
[3442] | 58 | Content.ProblemDataChanged += new EventHandler(Content_ProblemDataChanged);
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | protected override void DeregisterContentEvents() {
|
---|
| 62 | base.DeregisterContentEvents();
|
---|
[5663] | 63 | Content.ModelChanged -= new EventHandler(Content_ModelChanged);
|
---|
[3442] | 64 | Content.ProblemDataChanged -= new EventHandler(Content_ProblemDataChanged);
|
---|
| 65 | }
|
---|
| 66 |
|
---|
[5663] | 67 | private void Content_ProblemDataChanged(object sender, EventArgs e) {
|
---|
[3442] | 68 | OnContentChanged();
|
---|
| 69 | }
|
---|
| 70 |
|
---|
[5663] | 71 | private void Content_ModelChanged(object sender, EventArgs e) {
|
---|
[3442] | 72 | OnContentChanged();
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | protected override void OnContentChanged() {
|
---|
| 76 | base.OnContentChanged();
|
---|
[5853] | 77 | UpdateClusterValues();
|
---|
[3442] | 78 | }
|
---|
| 79 |
|
---|
[5853] | 80 | private void UpdateClusterValues() {
|
---|
| 81 | if (InvokeRequired) Invoke((Action)UpdateClusterValues);
|
---|
[3442] | 82 | else {
|
---|
[4011] | 83 | DoubleMatrix matrix = null;
|
---|
| 84 | if (Content != null) {
|
---|
[5853] | 85 | int[] clusters = Content.Model.GetClusterValues(Content.ProblemData.Dataset, Enumerable.Range(0, Content.ProblemData.Dataset.Rows)).ToArray();
|
---|
| 86 | var dataset = Content.ProblemData.Dataset;
|
---|
[6740] | 87 | int columns = Content.ProblemData.AllowedInputVariables.Count() + 1;
|
---|
[5014] | 88 |
|
---|
[5853] | 89 | double[,] values = new double[dataset.Rows, columns];
|
---|
| 90 | for (int row = 0; row < dataset.Rows; row++) {
|
---|
| 91 | values[row, 0] = clusters[row];
|
---|
| 92 |
|
---|
| 93 | int column = 1;
|
---|
[6740] | 94 | foreach (var columnName in Content.ProblemData.AllowedInputVariables) {
|
---|
| 95 | values[row, column] = dataset.GetDoubleValue(columnName, row);
|
---|
[5853] | 96 | column++;
|
---|
| 97 | }
|
---|
[5014] | 98 | }
|
---|
| 99 |
|
---|
[4011] | 100 | matrix = new DoubleMatrix(values);
|
---|
[6003] | 101 | var columnNames = Content.ProblemData.AllowedInputVariables.ToList();
|
---|
[5853] | 102 | columnNames.Insert(0, CLUSTER_NAMES);
|
---|
| 103 | matrix.ColumnNames = columnNames;
|
---|
[4011] | 104 | }
|
---|
| 105 | matrixView.Content = matrix;
|
---|
[3442] | 106 | }
|
---|
| 107 | }
|
---|
| 108 | #endregion
|
---|
| 109 | }
|
---|
| 110 | }
|
---|