Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HiveHiveEngine/HeuristicLab.Problems.DataAnalysis.Views/3.4/Clustering/ClusteringSolutionEstimatedClusterView.cs @ 12009

Last change on this file since 12009 was 7259, checked in by swagner, 13 years ago

Updated year of copyrights to 2012 (#1716)

File size: 3.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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
21using System;
22using System.Linq;
23using System.Windows.Forms;
24using HeuristicLab.Data;
25using HeuristicLab.Data.Views;
26using HeuristicLab.MainForm;
27using HeuristicLab.MainForm.WindowsForms;
28
29namespace 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
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;
94            foreach (var columnName in Content.ProblemData.AllowedInputVariables) {
95              values[row, column] = dataset.GetDoubleValue(columnName, row);
96              column++;
97            }
98          }
99
100          matrix = new DoubleMatrix(values);
101          var columnNames = Content.ProblemData.AllowedInputVariables.ToList();
102          columnNames.Insert(0, CLUSTER_NAMES);
103          matrix.ColumnNames = columnNames;
104        }
105        matrixView.Content = matrix;
106      }
107    }
108    #endregion
109  }
110}
Note: See TracBrowser for help on using the repository browser.