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