[13705] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[14185] | 3 | * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[13705] | 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Linq;
|
---|
| 24 | using System.Windows.Forms;
|
---|
| 25 | using HeuristicLab.Common;
|
---|
| 26 | using HeuristicLab.Data;
|
---|
| 27 | using HeuristicLab.MainForm;
|
---|
| 28 | using HeuristicLab.MainForm.WindowsForms;
|
---|
| 29 |
|
---|
| 30 | namespace 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 |
|
---|
[13715] | 47 | protected override void SetEnabledStateOfControls() {
|
---|
| 48 | base.SetEnabledStateOfControls();
|
---|
| 49 | averageEstimatesCheckBox.Enabled = Content != null && !Locked && !ReadOnly;
|
---|
| 50 | }
|
---|
| 51 |
|
---|
[13705] | 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;
|
---|
[13711] | 74 | array.ElementNames = Content.RegressionSolutions.Select(s => s.Name);
|
---|
[13705] | 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 |
|
---|
[13711] | 101 | array.ElementNames = Content.RegressionSolutions.Select(s => s.Name);
|
---|
[13705] | 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) {
|
---|
[13711] | 115 | if (Content == null) return;
|
---|
[13705] | 116 | Content.Model.AverageModelEstimates = averageEstimatesCheckBox.Checked;
|
---|
| 117 | }
|
---|
| 118 | }
|
---|
| 119 | }
|
---|