Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.Algorithms.DataAnalysis.Views/3.4/GradientBoostedTreesModelView.cs @ 17690

Last change on this file since 17690 was 17180, checked in by swagner, 5 years ago

#2875: Removed years in copyrights

File size: 3.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 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;
23using System.Linq;
24using System.Windows.Forms;
25using HeuristicLab.Common;
26using HeuristicLab.Core.Views;
27using HeuristicLab.MainForm;
28using HeuristicLab.MainForm.WindowsForms;
29using HeuristicLab.Problems.DataAnalysis;
30
31namespace HeuristicLab.Algorithms.DataAnalysis.Views {
32  [View("Gradient boosted trees model")]
33  [Content(typeof(IGradientBoostedTreesModel), true)]
34  public partial class GradientBoostedTreesModelView : ItemView {
35    #region Getter/Setter
36    public new IGradientBoostedTreesModel Content {
37      get { return (IGradientBoostedTreesModel)base.Content; }
38      set { base.Content = value; }
39    }
40    #endregion
41
42    #region Ctor
43    public GradientBoostedTreesModelView()
44      : base() {
45      InitializeComponent();
46    }
47    #endregion
48
49    #region Events
50    protected override void SetEnabledStateOfControls() {
51      base.SetEnabledStateOfControls();
52      listView.Enabled = Content != null;
53      viewHost.Enabled = Content != null;
54    }
55
56    protected override void OnContentChanged() {
57      base.OnContentChanged();
58      if (Content == null) {
59        viewHost.Content = null;
60        listView.Items.Clear();
61      } else {
62        viewHost.Content = null;
63        listView.BeginUpdate();
64        listView.Items.Clear();
65        int i = 1;
66        listView.Items.AddRange(
67          new ListViewItem(Content.Models.First().ToString()) { Tag = Content.Models.First() }.ToEnumerable()
68          .Union(Content.Models.Skip(1).Select(v => new ListViewItem("Model " + i++) { Tag = v }))
69          .ToArray()
70        );
71        listView.EndUpdate();
72      }
73    }
74
75
76    private void listView_SelectedIndexChanged(object sender, EventArgs e) {
77      if (listView.SelectedItems.Count == 1) {
78        var item = listView.SelectedItems[0];
79        viewHost.Content = ConvertModel(item);
80      }
81    }
82
83    private void listView_DoubleClick(object sender, EventArgs e) {
84      if (listView.SelectedItems.Count == 1) {
85        var item = listView.SelectedItems[0];
86        var content = ConvertModel(item);
87        if (content != null) { MainFormManager.MainForm.ShowContent(content); }
88      }
89    }
90    #endregion
91
92    #region Helper Methods
93    private IContent ConvertModel(ListViewItem item) {
94      if (item.Tag is RegressionTreeModel) {
95        return (item.Tag as RegressionTreeModel).CreateSymbolicRegressionModel();
96      } else if (item.Tag is IRegressionModel) {
97        return item.Tag as IRegressionModel;
98      } else {
99        return null;
100      }
101    }
102    #endregion
103  }
104}
Note: See TracBrowser for help on using the repository browser.