Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RunCollectionPartialDependencePlotView.cs

Last change on this file was 18208, checked in by gkronber, 3 years ago

#3134: bugfixes and improvements

File size: 2.0 KB
Line 
1using System.Collections.Generic;
2using System.Linq;
3using System.Threading.Tasks;
4using System.Windows.Forms;
5using HeuristicLab.MainForm;
6using HeuristicLab.MainForm.WindowsForms;
7using HeuristicLab.Optimization;
8using HeuristicLab.Problems.DataAnalysis.Views;
9
10namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
11  [Content(typeof(RunCollection), false)]
12  [View("RunCollection Partial Dependence Plots")]
13  public partial class RunCollectionPartialDependencePlotView : AsynchronousContentView {
14    public new RunCollection Content {
15      get => (RunCollection)base.Content;
16      set => base.Content = value;
17    }
18
19    public RunCollectionPartialDependencePlotView() {
20      InitializeComponent();
21    }
22
23    protected override async void OnContentChanged() {
24      base.OnContentChanged();
25      if (Content == null) {
26        tabControl.TabPages.Clear();
27        return;
28      }
29      // distinct names of results of types IRegressionSolution
30      var solutionResultNames = Content.SelectMany(run => run.Results.Where(kvp => kvp.Value is IRegressionSolution).Select(kvp => kvp.Key)).Distinct().ToArray();
31
32      foreach (var resultName in solutionResultNames) {
33        var tabPage = new TabPage(resultName);
34        tabControl.TabPages.Add(tabPage);
35
36        var solutions = new List<IRegressionSolution>();
37        foreach (var run in Content) {
38          // in experiments we may mix algorithms and therefore have different solution names in different runs
39          // we only combine solutions with the same name
40          if (run.Results.TryGetValue(resultName, out var sol) && sol is IRegressionSolution) {
41            solutions.Add((IRegressionSolution)sol);
42          }
43        }
44        var plot = new RegressionSolutionPartialDependencePlotView {
45          Content = solutions[0],
46          Dock = DockStyle.Fill
47        };
48
49        tabPage.Controls.Add(plot);
50        for (int i = 1; i < solutions.Count; i++)
51          await plot.AddSolutionAsync(solutions[i]);
52      }
53    }
54  }
55}
Note: See TracBrowser for help on using the repository browser.