[13817] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2016 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 |
|
---|
[13828] | 22 | using System;
|
---|
[14248] | 23 | using System.Collections;
|
---|
[13817] | 24 | using System.Collections.Generic;
|
---|
[13850] | 25 | using System.Drawing;
|
---|
[13808] | 26 | using System.Linq;
|
---|
[13843] | 27 | using System.Threading.Tasks;
|
---|
[13808] | 28 | using System.Windows.Forms;
|
---|
| 29 | using HeuristicLab.Common;
|
---|
| 30 | using HeuristicLab.MainForm;
|
---|
[13843] | 31 | using HeuristicLab.Visualization.ChartControlsExtensions;
|
---|
[13808] | 32 |
|
---|
| 33 | namespace HeuristicLab.Problems.DataAnalysis.Views {
|
---|
[14014] | 34 | [View("Target Response Gradients")]
|
---|
[13808] | 35 | [Content(typeof(IRegressionSolution))]
|
---|
| 36 | public partial class RegressionSolutionTargetResponseGradientView : DataAnalysisSolutionEvaluationView {
|
---|
[14248] | 37 | private readonly Dictionary<string, IGradientChart> gradientCharts;
|
---|
[13850] | 38 | private readonly Dictionary<string, DensityChart> densityCharts;
|
---|
| 39 | private readonly Dictionary<string, Panel> groupingPanels;
|
---|
| 40 |
|
---|
[13831] | 41 | private const int Points = 200;
|
---|
[13995] | 42 | private int MaxColumns = 4;
|
---|
[13808] | 43 |
|
---|
[13850] | 44 | private IEnumerable<string> VisibleVariables {
|
---|
| 45 | get {
|
---|
| 46 | foreach (ListViewItem item in variableListView.CheckedItems)
|
---|
| 47 | yield return item.Text;
|
---|
| 48 | }
|
---|
[13843] | 49 | }
|
---|
[14248] | 50 | private IEnumerable<IGradientChart> VisibleGradientCharts {
|
---|
[13850] | 51 | get { return VisibleVariables.Select(v => gradientCharts[v]); }
|
---|
| 52 | }
|
---|
| 53 | private IEnumerable<DensityChart> VisibleDensityCharts {
|
---|
| 54 | get { return VisibleVariables.Select(v => densityCharts[v]); }
|
---|
| 55 | }
|
---|
| 56 | private IEnumerable<Panel> VisibleChartsPanels {
|
---|
| 57 | get { return VisibleVariables.Select(v => groupingPanels[v]); }
|
---|
| 58 | }
|
---|
[13843] | 59 |
|
---|
[13808] | 60 | public RegressionSolutionTargetResponseGradientView() {
|
---|
| 61 | InitializeComponent();
|
---|
[14248] | 62 | gradientCharts = new Dictionary<string, IGradientChart>();
|
---|
[13850] | 63 | densityCharts = new Dictionary<string, DensityChart>();
|
---|
| 64 | groupingPanels = new Dictionary<string, Panel>();
|
---|
[13846] | 65 |
|
---|
| 66 | limitView.Content = new DoubleLimit(0, 1);
|
---|
[14021] | 67 | limitView.Content.ValueChanged += limit_ValueChanged;
|
---|
[13850] | 68 |
|
---|
[14021] | 69 | densityComboBox.SelectedIndex = 1; // select Training
|
---|
| 70 |
|
---|
[13850] | 71 | // Avoid additional horizontal scrollbar
|
---|
| 72 | var vertScrollWidth = SystemInformation.VerticalScrollBarWidth;
|
---|
| 73 | scrollPanel.Padding = new Padding(0, 0, vertScrollWidth, 0);
|
---|
| 74 | scrollPanel.AutoScroll = true;
|
---|
[13808] | 75 | }
|
---|
| 76 |
|
---|
| 77 | public new IRegressionSolution Content {
|
---|
| 78 | get { return (IRegressionSolution)base.Content; }
|
---|
[13831] | 79 | set { base.Content = value; }
|
---|
[13808] | 80 | }
|
---|
| 81 |
|
---|
| 82 | protected override void RegisterContentEvents() {
|
---|
| 83 | base.RegisterContentEvents();
|
---|
[13995] | 84 | Content.ModelChanged += solution_ModelChanged;
|
---|
[13808] | 85 | }
|
---|
| 86 |
|
---|
| 87 | protected override void DeregisterContentEvents() {
|
---|
[13995] | 88 | Content.ModelChanged -= solution_ModelChanged;
|
---|
[13808] | 89 | base.DeregisterContentEvents();
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | protected override void OnContentChanged() {
|
---|
| 93 | base.OnContentChanged();
|
---|
[13817] | 94 | if (Content == null) return;
|
---|
[13831] | 95 | var problemData = Content.ProblemData;
|
---|
[13846] | 96 |
|
---|
| 97 | // Init Y-axis range
|
---|
| 98 | double min = double.MaxValue, max = double.MinValue;
|
---|
| 99 | var trainingTarget = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, problemData.TrainingIndices);
|
---|
| 100 | foreach (var t in trainingTarget) {
|
---|
| 101 | if (t < min) min = t;
|
---|
| 102 | if (t > max) max = t;
|
---|
| 103 | }
|
---|
| 104 | double range = max - min;
|
---|
| 105 | const double scale = 1.0 / 3.0;
|
---|
| 106 | double axisMin, axisMax, axisInterval;
|
---|
| 107 | ChartUtil.CalculateAxisInterval(min - scale * range, max + scale * range, 5, out axisMin, out axisMax, out axisInterval);
|
---|
| 108 | automaticYAxisCheckBox.Checked = false;
|
---|
| 109 | limitView.ReadOnly = false;
|
---|
| 110 | limitView.Content.Lower = axisMin;
|
---|
| 111 | limitView.Content.Upper = axisMax;
|
---|
| 112 |
|
---|
[13828] | 113 | // create dataset
|
---|
[13845] | 114 | var allowedInputVariables = Content.ProblemData.AllowedInputVariables;
|
---|
[14248] | 115 | var doubleVariables = allowedInputVariables.Where(problemData.Dataset.VariableHasType<double>);
|
---|
| 116 | var doubleVariableValues = (IEnumerable<IList>)doubleVariables.Select(x => new List<double> { problemData.Dataset.GetDoubleValues(x, problemData.TrainingIndices).Median() });
|
---|
[13850] | 117 |
|
---|
[14248] | 118 | var factorVariables = allowedInputVariables.Where(problemData.Dataset.VariableHasType<string>);
|
---|
| 119 | var factorVariableValues = (IEnumerable<IList>)factorVariables.Select(x => new List<string> {
|
---|
| 120 | problemData.Dataset.GetStringValues(x, problemData.TrainingIndices)
|
---|
| 121 | .GroupBy(val => val).OrderByDescending(g => g.Count()).First().Key // most frequent value
|
---|
| 122 | });
|
---|
| 123 |
|
---|
| 124 | var sharedFixedVariables = new ModifiableDataset(doubleVariables.Concat(factorVariables), doubleVariableValues.Concat(factorVariableValues));
|
---|
| 125 |
|
---|
| 126 |
|
---|
[13850] | 127 | // create controls
|
---|
| 128 | gradientCharts.Clear();
|
---|
| 129 | densityCharts.Clear();
|
---|
| 130 | groupingPanels.Clear();
|
---|
[14248] | 131 | foreach (var variableName in doubleVariables) {
|
---|
[13850] | 132 | var gradientChart = CreateGradientChart(variableName, sharedFixedVariables);
|
---|
| 133 | gradientCharts.Add(variableName, gradientChart);
|
---|
| 134 |
|
---|
| 135 | var densityChart = new DensityChart() {
|
---|
| 136 | Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right,
|
---|
| 137 | Margin = Padding.Empty,
|
---|
| 138 | Height = 12,
|
---|
[14131] | 139 | Visible = false,
|
---|
| 140 | Top = (int)(gradientChart.Height * 0.1),
|
---|
[13850] | 141 | };
|
---|
| 142 | densityCharts.Add(variableName, densityChart);
|
---|
| 143 |
|
---|
[14089] | 144 | gradientChart.ZoomChanged += (o, e) => {
|
---|
| 145 | var gradient = (GradientChart)o;
|
---|
| 146 | var density = densityCharts[gradient.FreeVariable];
|
---|
| 147 | density.Visible = densityComboBox.SelectedIndex != 0 && !gradient.IsZoomed;
|
---|
| 148 | if (density.Visible)
|
---|
| 149 | UpdateDensityChart(density, gradient.FreeVariable);
|
---|
| 150 | };
|
---|
[14131] | 151 | gradientChart.SizeChanged += (o, e) => {
|
---|
| 152 | var gradient = (GradientChart)o;
|
---|
| 153 | var density = densityCharts[gradient.FreeVariable];
|
---|
| 154 | density.Top = (int)(gradient.Height * 0.1);
|
---|
| 155 | };
|
---|
[14089] | 156 |
|
---|
[14158] | 157 | // Initially, the inner plot areas are not initialized for hidden charts (scollpanel, ...)
|
---|
| 158 | // This event handler listens for the paint event once (where everything is already initialized) to do some manual layouting.
|
---|
[14248] | 159 | gradientChart.ChartPostPaint += OnGradientChartPostPaint;
|
---|
[14158] | 160 |
|
---|
[13850] | 161 | var panel = new Panel() {
|
---|
[13820] | 162 | Dock = DockStyle.Fill,
|
---|
| 163 | Margin = Padding.Empty,
|
---|
[13850] | 164 | BackColor = Color.White
|
---|
[13820] | 165 | };
|
---|
[13843] | 166 |
|
---|
[13850] | 167 | panel.Controls.Add(densityChart);
|
---|
| 168 | panel.Controls.Add(gradientChart);
|
---|
| 169 | groupingPanels.Add(variableName, panel);
|
---|
[13808] | 170 | }
|
---|
[14248] | 171 | foreach (var variableName in factorVariables) {
|
---|
| 172 | var gradientChart = CreateFactorGradientChart(variableName, sharedFixedVariables);
|
---|
| 173 | gradientCharts.Add(variableName, gradientChart);
|
---|
[13850] | 174 |
|
---|
[14248] | 175 | var densityChart = new DensityChart() {
|
---|
| 176 | Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right,
|
---|
| 177 | Margin = Padding.Empty,
|
---|
| 178 | Height = 12,
|
---|
| 179 | Visible = false,
|
---|
| 180 | Top = (int)(gradientChart.Height * 0.1),
|
---|
| 181 | };
|
---|
| 182 | densityCharts.Add(variableName, densityChart);
|
---|
| 183 | gradientChart.ZoomChanged += (o, e) => {
|
---|
| 184 | var gradient = (FactorGradientChart)o;
|
---|
| 185 | var density = densityCharts[gradient.FreeVariable];
|
---|
| 186 | density.Visible = densityComboBox.SelectedIndex != 0 && !gradient.IsZoomed;
|
---|
| 187 | if (density.Visible)
|
---|
| 188 | UpdateDensityChart(density, gradient.FreeVariable);
|
---|
| 189 | };
|
---|
| 190 | gradientChart.SizeChanged += (o, e) => {
|
---|
| 191 | var gradient = (FactorGradientChart)o;
|
---|
| 192 | var density = densityCharts[gradient.FreeVariable];
|
---|
| 193 | density.Top = (int)(gradient.Height * 0.1);
|
---|
| 194 | };
|
---|
| 195 |
|
---|
| 196 | // Initially, the inner plot areas are not initialized for hidden charts (scollpanel, ...)
|
---|
| 197 | // This event handler listens for the paint event once (where everything is already initialized) to do some manual layouting.
|
---|
| 198 | gradientChart.ChartPostPaint += OnFactorGradientChartPostPaint;
|
---|
| 199 |
|
---|
| 200 | var panel = new Panel() {
|
---|
| 201 | Dock = DockStyle.Fill,
|
---|
| 202 | Margin = Padding.Empty,
|
---|
| 203 | BackColor = Color.White
|
---|
| 204 | };
|
---|
| 205 |
|
---|
| 206 | panel.Controls.Add(densityChart);
|
---|
| 207 | panel.Controls.Add(gradientChart);
|
---|
| 208 | groupingPanels.Add(variableName, panel);
|
---|
| 209 | }
|
---|
[13828] | 210 | // update variable list
|
---|
[14021] | 211 | variableListView.ItemChecked -= variableListView_ItemChecked;
|
---|
[13828] | 212 | variableListView.Items.Clear();
|
---|
[13845] | 213 | foreach (var variable in allowedInputVariables)
|
---|
| 214 | variableListView.Items.Add(key: variable, text: variable, imageIndex: 0);
|
---|
| 215 |
|
---|
[13948] | 216 | foreach (var variable in Content.Model.VariablesUsedForPrediction)
|
---|
[13845] | 217 | variableListView.Items[variable].Checked = true;
|
---|
[14021] | 218 | variableListView.ItemChecked += variableListView_ItemChecked;
|
---|
| 219 |
|
---|
| 220 | RecalculateAndRelayoutCharts();
|
---|
[13808] | 221 | }
|
---|
[14021] | 222 |
|
---|
[14248] | 223 | private void OnGradientChartPostPaint(object o, EventArgs e) {
|
---|
[14158] | 224 | var gradient = (GradientChart)o;
|
---|
| 225 | var density = densityCharts[gradient.FreeVariable];
|
---|
| 226 |
|
---|
| 227 | density.Width = gradient.Width;
|
---|
| 228 |
|
---|
| 229 | var gcPlotPosition = gradient.InnerPlotPosition;
|
---|
| 230 | density.Left = (int)(gcPlotPosition.X / 100.0 * gradient.Width);
|
---|
| 231 | density.Width = (int)(gcPlotPosition.Width / 100.0 * gradient.Width);
|
---|
| 232 | gradient.UpdateTitlePosition();
|
---|
| 233 |
|
---|
| 234 | // removed after succesful layouting due to performance reasons
|
---|
| 235 | if (gcPlotPosition.Width != 0)
|
---|
[14248] | 236 | gradient.ChartPostPaint -= OnGradientChartPostPaint;
|
---|
[14158] | 237 | }
|
---|
| 238 |
|
---|
[14248] | 239 | private void OnFactorGradientChartPostPaint(object o, EventArgs e) {
|
---|
| 240 | var gradient = (FactorGradientChart)o;
|
---|
| 241 | var density = densityCharts[gradient.FreeVariable];
|
---|
| 242 |
|
---|
| 243 | density.Width = gradient.Width;
|
---|
| 244 |
|
---|
| 245 | var gcPlotPosition = gradient.InnerPlotPosition;
|
---|
| 246 | density.Left = (int)(gcPlotPosition.X / 100.0 * gradient.Width);
|
---|
| 247 | density.Width = (int)(gcPlotPosition.Width / 100.0 * gradient.Width);
|
---|
| 248 | gradient.UpdateTitlePosition();
|
---|
| 249 |
|
---|
| 250 | // removed after succesful layouting due to performance reasons
|
---|
| 251 | if (gcPlotPosition.Width != 0)
|
---|
| 252 | gradient.ChartPostPaint -= OnFactorGradientChartPostPaint;
|
---|
| 253 | }
|
---|
| 254 |
|
---|
[14021] | 255 | private async void RecalculateAndRelayoutCharts() {
|
---|
| 256 | foreach (var variable in VisibleVariables) {
|
---|
| 257 | var gradientChart = gradientCharts[variable];
|
---|
[14248] | 258 | await gradientChart.RecalculateAsync(false, false);
|
---|
[14021] | 259 | }
|
---|
| 260 | gradientChartTableLayout.SuspendLayout();
|
---|
| 261 | SetupYAxis();
|
---|
| 262 | ReOrderControls();
|
---|
| 263 | SetStyles();
|
---|
| 264 | gradientChartTableLayout.ResumeLayout();
|
---|
| 265 | gradientChartTableLayout.Refresh();
|
---|
| 266 | foreach (var variable in VisibleVariables) {
|
---|
[14248] | 267 | DensityChart densityChart;
|
---|
| 268 | if (densityCharts.TryGetValue(variable, out densityChart)) {
|
---|
| 269 | UpdateDensityChart(densityChart, variable);
|
---|
| 270 | }
|
---|
[14021] | 271 | }
|
---|
| 272 | }
|
---|
[13850] | 273 | private GradientChart CreateGradientChart(string variableName, ModifiableDataset sharedFixedVariables) {
|
---|
| 274 | var gradientChart = new GradientChart {
|
---|
| 275 | Dock = DockStyle.Fill,
|
---|
| 276 | Margin = Padding.Empty,
|
---|
| 277 | ShowLegend = false,
|
---|
| 278 | ShowCursor = true,
|
---|
[13855] | 279 | ShowConfigButton = false,
|
---|
[13850] | 280 | YAxisTicks = 5,
|
---|
| 281 | };
|
---|
| 282 | gradientChart.VariableValueChanged += async (o, e) => {
|
---|
[14248] | 283 | var recalculations = VisibleGradientCharts
|
---|
| 284 | .Except(new[] { (IGradientChart)o })
|
---|
| 285 | .Select(async chart => {
|
---|
| 286 | await chart.RecalculateAsync(updateOnFinish: false, resetYAxis: false);
|
---|
| 287 | }).ToList();
|
---|
[13850] | 288 | await Task.WhenAll(recalculations);
|
---|
[13843] | 289 |
|
---|
[13850] | 290 | if (recalculations.All(t => t.IsCompleted))
|
---|
| 291 | SetupYAxis();
|
---|
| 292 | };
|
---|
| 293 | gradientChart.Configure(new[] { Content }, sharedFixedVariables, variableName, Points);
|
---|
[13995] | 294 | gradientChart.SolutionAdded += gradientChart_SolutionAdded;
|
---|
| 295 | gradientChart.SolutionRemoved += gradientChart_SolutionRemoved;
|
---|
[13850] | 296 | return gradientChart;
|
---|
| 297 | }
|
---|
[14248] | 298 | private FactorGradientChart CreateFactorGradientChart(string variableName, ModifiableDataset sharedFixedVariables) {
|
---|
| 299 | var gradientChart = new FactorGradientChart {
|
---|
| 300 | Dock = DockStyle.Fill,
|
---|
| 301 | Margin = Padding.Empty,
|
---|
| 302 | ShowLegend = false,
|
---|
| 303 | ShowCursor = true,
|
---|
| 304 | YAxisTicks = 5,
|
---|
| 305 | };
|
---|
| 306 | gradientChart.VariableValueChanged += async (o, e) => {
|
---|
| 307 | var recalculations = VisibleGradientCharts
|
---|
| 308 | .Except(new[] { (FactorGradientChart)o })
|
---|
| 309 | .Select(async chart => {
|
---|
| 310 | await chart.RecalculateAsync(updateOnFinish: false, resetYAxis: false);
|
---|
| 311 | }).ToList();
|
---|
| 312 | await Task.WhenAll(recalculations);
|
---|
[13850] | 313 |
|
---|
[14248] | 314 | if (recalculations.All(t => t.IsCompleted))
|
---|
| 315 | SetupYAxis();
|
---|
| 316 | };
|
---|
| 317 | var variableValues = Content.ProblemData.Dataset.GetStringValues(variableName).Distinct().OrderBy(n => n).ToList();
|
---|
| 318 | gradientChart.Configure(new[] { Content }, sharedFixedVariables, variableName, variableValues);
|
---|
| 319 | gradientChart.SolutionAdded += gradientChart_SolutionAdded;
|
---|
| 320 | gradientChart.SolutionRemoved += gradientChart_SolutionRemoved;
|
---|
| 321 | return gradientChart;
|
---|
| 322 | }
|
---|
[13846] | 323 | private void SetupYAxis() {
|
---|
| 324 | double axisMin, axisMax;
|
---|
| 325 | if (automaticYAxisCheckBox.Checked) {
|
---|
| 326 | double min = double.MaxValue, max = double.MinValue;
|
---|
[13850] | 327 | foreach (var chart in VisibleGradientCharts) {
|
---|
[13846] | 328 | if (chart.YMin < min) min = chart.YMin;
|
---|
| 329 | if (chart.YMax > max) max = chart.YMax;
|
---|
| 330 | }
|
---|
| 331 |
|
---|
| 332 | double axisInterval;
|
---|
| 333 | ChartUtil.CalculateAxisInterval(min, max, 5, out axisMin, out axisMax, out axisInterval);
|
---|
| 334 | } else {
|
---|
| 335 | axisMin = limitView.Content.Lower;
|
---|
| 336 | axisMax = limitView.Content.Upper;
|
---|
[13843] | 337 | }
|
---|
| 338 |
|
---|
[13850] | 339 | foreach (var chart in VisibleGradientCharts) {
|
---|
[13843] | 340 | chart.FixedYAxisMin = axisMin;
|
---|
| 341 | chart.FixedYAxisMax = axisMax;
|
---|
| 342 | }
|
---|
| 343 | }
|
---|
| 344 |
|
---|
[13850] | 345 | // reorder chart controls so that they always appear in the same order as in the list view
|
---|
| 346 | // the table layout containing the controls should be suspended before calling this method
|
---|
| 347 | private void ReOrderControls() {
|
---|
[13828] | 348 | var tl = gradientChartTableLayout;
|
---|
| 349 | tl.Controls.Clear();
|
---|
[13850] | 350 | int row = 0, column = 0;
|
---|
[14014] | 351 | foreach (var v in VisibleVariables) {
|
---|
| 352 | var chartsPanel = groupingPanels[v];
|
---|
[13850] | 353 | tl.Controls.Add(chartsPanel, column, row);
|
---|
[14014] | 354 |
|
---|
[14021] | 355 | var chart = gradientCharts[v];
|
---|
| 356 | chart.YAxisTitle = column == 0 ? Content.ProblemData.TargetVariable : string.Empty;
|
---|
[13850] | 357 | column++;
|
---|
[14014] | 358 |
|
---|
[13850] | 359 | if (column == MaxColumns) {
|
---|
| 360 | row++;
|
---|
| 361 | column = 0;
|
---|
| 362 | }
|
---|
| 363 | }
|
---|
[13828] | 364 | }
|
---|
[13808] | 365 |
|
---|
[13995] | 366 | private void SetStyles() {
|
---|
| 367 | var tl = gradientChartTableLayout;
|
---|
| 368 | tl.RowStyles.Clear();
|
---|
| 369 | tl.ColumnStyles.Clear();
|
---|
| 370 | int numVariables = VisibleVariables.Count();
|
---|
| 371 | if (numVariables == 0)
|
---|
| 372 | return;
|
---|
| 373 |
|
---|
| 374 | // set column styles
|
---|
| 375 | tl.ColumnCount = Math.Min(numVariables, MaxColumns);
|
---|
| 376 | for (int c = 0; c < tl.ColumnCount; c++)
|
---|
| 377 | tl.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100.0f / tl.ColumnCount));
|
---|
| 378 |
|
---|
| 379 | // set row styles
|
---|
| 380 | tl.RowCount = (int)Math.Ceiling((double)numVariables / tl.ColumnCount);
|
---|
| 381 | var columnWidth = tl.Width / tl.ColumnCount; // assume all columns have the same width
|
---|
| 382 | var rowHeight = (int)(0.8 * columnWidth);
|
---|
| 383 | for (int r = 0; r < tl.RowCount; r++)
|
---|
| 384 | tl.RowStyles.Add(new RowStyle(SizeType.Absolute, rowHeight));
|
---|
| 385 | }
|
---|
| 386 |
|
---|
| 387 | private async void gradientChart_SolutionAdded(object sender, EventArgs<IRegressionSolution> e) {
|
---|
| 388 | var solution = e.Value;
|
---|
| 389 | foreach (var chart in gradientCharts.Values) {
|
---|
| 390 | if (sender == chart) continue;
|
---|
| 391 | await chart.AddSolutionAsync(solution);
|
---|
| 392 | }
|
---|
| 393 | }
|
---|
| 394 |
|
---|
| 395 | private async void gradientChart_SolutionRemoved(object sender, EventArgs<IRegressionSolution> e) {
|
---|
| 396 | var solution = e.Value;
|
---|
| 397 | foreach (var chart in gradientCharts.Values) {
|
---|
| 398 | if (sender == chart) continue;
|
---|
| 399 | await chart.RemoveSolutionAsync(solution);
|
---|
| 400 | }
|
---|
| 401 | }
|
---|
| 402 |
|
---|
[13842] | 403 | private async void variableListView_ItemChecked(object sender, ItemCheckedEventArgs e) {
|
---|
[13808] | 404 | var item = e.Item;
|
---|
| 405 | var variable = item.Text;
|
---|
[13850] | 406 | var gradientChart = gradientCharts[variable];
|
---|
| 407 | var chartsPanel = groupingPanels[variable];
|
---|
[13817] | 408 | var tl = gradientChartTableLayout;
|
---|
[13850] | 409 |
|
---|
[13817] | 410 | tl.SuspendLayout();
|
---|
[13808] | 411 | if (item.Checked) {
|
---|
[13850] | 412 | tl.Controls.Add(chartsPanel);
|
---|
[14248] | 413 | await gradientChart.RecalculateAsync(false, false);
|
---|
[13808] | 414 | } else {
|
---|
[13850] | 415 | tl.Controls.Remove(chartsPanel);
|
---|
[13808] | 416 | }
|
---|
[13843] | 417 |
|
---|
[13850] | 418 | if (tl.Controls.Count > 0) {
|
---|
| 419 | SetupYAxis();
|
---|
| 420 | ReOrderControls();
|
---|
[13995] | 421 | SetStyles();
|
---|
[13828] | 422 | }
|
---|
[13817] | 423 | tl.ResumeLayout();
|
---|
[14021] | 424 | tl.Refresh();
|
---|
| 425 | densityComboBox_SelectedIndexChanged(this, EventArgs.Empty);
|
---|
[13808] | 426 | }
|
---|
[13846] | 427 |
|
---|
| 428 | private void automaticYAxisCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
| 429 | limitView.ReadOnly = automaticYAxisCheckBox.Checked;
|
---|
| 430 | SetupYAxis();
|
---|
[14021] | 431 | gradientChartTableLayout.Refresh();
|
---|
| 432 | densityComboBox_SelectedIndexChanged(this, EventArgs.Empty); // necessary to realign the density plots
|
---|
[13846] | 433 | }
|
---|
| 434 |
|
---|
| 435 | private void limit_ValueChanged(object sender, EventArgs e) {
|
---|
| 436 | if (automaticYAxisCheckBox.Checked)
|
---|
| 437 | return;
|
---|
| 438 | SetupYAxis();
|
---|
[14021] | 439 | gradientChartTableLayout.Refresh();
|
---|
| 440 | densityComboBox_SelectedIndexChanged(this, EventArgs.Empty); // necessary to realign the density plots
|
---|
[13846] | 441 | }
|
---|
[13850] | 442 |
|
---|
| 443 | private void densityComboBox_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
[14021] | 444 | if (Content == null)
|
---|
| 445 | return;
|
---|
| 446 |
|
---|
[13850] | 447 | int si = densityComboBox.SelectedIndex;
|
---|
| 448 | if (si == 0) {
|
---|
| 449 | foreach (var densityChart in densityCharts.Values)
|
---|
| 450 | densityChart.Visible = false;
|
---|
| 451 | } else {
|
---|
| 452 | var indices = GetDensityIndices(si).ToList();
|
---|
| 453 |
|
---|
| 454 | foreach (var entry in densityCharts) {
|
---|
| 455 | var variableName = entry.Key;
|
---|
| 456 | var densityChart = entry.Value;
|
---|
[14089] | 457 | if (!VisibleVariables.Contains(variableName) || gradientCharts[variableName].IsZoomed)
|
---|
[13850] | 458 | continue;
|
---|
[14089] | 459 |
|
---|
[13850] | 460 | UpdateDensityChart(densityChart, variableName, indices);
|
---|
| 461 | }
|
---|
| 462 | }
|
---|
| 463 | }
|
---|
| 464 | private IEnumerable<int> GetDensityIndices(int selectedIndex) {
|
---|
| 465 | var problemData = Content.ProblemData;
|
---|
| 466 | return
|
---|
| 467 | selectedIndex == 1 ? problemData.TrainingIndices :
|
---|
| 468 | selectedIndex == 2 ? problemData.TestIndices :
|
---|
| 469 | problemData.AllIndices;
|
---|
| 470 | }
|
---|
| 471 | private void UpdateDensityChart(DensityChart densityChart, string variable, IList<int> indices = null) {
|
---|
| 472 | if (densityComboBox.SelectedIndex == 0)
|
---|
| 473 | return;
|
---|
| 474 | if (indices == null) {
|
---|
| 475 | indices = GetDensityIndices(densityComboBox.SelectedIndex).ToList();
|
---|
| 476 | }
|
---|
[14248] | 477 | if (Content.ProblemData.Dataset.VariableHasType<double>(variable)) {
|
---|
| 478 | var data = Content.ProblemData.Dataset.GetDoubleValues(variable, indices).ToList();
|
---|
| 479 | var gradientChart = gradientCharts[variable] as GradientChart;
|
---|
| 480 | if (gradientChart != null) {
|
---|
| 481 | var min = gradientChart.FixedXAxisMin;
|
---|
| 482 | var max = gradientChart.FixedXAxisMax;
|
---|
| 483 | var buckets = gradientChart.DrawingSteps;
|
---|
| 484 | if (min.HasValue && max.HasValue) {
|
---|
| 485 | densityChart.UpdateChart(data, min.Value, max.Value, buckets);
|
---|
| 486 | densityChart.Width = gradientChart.Width;
|
---|
[13850] | 487 |
|
---|
[14248] | 488 | var gcPlotPosition = gradientChart.InnerPlotPosition;
|
---|
| 489 | densityChart.Left = (int)(gcPlotPosition.X / 100.0 * gradientChart.Width);
|
---|
| 490 | densityChart.Width = (int)(gcPlotPosition.Width / 100.0 * gradientChart.Width);
|
---|
[13850] | 491 |
|
---|
[14248] | 492 | densityChart.Visible = true;
|
---|
| 493 | }
|
---|
| 494 | gradientChart.UpdateTitlePosition();
|
---|
| 495 | }
|
---|
| 496 | } else if (Content.ProblemData.Dataset.VariableHasType<string>(variable)) {
|
---|
| 497 | var data = Content.ProblemData.Dataset.GetStringValues(variable).ToList();
|
---|
| 498 | var gradientChart = gradientCharts[variable] as FactorGradientChart;
|
---|
| 499 | if (gradientChart != null) {
|
---|
| 500 | densityChart.UpdateChart(data);
|
---|
| 501 | densityChart.Width = gradientChart.Width;
|
---|
| 502 |
|
---|
| 503 | var gcPlotPosition = gradientChart.InnerPlotPosition;
|
---|
| 504 | densityChart.Left = (int)(gcPlotPosition.X / 100.0 * gradientChart.Width);
|
---|
| 505 | densityChart.Width = (int)(gcPlotPosition.Width / 100.0 * gradientChart.Width);
|
---|
| 506 |
|
---|
| 507 | densityChart.Visible = true;
|
---|
| 508 |
|
---|
| 509 | gradientChart.UpdateTitlePosition();
|
---|
| 510 | }
|
---|
[13850] | 511 | }
|
---|
| 512 | }
|
---|
[13995] | 513 |
|
---|
[14089] | 514 | private void columnsNumericUpDown_ValueChanged(object sender, EventArgs e) {
|
---|
| 515 | MaxColumns = (int)columnsNumericUpDown.Value;
|
---|
[13995] | 516 | int columns = Math.Min(VisibleVariables.Count(), MaxColumns);
|
---|
| 517 | if (columns > 0) {
|
---|
| 518 | var tl = gradientChartTableLayout;
|
---|
| 519 | MaxColumns = columns;
|
---|
| 520 | tl.SuspendLayout();
|
---|
| 521 | ReOrderControls();
|
---|
| 522 | SetStyles();
|
---|
[14021] | 523 | tl.ResumeLayout();
|
---|
| 524 | tl.Refresh();
|
---|
| 525 | densityComboBox_SelectedIndexChanged(this, EventArgs.Empty);
|
---|
[13995] | 526 | }
|
---|
| 527 | }
|
---|
| 528 |
|
---|
[14021] | 529 | private async void solution_ModelChanged(object sender, EventArgs e) {
|
---|
| 530 | foreach (var variable in VisibleVariables) {
|
---|
| 531 | var gradientChart = gradientCharts[variable];
|
---|
| 532 | var densityChart = densityCharts[variable];
|
---|
| 533 | // recalculate and refresh
|
---|
[14248] | 534 | await gradientChart.RecalculateAsync(false, false);
|
---|
[14021] | 535 | gradientChart.Refresh();
|
---|
| 536 | UpdateDensityChart(densityChart, variable);
|
---|
[13996] | 537 | }
|
---|
[13995] | 538 | }
|
---|
[13808] | 539 | }
|
---|
| 540 | }
|
---|