Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2389-EpsLexicase/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionEnsembleSolutionModelWeightsView.cs @ 16375

Last change on this file since 16375 was 15583, checked in by swagner, 7 years ago

#2640: Updated year of copyrights in license headers

File size: 4.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2018 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 SetEnabledStateOfControls() {
48      base.SetEnabledStateOfControls();
49      averageEstimatesCheckBox.Enabled = Content != null && !Locked && !ReadOnly;
50    }
51
52    protected override void RegisterContentEvents() {
53      base.RegisterContentEvents();
54      Content.Model.Changed += Content_ModelChanged;
55    }
56    private void RegisterArrayEvents(DoubleArray array) {
57      array.ItemChanged += DoubleArray_Changed;
58    }
59
60    protected override void DeregisterContentEvents() {
61      Content.Model.Changed -= Content_ModelChanged;
62      base.DeregisterContentEvents();
63    }
64    private void DeregisterArrayEvents(DoubleArray array) {
65      array.ItemChanged -= DoubleArray_Changed;
66    }
67
68    protected override void OnContentChanged() {
69      base.OnContentChanged();
70      if (Content != null) {
71        if (arrayView.Content != null) DeregisterArrayEvents((DoubleArray)arrayView.Content);
72        var array = new DoubleArray(Content.Model.ModelWeights.ToArray());
73        array.Resizable = false;
74        array.ElementNames = Content.RegressionSolutions.Select(s => s.Name);
75
76        RegisterArrayEvents(array);
77
78        arrayView.Content = array;
79        arrayView.Locked = Content.ProblemData == RegressionEnsembleProblemData.EmptyProblemData;
80        averageEstimatesCheckBox.Checked = Content.Model.AverageModelEstimates;
81      } else {
82        arrayView.Content = null;
83        averageEstimatesCheckBox.Checked = false;
84      }
85    }
86
87    private void Content_ModelChanged(object sender, EventArgs eventArgs) {
88      var array = (DoubleArray)arrayView.Content;
89      var modelWeights = Content.Model.ModelWeights.ToList();
90
91      if (array.Length != modelWeights.Count) {
92        DeregisterArrayEvents(array);
93        array = new DoubleArray(Content.Model.ModelWeights.ToArray());
94        array.Resizable = false;
95        RegisterArrayEvents(array);
96      }
97
98      for (int i = 0; i < modelWeights.Count; i++)
99        array[i] = modelWeights[i];
100
101      array.ElementNames = Content.RegressionSolutions.Select(s => s.Name);
102      averageEstimatesCheckBox.Checked = Content.Model.AverageModelEstimates;
103    }
104
105    private void DoubleArray_Changed(object sender, EventArgs<int> eventArgs) {
106      var array = (DoubleArray)arrayView.Content;
107      var index = eventArgs.Value;
108      var newWeight = array[index];
109      var model = Content.Model.Models.ElementAt(index);
110
111      Content.Model.SetModelWeight(model, newWeight);
112    }
113
114    private void averageEstimatesCheckBox_CheckedChanged(object sender, EventArgs e) {
115      if (Content == null) return;
116      Content.Model.AverageModelEstimates = averageEstimatesCheckBox.Checked;
117    }
118  }
119}
Note: See TracBrowser for help on using the repository browser.