Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataPreprocessing/HeuristicLab.Algorithms.DataAnalysis.Views/3.4/NcaDimensionReductionView.cs @ 10367

Last change on this file since 10367 was 9456, checked in by swagner, 12 years ago

Updated copyright year and added some missing license headers (#1889)

File size: 3.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 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
22using System.Collections.Generic;
23using System.Linq;
24using System.Windows.Forms;
25using HeuristicLab.Analysis;
26using HeuristicLab.Common;
27using HeuristicLab.MainForm;
28using HeuristicLab.MainForm.WindowsForms;
29using HeuristicLab.Problems.DataAnalysis.Views;
30
31namespace HeuristicLab.Algorithms.DataAnalysis.Views {
32  [View("Dimension Reduction")]
33  [Content(typeof(INcaClassificationSolution), IsDefaultView = false)]
34  public partial class NCADimensionReductionView : DataAnalysisSolutionEvaluationView {
35    private ViewHost viewHost = new ViewHost();
36    private ScatterPlot scatterPlot = new ScatterPlot();
37
38    public new INcaClassificationSolution Content {
39      get { return (INcaClassificationSolution)base.Content; }
40      set { base.Content = value; }
41    }
42
43    public NCADimensionReductionView() {
44      InitializeComponent();
45      messageLabel.Visible = false;
46      viewHost.Dock = DockStyle.Fill;
47      splitContainer.Panel2.Controls.Add(viewHost);
48      rangeComboBox.SelectedIndex = 0;
49    }
50
51    protected override void OnContentChanged() {
52      base.OnContentChanged();
53      if (Content == null) {
54        viewHost.Content = null;
55        scatterPlot.Rows.Clear();
56      } else {
57        UpdateScatterPlot();
58        viewHost.Content = scatterPlot;
59      }
60    }
61
62    private void UpdateScatterPlot() {
63      scatterPlot.Rows.Clear();
64      var rows = Content.ProblemData.ClassValues
65        .ToDictionary(c => c, c => new ScatterPlotDataRow(Content.ProblemData.GetClassName(c), string.Empty, Enumerable.Empty<Point2D<double>>()));
66      foreach (var r in rows.Values)
67        r.VisualProperties.PointSize = 5;
68
69      IEnumerable<int> range = null;
70      if (rangeComboBox.SelectedIndex == 0) range = Content.ProblemData.TrainingIndices;
71      else if (rangeComboBox.SelectedIndex == 1) range = Content.ProblemData.TestIndices;
72      else range = Enumerable.Range(0, Content.ProblemData.Dataset.Rows);
73
74      var reduced = Content.Model.Reduce(Content.ProblemData.Dataset, range);
75
76      int idx = 0;
77      if (reduced.GetLength(1) == 2) { // last column is the target variable
78        foreach (var r in range) {
79          var label = Content.ProblemData.Dataset.GetDoubleValue(Content.ProblemData.TargetVariable, r);
80          rows[label].Points.Add(new Point2D<double>(reduced[idx++, 0], 1.0));
81        }
82      } else {
83        foreach (var r in range) {
84          var label = Content.ProblemData.Dataset.GetDoubleValue(Content.ProblemData.TargetVariable, r);
85          rows[label].Points.Add(new Point2D<double>(reduced[idx, 0], reduced[idx, 1]));
86          idx++;
87        }
88      }
89      scatterPlot.Rows.AddRange(rows.Values);
90    }
91
92    protected override void SetEnabledStateOfControls() {
93      base.SetEnabledStateOfControls();
94      rangeComboBox.Enabled = Content != null && viewHost.Visible;
95    }
96
97    #region Event Handlers
98    private void rangeComboBox_SelectedIndexChanged(object sender, System.EventArgs e) {
99      if (Content != null) UpdateScatterPlot();
100    }
101    #endregion
102  }
103}
Note: See TracBrowser for help on using the repository browser.