Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionEnsembleSolutionModelWeightsView.cs @ 13705

Last change on this file since 13705 was 13705, checked in by mkommend, 8 years ago

#2590: Added view for ensemble weights.

File size: 4.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 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.Data;
27using HeuristicLab.MainForm;
28using HeuristicLab.MainForm.WindowsForms;
29
30namespace HeuristicLab.Problems.DataAnalysis.Views {
31  [View("Ensemble Solutions Weights")]
32  [Content(typeof(RegressionEnsembleSolution), false)]
33  internal sealed partial class RegressionEnsembleSolutionModelWeightsView : DataAnalysisSolutionEvaluationView {
34    public override System.Drawing.Image ViewImage {
35      get { return HeuristicLab.Common.Resources.VSImageLibrary.Properties; }
36    }
37
38    public RegressionEnsembleSolutionModelWeightsView() {
39      InitializeComponent();
40    }
41
42    public new RegressionEnsembleSolution Content {
43      get { return (RegressionEnsembleSolution)base.Content; }
44      set { base.Content = value; }
45    }
46
47    protected override void RegisterContentEvents() {
48      base.RegisterContentEvents();
49      Content.Model.Changed += Content_ModelChanged;
50    }
51    private void RegisterArrayEvents(DoubleArray array) {
52      array.ItemChanged += DoubleArray_Changed;
53    }
54
55    protected override void DeregisterContentEvents() {
56      Content.Model.Changed -= Content_ModelChanged;
57      base.DeregisterContentEvents();
58    }
59    private void DeregisterArrayEvents(DoubleArray array) {
60      array.ItemChanged -= DoubleArray_Changed;
61    }
62
63    protected override void OnContentChanged() {
64      base.OnContentChanged();
65      if (Content != null) {
66        if (arrayView.Content != null) DeregisterArrayEvents((DoubleArray)arrayView.Content);
67        var array = new DoubleArray(Content.Model.ModelWeights.ToArray());
68        array.Resizable = false;
69        array.ElementNames = Content.Model.Models.Select(m => m.Name);
70
71        RegisterArrayEvents(array);
72
73        arrayView.Content = array;
74        arrayView.Locked = Content.ProblemData == RegressionEnsembleProblemData.EmptyProblemData;
75        averageEstimatesCheckBox.Checked = Content.Model.AverageModelEstimates;
76      } else {
77        arrayView.Content = null;
78        averageEstimatesCheckBox.Checked = false;
79      }
80    }
81
82    private void Content_ModelChanged(object sender, EventArgs eventArgs) {
83      var array = (DoubleArray)arrayView.Content;
84      var modelWeights = Content.Model.ModelWeights.ToList();
85
86      if (array.Length != modelWeights.Count) {
87        DeregisterArrayEvents(array);
88        array = new DoubleArray(Content.Model.ModelWeights.ToArray());
89        array.Resizable = false;
90        RegisterArrayEvents(array);
91      }
92
93      for (int i = 0; i < modelWeights.Count; i++)
94        array[i] = modelWeights[i];
95
96      array.ElementNames = Content.Model.Models.Select(m => m.Name);
97      averageEstimatesCheckBox.Checked = Content.Model.AverageModelEstimates;
98    }
99
100    private void DoubleArray_Changed(object sender, EventArgs<int> eventArgs) {
101      var array = (DoubleArray)arrayView.Content;
102      var index = eventArgs.Value;
103      var newWeight = array[index];
104      var model = Content.Model.Models.ElementAt(index);
105
106      Content.Model.SetModelWeight(model, newWeight);
107    }
108
109    private void averageEstimatesCheckBox_CheckedChanged(object sender, EventArgs e) {
110      Content.Model.AverageModelEstimates = averageEstimatesCheckBox.Checked;
111    }
112  }
113}
Note: See TracBrowser for help on using the repository browser.