Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 15103 was 15103, checked in by gkronber, 7 years ago

#2690 added event-handler for double click events to open the clicked model in a new view

File size: 3.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 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.Drawing;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.MainForm;
26using HeuristicLab.Problems.DataAnalysis;
27using HeuristicLab.Problems.DataAnalysis.Views;
28
29namespace HeuristicLab.Algorithms.DataAnalysis.Views {
30  [View("Gradient boosted tree model")]
31  [Content(typeof(GradientBoostedTreesSolution), false)]
32  public partial class GradientBoostedTreesModelView : DataAnalysisSolutionEvaluationView {
33    public override Image ViewImage {
34      get { return HeuristicLab.Common.Resources.VSImageLibrary.Function; }
35    }
36
37    public new GradientBoostedTreesSolution Content {
38      get { return (GradientBoostedTreesSolution)base.Content; }
39      set { base.Content = value; }
40    }
41
42    protected override void SetEnabledStateOfControls() {
43      base.SetEnabledStateOfControls();
44      listBox.Enabled = Content != null;
45      viewHost.Enabled = Content != null;
46    }
47
48    public GradientBoostedTreesModelView()
49      : base() {
50      InitializeComponent();
51    }
52
53    protected override void OnContentChanged() {
54      base.OnContentChanged();
55      if (Content == null) {
56        viewHost.Content = null;
57        listBox.Items.Clear();
58      } else {
59        viewHost.Content = null;
60        listBox.Items.Clear();
61        foreach (var e in Content.Model.Models) {
62          listBox.Items.Add(e);
63        }
64      }
65    }
66
67    private void listBox_SelectedIndexChanged(object sender, System.EventArgs e) {
68      var model = listBox.SelectedItem;
69      if (model == null) viewHost.Content = null;
70      else {
71        viewHost.Content = ConvertModel(model);
72      }
73    }
74
75    private void listBox_DoubleClick(object sender, System.EventArgs e) {
76      var selectedItem = listBox.SelectedItem;
77      if (selectedItem == null) return;
78      MainFormManager.MainForm.ShowContent(ConvertModel(selectedItem));
79    }
80
81    private IContent ConvertModel(object model) {
82      var treeModel = model as RegressionTreeModel;
83      if (treeModel != null)
84        return treeModel.CreateSymbolicRegressionSolution(Content.ProblemData);
85      else {
86        var regModel = model as IRegressionModel;
87        return regModel;
88      }
89    }
90  }
91}
Note: See TracBrowser for help on using the repository browser.