[10402] | 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;
|
---|
[10396] | 23 | using System.Collections.Generic;
|
---|
[10720] | 24 | using System.ComponentModel;
|
---|
[10396] | 25 | using System.Linq;
|
---|
| 26 | using System.Windows.Forms;
|
---|
| 27 | using HeuristicLab.Core.Views;
|
---|
| 28 | using HeuristicLab.Data;
|
---|
| 29 | using HeuristicLab.MainForm;
|
---|
| 30 | using HeuristicLab.Optimization;
|
---|
| 31 | using HeuristicLab.Optimization.Views;
|
---|
| 32 |
|
---|
| 33 | namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
|
---|
| 34 | [View("Sliding Window Best Solutions View")]
|
---|
| 35 | [Content(typeof(SlidingWindowBestSolutionsCollection), true)]
|
---|
| 36 | public partial class SlidingWindowBestSolutionsCollectionView : ItemView {
|
---|
| 37 | public new SlidingWindowBestSolutionsCollection Content {
|
---|
| 38 | get { return (SlidingWindowBestSolutionsCollection)base.Content; }
|
---|
| 39 | set { base.Content = value; }
|
---|
| 40 | }
|
---|
| 41 |
|
---|
[10720] | 42 | protected override void OnContentChanged() {
|
---|
| 43 | base.OnContentChanged();
|
---|
| 44 | if (Content != null) {
|
---|
[10721] | 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 | SetMatrixContent(Content.SlidingWindowQualities);
|
---|
| 55 | } else if (!Content.QualitiesCalculationInProgress) {
|
---|
| 56 | Content.CalculateQualities();
|
---|
| 57 | }
|
---|
| 58 | }
|
---|
[10396] | 59 | }
|
---|
| 60 |
|
---|
[10720] | 61 | private readonly Progress progress;
|
---|
[10396] | 62 |
|
---|
| 63 | protected override void DeregisterContentEvents() {
|
---|
| 64 | // TODO: Deregister your event handlers here
|
---|
| 65 | enhancedStringConvertibleMatrixView.DataGridView.CellDoubleClick -= enhancedStringConvertibleMatrixView_cellDoubleClick;
|
---|
[10720] | 66 | Content.QualitiesCalculationCompleted -= bestSolutionsCollectionQualitiesCalculated;
|
---|
| 67 | Content.QualitiesCalculationProgress -= bestSolutionCollectionQualitiesCalculationProgress;
|
---|
| 68 | Content.QualitiesUpdated -= bestSolutionCollectionQualitiesUpdated;
|
---|
[10721] | 69 | Content.QualitiesCalculationStarted -= bestSolutionsCollectionQualtiesCalculationStarted;
|
---|
[10396] | 70 | base.DeregisterContentEvents();
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | protected override void RegisterContentEvents() {
|
---|
| 74 | base.RegisterContentEvents();
|
---|
[10720] | 75 | // TODO: Register your event handlers here
|
---|
[10396] | 76 | enhancedStringConvertibleMatrixView.DataGridView.CellDoubleClick += enhancedStringConvertibleMatrixView_cellDoubleClick;
|
---|
[10720] | 77 | Content.QualitiesCalculationCompleted += bestSolutionsCollectionQualitiesCalculated;
|
---|
| 78 | Content.QualitiesCalculationProgress += bestSolutionCollectionQualitiesCalculationProgress;
|
---|
| 79 | Content.QualitiesUpdated += bestSolutionCollectionQualitiesUpdated;
|
---|
[10721] | 80 | Content.QualitiesCalculationStarted += bestSolutionsCollectionQualtiesCalculationStarted;
|
---|
[10396] | 81 | }
|
---|
| 82 |
|
---|
[10720] | 83 | public SlidingWindowBestSolutionsCollectionView() {
|
---|
| 84 | InitializeComponent();
|
---|
| 85 | progress = new Progress();
|
---|
| 86 | MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().AddOperationProgressToView(this, progress);
|
---|
[10396] | 87 | }
|
---|
| 88 |
|
---|
| 89 | #region Event Handlers (Content)
|
---|
[10721] | 90 | private void bestSolutionsCollectionQualtiesCalculationStarted(object sender, EventArgs e) {
|
---|
| 91 | progress.Start("Calculating best solutions qualities...");
|
---|
| 92 | }
|
---|
| 93 |
|
---|
[10720] | 94 | private void bestSolutionsCollectionQualitiesCalculated(object sender, RunWorkerCompletedEventArgs e) {
|
---|
| 95 | if (e.Cancelled || e.Error != null) {
|
---|
| 96 | progress.Cancel();
|
---|
| 97 | return;
|
---|
| 98 | }
|
---|
[10396] | 99 |
|
---|
[10720] | 100 | SetMatrixContent(Content.SlidingWindowQualities);
|
---|
| 101 | progress.Finish();
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | private void bestSolutionCollectionQualitiesCalculationProgress(object sender, ProgressChangedEventArgs e) {
|
---|
| 105 | progress.ProgressValue = e.ProgressPercentage / 100.0;
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | private void bestSolutionCollectionQualitiesUpdated(object sender, EventArgs e) {
|
---|
| 109 | SetMatrixContent(Content.SlidingWindowQualities);
|
---|
| 110 | }
|
---|
| 111 | #endregion
|
---|
| 112 |
|
---|
[10396] | 113 | protected override void SetEnabledStateOfControls() {
|
---|
| 114 | base.SetEnabledStateOfControls();
|
---|
| 115 | // TODO: Enable or disable controls based on whether the content is null or the view is set readonly
|
---|
| 116 | }
|
---|
| 117 |
|
---|
[10721] | 118 | private void SetMatrixContent(double[,] values) {
|
---|
| 119 | var qualitiesMap = new DoubleMatrix(values); // add an extra columns for the training data
|
---|
| 120 | qualitiesMap.ColumnNames = Enumerable.Range(0, qualitiesMap.Columns - 1).Select(x => Content.SlidingWindowRanges[x].Start + " - " + Content.SlidingWindowRanges[x].End).Concat(new List<string> { "Training" });
|
---|
| 121 | qualitiesMap.RowNames = Enumerable.Range(1, qualitiesMap.Rows).Select(x => "M" + x);
|
---|
| 122 | double min = 0, max = 0;
|
---|
| 123 | if (Content.QualityMeasure == SlidingWindowBestSolutionsCollection.QualityMeasures.PEARSON) {
|
---|
| 124 | max = 1.0;
|
---|
| 125 | } else {
|
---|
| 126 | foreach (var q in qualitiesMap) {
|
---|
| 127 | if (min > q) min = q;
|
---|
| 128 | if (max < q) max = q;
|
---|
| 129 | }
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | enhancedStringConvertibleMatrixView.Minimum = min;
|
---|
| 133 | enhancedStringConvertibleMatrixView.Maximum = max;
|
---|
| 134 | enhancedStringConvertibleMatrixView.Content = qualitiesMap;
|
---|
| 135 | }
|
---|
| 136 |
|
---|
[10396] | 137 | #region Event Handlers (child controls)
|
---|
| 138 | private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e) {
|
---|
| 139 | var combobox = (ComboBox)sender;
|
---|
| 140 | switch ((string)combobox.SelectedItem) {
|
---|
| 141 | case "Pearson R2": {
|
---|
[10720] | 142 | Content.QualityMeasure = SlidingWindowBestSolutionsCollection.QualityMeasures.PEARSON;
|
---|
[10396] | 143 | break;
|
---|
| 144 | }
|
---|
| 145 | case "Mean Squared Error": {
|
---|
[10720] | 146 | Content.QualityMeasure = SlidingWindowBestSolutionsCollection.QualityMeasures.MSE;
|
---|
[10396] | 147 | break;
|
---|
| 148 | }
|
---|
| 149 | }
|
---|
| 150 | }
|
---|
| 151 |
|
---|
[10720] | 152 | public void enhancedStringConvertibleMatrixView_cellDoubleClick(object sender, DataGridViewCellEventArgs e) {
|
---|
| 153 | var dataGridView = (DataGridView)sender;
|
---|
| 154 | var cell = dataGridView.SelectedCells[0];
|
---|
| 155 | var bestSolutions = Content.SlidingWindowBestSolutions.Values.ToList();
|
---|
| 156 | var tree = bestSolutions[cell.RowIndex];
|
---|
| 157 | var model = Content.CreateModel(tree, Content.Interpreter);
|
---|
| 158 | var solution = Content.CreateSolution(model, Content.ProblemData);
|
---|
| 159 | var result = new Result("Sliding Window Solution", solution);
|
---|
| 160 | var view = MainFormManager.MainForm.ShowContent(result, typeof(ResultView));
|
---|
| 161 | if (view != null) {
|
---|
| 162 | view.ReadOnly = ReadOnly;
|
---|
| 163 | view.Locked = Locked;
|
---|
[10396] | 164 | }
|
---|
| 165 | }
|
---|
[10720] | 166 | #endregion
|
---|
[10396] | 167 | }
|
---|
| 168 | }
|
---|