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