[10686] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2014 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 |
|
---|
| 22 | using System;
|
---|
[10720] | 23 | using System.ComponentModel;
|
---|
[10686] | 24 | using System.Linq;
|
---|
| 25 | using System.Windows.Forms;
|
---|
| 26 | using HeuristicLab.Analysis;
|
---|
| 27 | using HeuristicLab.Core.Views;
|
---|
| 28 | using HeuristicLab.MainForm;
|
---|
| 29 | using HeuristicLab.Optimization;
|
---|
| 30 | using HeuristicLab.Optimization.Views;
|
---|
| 31 |
|
---|
| 32 | namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
|
---|
[10723] | 33 | [View("Sliding Window Best Solutions HeatMap Control")]
|
---|
[10686] | 34 | [Content(typeof(SlidingWindowBestSolutionsCollection), false)]
|
---|
[10722] | 35 | public partial class SlidingWindowBestSolutionsCollectionHeatMapControl : ItemView {
|
---|
[10686] | 36 | public new SlidingWindowBestSolutionsCollection Content {
|
---|
| 37 | get { return (SlidingWindowBestSolutionsCollection)base.Content; }
|
---|
| 38 | set { base.Content = value; }
|
---|
| 39 | }
|
---|
| 40 |
|
---|
[10720] | 41 | protected override void OnContentChanged() {
|
---|
| 42 | base.OnContentChanged();
|
---|
| 43 | if (Content != null) {
|
---|
[10721] | 44 | // set the dropdown value to the correct value
|
---|
| 45 | switch (Content.QualityMeasure) {
|
---|
| 46 | case SlidingWindowBestSolutionsCollection.QualityMeasures.PEARSON:
|
---|
| 47 | comboBox1.SelectedIndex = comboBox1.Items.IndexOf("Pearson R2");
|
---|
| 48 | break;
|
---|
| 49 | case SlidingWindowBestSolutionsCollection.QualityMeasures.MSE:
|
---|
| 50 | comboBox1.SelectedIndex = comboBox1.Items.IndexOf("Mean Squared Error");
|
---|
| 51 | break;
|
---|
| 52 | }
|
---|
[10720] | 53 | if (Content.SlidingWindowQualities != null) {
|
---|
| 54 | SetHeatmapContent(Content.SlidingWindowQualities);
|
---|
| 55 | } else if (!Content.QualitiesCalculationInProgress) {
|
---|
| 56 | Content.CalculateQualities();
|
---|
| 57 | }
|
---|
| 58 | }
|
---|
[10686] | 59 | }
|
---|
| 60 |
|
---|
[10720] | 61 | private readonly IProgress progress; // use this to show some progress when the sliding window qualities are calculated for each model
|
---|
[10686] | 62 |
|
---|
[10722] | 63 | public SlidingWindowBestSolutionsCollectionHeatMapControl() {
|
---|
[10720] | 64 | InitializeComponent();
|
---|
| 65 | progress = new Progress();
|
---|
| 66 | MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().AddOperationProgressToView(this, progress);
|
---|
| 67 | }
|
---|
[10686] | 68 |
|
---|
| 69 | protected override void DeregisterContentEvents() {
|
---|
| 70 | // TODO: Deregister your event handlers here
|
---|
[10720] | 71 | Content.QualitiesCalculationCompleted -= bestSolutionsCollectionQualitiesCalculated;
|
---|
| 72 | Content.QualitiesCalculationProgress -= bestSolutionCollectionQualitiesCalculationProgress;
|
---|
| 73 | Content.QualitiesUpdated -= bestSolutionCollectionQualitiesUpdated;
|
---|
[10721] | 74 | Content.QualitiesCalculationStarted -= bestSolutionsCollectionQualtiesCalculationStarted;
|
---|
[10686] | 75 | base.DeregisterContentEvents();
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | protected override void RegisterContentEvents() {
|
---|
| 79 | base.RegisterContentEvents();
|
---|
| 80 | // TODO: Register your event handlers here
|
---|
[10720] | 81 | Content.QualitiesCalculationCompleted += bestSolutionsCollectionQualitiesCalculated;
|
---|
| 82 | Content.QualitiesCalculationProgress += bestSolutionCollectionQualitiesCalculationProgress;
|
---|
| 83 | Content.QualitiesUpdated += bestSolutionCollectionQualitiesUpdated;
|
---|
[10721] | 84 | Content.QualitiesCalculationStarted += bestSolutionsCollectionQualtiesCalculationStarted;
|
---|
[10686] | 85 | }
|
---|
| 86 |
|
---|
[10720] | 87 | private void bestSolutionsCollectionQualitiesCalculated(object sender, RunWorkerCompletedEventArgs e) {
|
---|
| 88 | if (e.Cancelled || e.Error != null) {
|
---|
| 89 | progress.Cancel();
|
---|
| 90 | return;
|
---|
| 91 | }
|
---|
| 92 | SetHeatmapContent(Content.SlidingWindowQualities);
|
---|
| 93 | progress.Finish();
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | private void bestSolutionCollectionQualitiesUpdated(object sender, EventArgs e) {
|
---|
| 97 | SetHeatmapContent(Content.SlidingWindowQualities);
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | private void SetHeatmapContent(double[,] values) {
|
---|
| 101 | double min = 0, max = 0;
|
---|
[10721] | 102 | if (Content.QualityMeasure == SlidingWindowBestSolutionsCollection.QualityMeasures.PEARSON) {
|
---|
| 103 | max = 1.0;
|
---|
| 104 | } else {
|
---|
| 105 | foreach (var q in values) {
|
---|
| 106 | if (min > q) min = q;
|
---|
| 107 | if (max < q) max = q;
|
---|
| 108 | }
|
---|
[10720] | 109 | }
|
---|
[10723] | 110 |
|
---|
[10724] | 111 | heatMapView.Content = new HeatMap(values, "Best Sliding Window Solutions", min, max);
|
---|
[10720] | 112 | }
|
---|
| 113 |
|
---|
[10721] | 114 | private void bestSolutionsCollectionQualtiesCalculationStarted(object sender, EventArgs e) {
|
---|
| 115 | progress.Start("Calculating best solutions qualities...");
|
---|
| 116 | }
|
---|
| 117 |
|
---|
[10720] | 118 | private void bestSolutionCollectionQualitiesCalculationProgress(object sender, ProgressChangedEventArgs e) {
|
---|
| 119 | progress.ProgressValue = e.ProgressPercentage / 100.0;
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | protected override void SetEnabledStateOfControls() {
|
---|
| 123 | base.SetEnabledStateOfControls();
|
---|
| 124 | // TODO: Enable or disable controls based on whether the content is null or the view is set readonly
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | #region Event Handlers (child controls)
|
---|
[10686] | 128 | public void heatMapView_cellDoubleClick(object sender, DataGridViewCellEventArgs e) {
|
---|
| 129 | var dataGridView = (DataGridView)sender;
|
---|
| 130 | var cell = dataGridView.SelectedCells[0];
|
---|
[10720] | 131 | var bestSolutions = Content.SlidingWindowBestSolutions.Values.ToList();
|
---|
[10686] | 132 | var tree = bestSolutions[cell.RowIndex];
|
---|
| 133 | var model = Content.CreateModel(tree, Content.Interpreter);
|
---|
| 134 | var solution = Content.CreateSolution(model, Content.ProblemData);
|
---|
| 135 | var result = new Result("Sliding Window Solution", solution);
|
---|
| 136 | var view = MainFormManager.MainForm.ShowContent(result, typeof(ResultView));
|
---|
| 137 | if (view != null) {
|
---|
| 138 | view.ReadOnly = ReadOnly;
|
---|
| 139 | view.Locked = Locked;
|
---|
| 140 | }
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 | private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e) {
|
---|
| 144 | var combobox = (ComboBox)sender;
|
---|
| 145 | switch ((string)combobox.SelectedItem) {
|
---|
| 146 | case "Pearson R2": {
|
---|
[10720] | 147 | Content.QualityMeasure = SlidingWindowBestSolutionsCollection.QualityMeasures.PEARSON;
|
---|
[10686] | 148 | break;
|
---|
| 149 | }
|
---|
| 150 | case "Mean Squared Error": {
|
---|
[10720] | 151 | Content.QualityMeasure = SlidingWindowBestSolutionsCollection.QualityMeasures.MSE;
|
---|
[10686] | 152 | break;
|
---|
| 153 | }
|
---|
| 154 | }
|
---|
| 155 | }
|
---|
[10720] | 156 | #endregion
|
---|
[10686] | 157 | }
|
---|
| 158 | }
|
---|